1- # It does magic only if there is package.json file in the root of the project
1+ # It does magic only if there is package.json file in the root of the project.
2+ # Runs untrusted PR code under pull_request (no secrets). Privileged follow-up
3+ # (comments + Codecov for PRs) lives in if-nodejs-pr-results.yml.
24name : PR testing - if Node project
35
46on :
5- pull_request_target :
7+ pull_request :
68 types : [opened, reopened, synchronize, ready_for_review]
79 push :
810 branches : [master]
4143 shell : bash
4244 - if : steps.should_run.outputs.shouldrun == 'true'
4345 name : Checkout repository
44- uses : actions/checkout@v4
45- with :
46- # Checkout the merge commit instead of the pull request head commit for a pull request
47- # Fallback to the head commit if its not a pull request
48- ref : ${{ github.event.pull_request.number != '' && format('refs/pull/{0}/merge', github.event.pull_request.number) || github.ref }}
46+ uses : actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
4947
5048 - if : steps.should_run.outputs.shouldrun == 'true'
5149 name : Check if Node.js project and has package.json
6462 shell : bash
6563 - if : steps.packagejson.outputs.exists == 'true' && steps.nvmrc.outputs.exists == 'true'
6664 name : Setup Node.js
67- uses : actions/setup-node@v4
65+ uses : actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
6866 with :
6967 node-version : ' ${{ steps.nodeversion.outputs.version }}'
7068 - if : steps.packagejson.outputs.exists == 'true'
@@ -81,95 +79,61 @@ jobs:
8179 shell : bash
8280 run : npm run generate:assets --if-present
8381
84- # Run the test:md script and capture output
82+ # Run the test:md script; on PRs write results for the privileged comment workflow
8583 - if : ${{ steps.packagejson.outputs.exists == 'true' && matrix.os == 'ubuntu-latest' }}
8684 name : Run markdown checks
8785 id : markdown_check
8886 run : |
87+ set +e
8988 ERRORS=$(npm run test:md | sed -n '/Errors in file/,$p')
90- echo "markdown_output<<EOF" >> $GITHUB_OUTPUT
91- echo "$ERRORS" >> $GITHUB_OUTPUT
92- echo "EOF" >> $GITHUB_OUTPUT
93-
94- # Post a comment using sticky-pull-request-comment
95- - name : Comment on PR with markdown issues
96- if : ${{ steps.markdown_check.outputs.markdown_output != '' && matrix.os == 'ubuntu-latest' }}
97- uses : marocchino/sticky-pull-request-comment@3d60a5b2dae89d44e0c6ddc69dd7536aec2071cd
98- with :
99- header : markdown-check-error
100- GITHUB_TOKEN : ${{ secrets.GH_TOKEN }}
101- message : |
102- ### Markdown Check Results
103-
104- We found issues in the following markdown files:
105-
106- ```
107- ${{ steps.markdown_check.outputs.markdown_output }}
108- ```
109-
110- # Delete the comment if there are no issues
111- - if : ${{ steps.markdown_check.outputs.markdown_output == '' && matrix.os == 'ubuntu-latest' }}
112- name : Delete markdown check comment
113- uses : marocchino/sticky-pull-request-comment@3d60a5b2dae89d44e0c6ddc69dd7536aec2071cd
114- with :
115- header : markdown-check-error
116- delete : true
117- GITHUB_TOKEN : ${{ secrets.GH_TOKEN }}
89+ set -e
90+ if [ "${{ github.event_name }}" = "pull_request" ]; then
91+ mkdir -p pr-check-results
92+ printf '%s' "$ERRORS" > pr-check-results/markdown_output.txt
93+ fi
11894
119- # Run the test:locales script and capture output with cleaner formatting
95+ # Run the test:locales script; on PRs write results for the privileged comment workflow
12096 - if : ${{ steps.packagejson.outputs.exists == 'true' && matrix.os == 'ubuntu-latest' }}
12197 name : Run locale checks
12298 id : locale_check
12399 run : |
124- # Run the test and capture any errors
125100 set +e
126101 LOCALE_OUTPUT=$(npm run test:locales 2>&1)
127102 EXIT_CODE=$?
128103 set -e
129-
130- # If the command failed, extract and format the error message
131- if [ $EXIT_CODE -ne 0 ]; then
132- # Extract the found languages
133- LANGUAGES=$(echo "$LOCALE_OUTPUT" | grep "Found" | sed 's/.*Found \(.*\) languages.*/Found \1 languages:/')
134-
135- # Extract the missing keys information without timestamps
136- MISSING_KEYS=$(echo "$LOCALE_OUTPUT" | grep -A 100 "Missing keys in" | grep -v "\[.*PM\] \|^\s*$")
137-
138- # Combine the cleaned output
139- CLEANED_OUTPUT="$LANGUAGES\n\n$MISSING_KEYS"
140-
141- echo "locale_output<<EOF" >> $GITHUB_OUTPUT
142- echo -e "$CLEANED_OUTPUT" >> $GITHUB_OUTPUT
143- echo "EOF" >> $GITHUB_OUTPUT
104+
105+ if [ "${{ github.event_name }}" = "pull_request" ]; then
106+ mkdir -p pr-check-results
107+ if [ $EXIT_CODE -ne 0 ]; then
108+ LANGUAGES=$(echo "$LOCALE_OUTPUT" | grep "Found" | sed 's/.*Found \(.*\) languages.*/Found \1 languages:/')
109+ MISSING_KEYS=$(echo "$LOCALE_OUTPUT" | grep -A 100 "Missing keys in" | grep -v "\[.*PM\] \|^\s*$")
110+ CLEANED_OUTPUT="$LANGUAGES\n\n$MISSING_KEYS"
111+ echo -e "$CLEANED_OUTPUT" > pr-check-results/locale_output.txt
112+ else
113+ : > pr-check-results/locale_output.txt
114+ fi
144115 fi
145116
146- # Post a comment using sticky-pull-request-comment
147- - name : Comment on PR with locale issues
148- if : ${{ steps.locale_check.outputs.locale_output != '' && matrix.os == 'ubuntu-latest' }}
149- uses : marocchino/sticky-pull-request-comment@3d60a5b2dae89d44e0c6ddc69dd7536aec2071cd
117+ - if : ${{ steps.packagejson.outputs.exists == 'true' && matrix.os == 'ubuntu-latest' && github.event_name == 'pull_request' }}
118+ name : Upload PR check results
119+ uses : actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
150120 with :
151- header : locale-check-error
152- GITHUB_TOKEN : ${{ secrets.GH_TOKEN }}
153- message : |
154- ### Locale Check Results
155- We found issues with locale keys:
156- ```
157- ${{ steps.locale_check.outputs.locale_output }}
158- ```
159- Please make sure all locale files have the same translation keys.
121+ name : pr-check-results
122+ path : pr-check-results/
123+ if-no-files-found : ignore
160124
161- # Delete the comment if there are no issues
162- - if : ${{ steps.locale_check.outputs.locale_output == '' && steps.packagejson.outputs.exists == 'true' && matrix.os == 'ubuntu-latest' }}
163- name : Delete locale check comment if no issues
164- uses : marocchino/sticky-pull-request-comment@3d60a5b2dae89d44e0c6ddc69dd7536aec2071cd
125+ - if : ${{ steps.packagejson.outputs.exists == 'true' && matrix.os == 'ubuntu-latest' && github.event_name == 'pull_request' }}
126+ name : Upload coverage artifact
127+ uses : actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
165128 with :
166- header : locale-check-error
167- delete : true
168- GITHUB_TOKEN : ${{ secrets.GH_TOKEN }}
129+ name : coverage-lcov
130+ path : coverage/lcov.info
131+ if-no-files-found : ignore
169132
170- - if : steps.packagejson.outputs.exists == 'true'
133+ # Trusted push to master: upload coverage with secrets in this workflow
134+ - if : steps.packagejson.outputs.exists == 'true' && github.event_name == 'push'
171135 name : Upload Coverage to Codecov
172- uses : codecov/codecov-action@e28ff129e5465c2c0dcc6f003fc735cb6ae0c673
136+ uses : codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v7.0.0
173137 with :
174138 fail_ci_if_error : true
175139 files : ./coverage/lcov.info
0 commit comments