name: MarkdownLint on PR on: pull_request: paths-ignore: - '**/changelog/**' jobs: lint: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 with: fetch-depth: 2 - name: Get repo changed files id: repo-changed-files uses: tj-actions/changed-files@v41 with: files: | **/*.md files_ignore: | docs/**/*.md .github/**/*.md - name: Get docs changed files id: docs-changed-files uses: tj-actions/changed-files@v41 with: files: | docs/**/*.md - name: Get docs manifest id: docs-manifest uses: tj-actions/changed-files@v41 with: files: | docs/docs-manifest.json - name: Setup PNPM uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 with: version: '8.6.7' - name: Setup Node uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c with: node-version-file: .nvmrc cache: pnpm registry-url: 'https://registry.npmjs.org' - name: Install prerequisites run: | pnpm i -g markdownlint-cli npm --prefix .github/workflows/scripts install @actions/core - name: Lint repo changed markdown files run: | RED="\e[1;31m" GREEN="\e[1;32m" NC="\e[0m" set -e rc=0 changed_files="${{ steps.repo-changed-files.outputs.all_changed_files }}" if [ -n "$changed_files" ]; then lint_results="" for file in $changed_files; do lint_result=$( { cat "$file" | markdownlint --stdin ; } 2>&1 ) || rc="$?" if [ $rc -ne 0 ]; then lint_results="$lint_results\n>>>Linting failed for file: $file <<<\n$lint_result\n--------" fi done if [ $rc -ne 0 ]; then echo -e "${RED}Linting failed for one or more files${NC}" echo -e "$lint_results" exit 1 else echo -e "${GREEN}Linting successful for all files.${NC}" fi else echo "No repo markdown files changed." fi - name: Check if docs manifest is valid JSON id: is-valid-json run: node .github/workflows/scripts/is-valid-json.js docs/docs-manifest.json - name: Lint docs changed markdown files run: | RED="\e[1;31m" GREEN="\e[1;32m" NC="\e[0m" set -e rc=0 changed_files="${{ steps.docs-changed-files.outputs.all_changed_files }}" changed_manifest="${{ steps.docs-manifest.outputs.all_changed_files }}" is_valid_json="${{ steps.is-valid-json.outputs.is-valid-json }}" storybook="no" for L in ${{github.event.pull_request.labels.*.name}} do if [ $L == "type: storybook" ]; then storybook="yes" fi done if [ -n "$changed_files" ]; then lint_results="" failed_check="" for file in $changed_files; do lint_result=$( { cat "$file" | markdownlint --stdin -c docs/.markdownlint.json ; } 2>&1 ) || rc="$?" if [ $rc -ne 0 ]; then lint_results="$lint_results\n>>>Linting failed for file: $file <<<\n$lint_result\n--------" fi done if [ $rc -ne 0 ]; then echo -e "${RED}Linting failed for one or more files${NC}" echo -e "$lint_results" failed_check="lint" else echo -e "${GREEN}Linting successful for all files.${NC}" fi if [ "$storybook" == "no" ]; then if [ -z "$changed_manifest" ]; then echo -e "${RED}Changes in the docs folder require updating the manifest${NC}" failed_check="manifest" fi if [ "$is_valid_json" == "no" ]; then echo -e "${RED}'docs/docs-manifest.json' is not valid JSON${NC}" failed_check="manifest" fi if [ "$failed_check" == "manifest" ]; then echo -e "Generate a manifest with 'pnpm utils md-docs create docs woocommerce -o docs/docs-manifest.json'" fi fi if [ -n "$failed_check" ]; then exit 1 fi else echo "No docs markdown files changed." fi