Skip to content

Commit bfad0cd

Browse files
authored
Merge pull request #937 from softworkz/submit_move_workflow
Move PR comment creation to separate workflow on:pull_request_target
2 parents 20acd31 + 91ed116 commit bfad0cd

File tree

3 files changed

+99
-18
lines changed

3 files changed

+99
-18
lines changed

.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: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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+
set -Eeuo pipefail
39+
FILE='pr_number/pr_number.txt'
40+
41+
# Ensure file exists
42+
if [ ! -f "$FILE" ] || [ -L "$FILE" ]; then
43+
echo "Error: $FILE is missing or is not a regular file." >&2
44+
exit 1
45+
fi
46+
47+
# Chec file size
48+
if [ "$(wc -c < "$FILE" | tr -d ' ')" -gt 200 ]; then
49+
echo "Error: $FILE is too large." >&2
50+
exit 1
51+
fi
52+
53+
# Read first line
54+
PR_NUMBER=""
55+
IFS= read -r PR_NUMBER < "$FILE" || true
56+
57+
# Validate whether it's a number
58+
if ! [[ "$PR_NUMBER" =~ ^[0-9]{1,10}$ ]]; then
59+
echo "Error: PR_NUMBER is not a valid integer on the first line." >&2
60+
exit 1
61+
fi
62+
63+
printf 'PR_NUMBER=%s\n' "$PR_NUMBER" >> "$GITHUB_ENV"
64+
65+
- name: Post PR Comment
66+
uses: ctrf-io/github-test-reporter@v1
67+
with:
68+
report-path: 'ctrf/**/*.json'
69+
issue: ${{ env.PR_NUMBER }}
70+
71+
summary: true
72+
pull-request: true
73+
use-suite-name: true
74+
update-comment: true
75+
always-group-by: true
76+
overwrite-comment: true
77+
upload-artifact: false
78+
79+
pull-request-report: true
80+
env:
81+
GITHUB_TOKEN: ${{ github.token }}

src/ElectronNET.sln

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ EndProject
4242
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build", "Build", "{985D39A7-5216-4945-8167-2FD0CB387BD8}"
4343
ProjectSection(SolutionItems) = preProject
4444
..\.github\workflows\ci.yml = ..\.github\workflows\ci.yml
45+
..\.github\workflows\integration-tests.yml = ..\.github\workflows\integration-tests.yml
46+
..\.github\workflows\pr-comment.yml = ..\.github\workflows\pr-comment.yml
47+
..\.github\workflows\publish-wiki.yml = ..\.github\workflows\publish-wiki.yml
48+
..\.github\workflows\trailing-whitespace-check.yml = ..\.github\workflows\trailing-whitespace-check.yml
4549
EndProjectSection
4650
EndProject
4751
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "_build", "..\nuke\_build.csproj", "{015CB06B-6CAE-209F-E050-21C3ACA5FE9F}"

0 commit comments

Comments
 (0)