@@ -34,21 +34,34 @@ jobs:
3434 run : |
3535 # Use the GitHub API to get the list of changed files
3636 # documentation: https://docs.github.com/rest/commits/commits#compare-two-commits
37- DIFF_DOCUMENTS=$(gh api repos/{owner}/{repo}/compare/${BASE_SHA}...${HEAD_SHA} \
38- --jq '.files | .[] | select(.status|IN("added", "modified", "renamed", "copied", "changed")) | .filename')
39- # filter out files that are not markdown
40- DIFF_DOCUMENTS=$(echo "${DIFF_DOCUMENTS}" | egrep -i "^files/.*\.md$" | xargs)
41- echo "DIFF_DOCUMENTS=${DIFF_DOCUMENTS}" >> "$GITHUB_OUTPUT"
37+
38+ # Get files as newline-separated list
39+ FILTERED_FILES=$(gh api repos/{owner}/{repo}/compare/${BASE_SHA}...${HEAD_SHA} \
40+ --jq '.files | .[] | select(.status|IN("added", "modified", "renamed", "copied", "changed")) | .filename' | \
41+ egrep -i "^files/.*\.md$")
42+
43+ # Store as multiline output
44+ EOF="$(openssl rand -hex 8)"
45+ echo "DIFF_DOCUMENTS<<${EOF}" >> "$GITHUB_OUTPUT"
46+ echo "${FILTERED_FILES}" >> "$GITHUB_OUTPUT"
47+ echo "${EOF}" >> "$GITHUB_OUTPUT"
48+
49+ # Also set a simple flag for whether we have files
50+ if [ -n "${FILTERED_MD_FILES// /}" ]; then # Remove all spaces and check if anything remains
51+ echo "HAS_FILES=true" >> "$GITHUB_OUTPUT"
52+ else
53+ echo "HAS_FILES=false" >> "$GITHUB_OUTPUT"
54+ fi
4255
4356 - name : Checkout HEAD
44- if : steps.check.outputs.DIFF_DOCUMENTS
57+ if : steps.check.outputs.HAS_FILES == 'true'
4558 uses : actions/checkout@v4
4659 with :
4760 ref : ${{ github.event.pull_request.head.sha }}
4861 path : pr_head
4962
5063 - name : Get changed content from HEAD
51- if : steps.check.outputs.DIFF_DOCUMENTS
64+ if : steps.check.outputs.HAS_FILES == 'true'
5265 run : |
5366 git config --global user.email "108879845+mdn-bot@users.noreply.github.com"
5467 git config --global user.name "mdn-bot"
@@ -64,63 +77,69 @@ jobs:
6477 git commit -m "Code from PR head"
6578
6679 - name : Setup Node.js environment
67- if : steps.check.outputs.DIFF_DOCUMENTS
80+ if : steps.check.outputs.HAS_FILES == 'true'
6881 uses : actions/setup-node@v4
6982 with :
7083 node-version-file : " .nvmrc"
7184 cache : yarn
7285
7386 - name : Install all yarn packages
74- if : steps.check.outputs.DIFF_DOCUMENTS
87+ if : steps.check.outputs.HAS_FILES == 'true'
7588 run : yarn --frozen-lockfile
7689 env :
7790 # https://github.com/microsoft/vscode-ripgrep#github-api-limit-note
7891 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
7992
8093 - name : Lint and format markdown files
8194 id : lint
82- if : steps.check.outputs.DIFF_DOCUMENTS
95+ if : steps.check.outputs.HAS_FILES == 'true'
8396 env :
8497 DIFF_DOCUMENTS : ${{ steps.check.outputs.DIFF_DOCUMENTS }}
8598 run : |
8699 # Generate random delimiter
87100 # https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings
88101 EOF="$(openssl rand -hex 8)"
89102
90- files_to_lint="$DIFF_DOCUMENTS"
103+ # The DIFF_DOCUMENTS env var contains the clean newline-separated list
104+ # Read into array, one filename per line
105+ readarray -t files_to_lint <<< "$DIFF_DOCUMENTS"
106+
107+ # Debug: show what we got
108+ printf "Files to process (%d files):\n" "${#files_to_lint[@]}"
109+ printf "'%s'\n" "${files_to_lint[@]}"
91110
92111 echo "crlf line ending check"
93112 CRLF_FAILED=true
94- CRLF_LOG=$(git ls-files --eol ${files_to_lint} | grep -E 'w/(mixed|crlf)') || CRLF_FAILED=false
113+ CRLF_LOG=$(git ls-files --eol " ${files_to_lint[@]}" | grep -E 'w/(mixed|crlf)') || CRLF_FAILED=false
95114 echo "CRLF_LOG<<${EOF}" >> "$GITHUB_OUTPUT"
96115 echo "${CRLF_LOG}" >> "$GITHUB_OUTPUT"
97116 echo "${EOF}" >> "$GITHUB_OUTPUT"
98117 echo "CRLF_FAILED=${CRLF_FAILED}" >> "$GITHUB_OUTPUT"
99118
100119 echo "Running markdownlint --fix"
101120 MD_LINT_FAILED=false
102- MD_LINT_LOG=$(yarn markdownlint-cli2 --fix ${files_to_lint} 2>&1) || MD_LINT_FAILED=true
121+ MD_LINT_LOG=$(yarn markdownlint-cli2 --fix " ${files_to_lint[@]}" 2>&1) || MD_LINT_FAILED=true
103122 echo "MD_LINT_LOG<<${EOF}" >> "$GITHUB_OUTPUT"
104123 echo "${MD_LINT_LOG}" >> "$GITHUB_OUTPUT"
105124 echo "${EOF}" >> "$GITHUB_OUTPUT"
106125 echo "MD_LINT_FAILED=${MD_LINT_FAILED}" >> "$GITHUB_OUTPUT"
107126
108127 echo "Linting front-matter"
109128 FM_LINT_FAILED=false
110- FM_LINT_LOG=$(node scripts/front-matter_linter.js --fix true ${files_to_lint} 2>&1) || FM_LINT_FAILED=true
129+ FM_LINT_LOG=$(node scripts/front-matter_linter.js --fix true " ${files_to_lint[@]}" 2>&1) || FM_LINT_FAILED=true
111130 echo "FM_LINT_LOG<<${EOF}" >> "$GITHUB_OUTPUT"
112131 echo "${FM_LINT_LOG}" >> "$GITHUB_OUTPUT"
113132 echo "${EOF}" >> "$GITHUB_OUTPUT"
114133 echo "FM_LINT_FAILED=${FM_LINT_FAILED}" >> "$GITHUB_OUTPUT"
115134
116135 echo "Running Prettier"
117136 PRETTIER_FAILED=false
118- PRETTIER_LOG=$(yarn prettier --check ${files_to_lint} 2>&1) || PRETTIER_FAILED=true
137+ PRETTIER_LOG=$(yarn prettier --check " ${files_to_lint[@]}" 2>&1) || PRETTIER_FAILED=true
119138 echo "PRETTIER_LOG<<${EOF}" >> "$GITHUB_OUTPUT"
120139 echo "${PRETTIER_LOG}" >> "$GITHUB_OUTPUT"
121140 echo "${EOF}" >> "$GITHUB_OUTPUT"
122141 echo "PRETTIER_FAILED=${PRETTIER_FAILED}" >> "$GITHUB_OUTPUT"
123- yarn prettier -w ${files_to_lint}
142+ yarn prettier -w " ${files_to_lint[@]}"
124143
125144 if [[ -n $(git diff) ]]; then
126145 echo "FILES_MODIFIED=true" >> "$GITHUB_OUTPUT"
0 commit comments