Skip to content

Commit ac05ded

Browse files
committed
Move PR comment creation to separate workflow on:pull_request_target
1 parent 20acd31 commit ac05ded

2 files changed

Lines changed: 75 additions & 18 deletions

File tree

.github/workflows/integration-tests.yml

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ jobs:
144144
done
145145
echo "Processed $conv TRX file(s)"
146146
147-
148147
- name: Publish Test Report
149148
if: always()
150149
uses: ctrf-io/github-test-reporter@v1
@@ -186,24 +185,21 @@ jobs:
186185
env:
187186
GITHUB_TOKEN: ${{ github.token }}
188187

188+
- name: Save PR Number
189+
if: github.event_name == 'pull_request'
190+
run: echo "PR_NUMBER=${{ github.event.pull_request.number }}" >> $GITHUB_ENV
189191

190-
- name: Create PR Comment
191-
if: always()
192-
uses: ctrf-io/github-test-reporter@v1
193-
with:
194-
report-path: 'ctrf/**/*.json'
195-
196-
summary: true
197-
pull-request: true
198-
use-suite-name: true
199-
update-comment: true
200-
always-group-by: true
201-
overwrite-comment: true
202-
upload-artifact: false
192+
- name: Write PR Number to File
193+
if: github.event_name == 'pull_request'
194+
run: echo "$PR_NUMBER" > pr_number.txt
195+
shell: bash
203196

204-
pull-request-report: true
205-
env:
206-
GITHUB_TOKEN: ${{ github.token }}
197+
- name: Upload PR Number Artifact
198+
if: github.event_name == 'pull_request'
199+
uses: actions/upload-artifact@v4
200+
with:
201+
name: pr_number
202+
path: pr_number.txt
207203

208204
- name: Summary
209-
run: echo "All matrix test jobs completed."
205+
run: echo "All matrix test jobs completed."

.github/workflows/pr-comment.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Create PR Comments
2+
3+
on:
4+
workflow_run:
5+
workflows: ["Tests"]
6+
types: [completed]
7+
8+
permissions:
9+
contents: read
10+
actions: read
11+
pull-requests: write
12+
13+
jobs:
14+
pr-comment:
15+
name: Post Test Result as PR comment
16+
runs-on: ubuntu-24.04
17+
if: github.event.workflow_run.event == 'pull_request'
18+
19+
steps:
20+
- name: Download CTRF artifact
21+
uses: dawidd6/action-download-artifact@v8
22+
with:
23+
github_token: ${{ github.token }}
24+
run_id: ${{ github.event.workflow_run.id }}
25+
name: ctrf-report
26+
path: ctrf
27+
28+
- name: Download PR Number Artifact
29+
uses: dawidd6/action-download-artifact@v8
30+
with:
31+
github_token: ${{ github.token }}
32+
run_id: ${{ github.event.workflow_run.id }}
33+
name: pr_number
34+
path: pr_number
35+
36+
- name: Read PR Number
37+
run: |
38+
PR_NUMBER=$(cat pr_number/pr_number.txt | grep -E '^[0-9]+$')
39+
if [ -z "$PR_NUMBER" ]; then
40+
echo "Error: PR_NUMBER is not a valid integer."
41+
exit 1
42+
fi
43+
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
44+
45+
- name: Post PR Comment
46+
uses: ctrf-io/github-test-reporter@v1
47+
with:
48+
report-path: 'ctrf/**/*.json'
49+
issue: ${{ env.PR_NUMBER }}
50+
51+
summary: true
52+
pull-request: true
53+
use-suite-name: true
54+
update-comment: true
55+
always-group-by: true
56+
overwrite-comment: true
57+
upload-artifact: false
58+
59+
pull-request-report: true
60+
env:
61+
GITHUB_TOKEN: ${{ github.token }}

0 commit comments

Comments
 (0)