Skip to content

Commit 689b3eb

Browse files
committed
Split PR workflow into main run that operates in the PR context (with a read-only token) and a separate "workflow_run" triggered phase that can publish the test results.
1 parent 4bea713 commit 689b3eb

File tree

2 files changed

+59
-4
lines changed

2 files changed

+59
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Test Reports (PR)
2+
3+
on:
4+
workflow_run:
5+
workflows: ["Pull Request"]
6+
types:
7+
- completed
8+
9+
permissions: {}
10+
11+
jobs:
12+
test-results:
13+
name: Test Results
14+
runs-on: ubuntu-latest
15+
if: github.event.workflow_run.conclusion != 'skipped'
16+
17+
permissions:
18+
checks: write
19+
pull-requests: write
20+
actions: read
21+
22+
steps:
23+
- name: Download and Extract Artifacts
24+
env:
25+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
26+
run: |
27+
mkdir -p artifacts && cd artifacts
28+
29+
artifacts_url=${{ github.event.workflow_run.artifacts_url }}
30+
31+
gh api --paginate "$artifacts_url" -q '.artifacts[] | [.name, .archive_download_url] | @tsv' | while read artifact
32+
do
33+
IFS=$'\t' read name url <<< "$artifact"
34+
gh api $url > "$name.zip"
35+
unzip -d "$name" "$name.zip"
36+
done
37+
38+
- name: Publish Test Results
39+
uses: EnricoMi/publish-unit-test-result-action@v2
40+
with:
41+
commit: ${{ github.event.workflow_run.head_sha }}
42+
event_file: artifacts/Event File/event.json
43+
event_name: ${{ github.event.workflow_run.event }}
44+
junit_files: "artifacts/Test Results/**/*.xml"

.github/workflows/pull-request.yaml

+15-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: CI (Pull Request)
1+
name: Pull Request
22

33
on:
44
pull_request:
@@ -65,12 +65,23 @@ jobs:
6565
- name: Build with Maven
6666
run: mvn --batch-mode -e clean install
6767

68-
- name: Publish Test Report
69-
uses: scacap/action-surefire-report@v1
68+
- name: Upload Test Results
7069
if: success() || failure()
70+
uses: actions/upload-artifact@v2
7171
with:
72-
fail_if_no_tests: false
72+
name: Test Results
73+
path: |
74+
target/surefire-reports/*.xml
7375
7476
- name: Build site
7577
run: mvn --batch-mode -e -DskipTests site
7678

79+
event_file:
80+
name: "Event File"
81+
runs-on: ubuntu-latest
82+
steps:
83+
- name: Upload
84+
uses: actions/upload-artifact@v2
85+
with:
86+
name: Event File
87+
path: ${{ github.event_path }}

0 commit comments

Comments
 (0)