Skip to content

Commit 3de40a1

Browse files
committed
Publish test results using EnricoMi/publish-unit-test-result-action
1 parent 4bf1f07 commit 3de40a1

File tree

4 files changed

+114
-52
lines changed

4 files changed

+114
-52
lines changed

.github/workflows/cd.yml

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,51 @@ on:
55
branches:
66
- main
77
jobs:
8-
publish:
8+
event-file:
9+
# https://github.com/marketplace/actions/publish-test-results#support-fork-repositories-and-dependabot-branches
10+
name: "Event File"
911
runs-on: ubuntu-latest
12+
steps:
13+
- name: Upload
14+
uses: actions/upload-artifact@v3
15+
with:
16+
name: event-file
17+
path: ${{ github.event_path }}
18+
publish:
19+
strategy:
20+
matrix:
21+
os:
22+
- ubuntu-latest
23+
# - windows-latest
24+
# - macos-latest
25+
java:
26+
- 8
27+
# - 17
28+
runs-on: ${{ matrix.os }}
1029
timeout-minutes: 20
1130
steps:
1231
- uses: actions/checkout@v3
1332
with:
1433
fetch-depth: 1
1534
- name: Set up JDK
16-
uses: actions/setup-java@v3
35+
uses: actions/setup-java@v3.12.0
1736
with:
1837
distribution: 'zulu'
19-
java-version: 8
20-
cache: 'gradle'
38+
java-version: ${{ matrix.java }}
39+
- name: Setup Gradle
40+
uses: gradle/gradle-build-action@v2
2141
- name: build publish
2242
run: ./gradlew clean build publish --info --stacktrace
2343
env:
2444
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2545
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.GPG_SIGNING_KEY }}
2646
ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.GPG_SIGNING_PASSWORD }}
27-
- name: Publish Test Report
28-
if: ${{ always() }}
29-
uses: scacap/action-surefire-report@v1
47+
- name: Upload Test Results
48+
# see publish-test-results.yml for workflow that publishes test results without security issues for forks
49+
# https://github.com/marketplace/actions/publish-test-results#support-fork-repositories-and-dependabot-branches
50+
if: always()
51+
uses: actions/upload-artifact@v3
3052
with:
31-
github_token: ${{ secrets.GITHUB_TOKEN }}
32-
report_paths: '**/build/test-results/test/TEST-*.xml'
53+
name: Test Results (Java ${{ matrix.java }} on ${{ matrix.os }})
54+
path: '**/build/test-results/test/TEST-*.xml'
3355
...

.github/workflows/ci.yml

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,47 @@ on:
66
branches-ignore:
77
- main
88
jobs:
9+
event-file:
10+
# https://github.com/marketplace/actions/publish-test-results#support-fork-repositories-and-dependabot-branches
11+
name: "Event File"
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Upload
15+
uses: actions/upload-artifact@v3
16+
with:
17+
name: event-file
18+
path: ${{ github.event_path }}
919
ci-build:
1020
strategy:
1121
matrix:
12-
os: [ ubuntu-latest, windows-latest, macos-latest ]
13-
java: [ 8, 17 ]
22+
os:
23+
- ubuntu-latest
24+
- windows-latest
25+
- macos-latest
26+
java:
27+
- 8
28+
- 17
1429
runs-on: ${{ matrix.os }}
1530
timeout-minutes: 20
1631
steps:
1732
- uses: actions/checkout@v3
1833
with:
1934
fetch-depth: 1
2035
- name: Set up JDK
21-
uses: actions/setup-java@v3
36+
uses: actions/setup-java@v3.12.0
2237
with:
2338
distribution: 'zulu'
2439
java-version: ${{ matrix.java }}
25-
cache: 'gradle'
40+
- name: Setup Gradle
41+
uses: gradle/gradle-build-action@v2
2642
- name: clean build
2743
run: ./gradlew clean build --info --stacktrace
2844
- name: Upload Test Results
2945
# see publish-test-results.yml for workflow that publishes test results without security issues for forks
46+
# https://github.com/marketplace/actions/publish-test-results#support-fork-repositories-and-dependabot-branches
47+
if: always()
3048
uses: actions/upload-artifact@v3
31-
if: ${{ always() }}
3249
with:
33-
name: test-results
50+
name: Test Results (Java ${{ matrix.java }} on ${{ matrix.os }})
3451
path: '**/build/test-results/test/TEST-*.xml'
3552
...

.github/workflows/publish-test-results.yml

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,41 +10,42 @@ on:
1010
workflow_run:
1111
workflows:
1212
- CI
13+
- Publish
14+
- Release
1315
types:
1416
- completed
17+
permissions: {}
1518

1619
jobs:
17-
# Job based on https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
20+
# Job based on
21+
# - https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
22+
# - https://github.com/marketplace/actions/publish-test-results#support-fork-repositories-and-dependabot-branches
1823
publish-test-results:
1924
runs-on: ubuntu-latest
20-
if: ${{ github.event.workflow_run.conclusion == 'success' }}
25+
if: github.event.workflow_run.conclusion != 'skipped'
26+
27+
permissions:
28+
checks: write
29+
# needed unless run with comment_mode: off
30+
pull-requests: write
31+
# only needed for private repository
32+
#contents: read
33+
# only needed for private repository
34+
#issues: read
35+
# required by download step to access artifacts API
36+
actions: read
37+
2138
steps:
22-
# Unfortunately, the official actions/download-artifact action is very limited in scope.
23-
# Can't use it yet in this context, https://github.com/actions/download-artifact/issues/60
24-
- name: Download artifact
25-
uses: actions/github-script@v6
39+
- name: Download and Extract Artifacts
40+
uses: dawidd6/action-download-artifact@246dbf436b23d7c49e21a7ab8204ca9ecd1fe615
2641
with:
27-
script: |
28-
var artifacts = await github.rest.actions.listWorkflowRunArtifacts({
29-
owner: context.repo.owner,
30-
repo: context.repo.repo,
31-
run_id: ${{ github.event.workflow_run.id }},
32-
});
33-
var matchArtifact = artifacts.data.artifacts.filter((artifact) => {
34-
return artifact.name == "test-results"
35-
})[0];
36-
var download = await github.rest.actions.downloadArtifact({
37-
owner: context.repo.owner,
38-
repo: context.repo.repo,
39-
artifact_id: matchArtifact.id,
40-
archive_format: 'zip',
41-
});
42-
var fs = require('fs');
43-
fs.writeFileSync('${{github.workspace}}/test-results.zip', Buffer.from(download.data));
44-
- run: unzip test-results.zip
42+
run_id: ${{ github.event.workflow_run.id }}
43+
path: artifacts
4544
- name: Publish Test Results
46-
uses: scacap/action-surefire-report@v1
45+
uses: EnricoMi/publish-unit-test-result-action@v2
4746
with:
48-
commit: ${{ github.event.workflow_run.head_commit.id }}
49-
github_token: ${{ secrets.GITHUB_TOKEN }}
50-
report_paths: '**/build/test-results/test/TEST-*.xml'
47+
commit: ${{ github.event.workflow_run.head_sha }}
48+
event_file: artifacts/event-file/event.json
49+
event_name: ${{ github.event.workflow_run.event }}
50+
files: "artifacts/**/build/test-results/test/TEST-*.xml"
51+
...

.github/workflows/release.yml

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,39 @@ on:
77
# - published
88

99
jobs:
10-
release:
10+
event-file:
11+
# https://github.com/marketplace/actions/publish-test-results#support-fork-repositories-and-dependabot-branches
12+
name: "Event File"
1113
runs-on: ubuntu-latest
14+
steps:
15+
- name: Upload
16+
uses: actions/upload-artifact@v3
17+
with:
18+
name: event-file
19+
path: ${{ github.event_path }}
20+
release:
21+
strategy:
22+
matrix:
23+
os:
24+
- ubuntu-latest
25+
# - windows-latest
26+
# - macos-latest
27+
java:
28+
- 8
29+
# - 17
30+
runs-on: ${{ matrix.os }}
1231
timeout-minutes: 20
1332
steps:
1433
- uses: actions/checkout@v3
1534
with:
1635
fetch-depth: 1
1736
- name: Set up JDK
18-
uses: actions/setup-java@v3
37+
uses: actions/setup-java@v3.12.0
1938
with:
2039
distribution: 'zulu'
21-
java-version: 8
22-
cache: 'gradle'
40+
java-version: ${{ matrix.java }}
41+
- name: Setup Gradle
42+
uses: gradle/gradle-build-action@v2
2343
- name: Set artifact version
2444
run: |
2545
echo "RELEASE_VERSION=$(echo '${{ github.event.release.tag_name }}' | sed -e s/^v//)" >> $GITHUB_ENV
@@ -32,10 +52,12 @@ jobs:
3252
SONATYPE_STAGING_PROFILE_ID: ${{ secrets.SONATYPE_STAGING_PROFILE_ID }}
3353
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
3454
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
35-
- name: Publish Test Report
36-
if: ${{ always() }}
37-
uses: scacap/action-surefire-report@v1
55+
- name: Upload Test Results
56+
# see publish-test-results.yml for workflow that publishes test results without security issues for forks
57+
# https://github.com/marketplace/actions/publish-test-results#support-fork-repositories-and-dependabot-branches
58+
if: always()
59+
uses: actions/upload-artifact@v3
3860
with:
39-
github_token: ${{ secrets.GITHUB_TOKEN }}
40-
report_paths: '**/build/test-results/test/TEST-*.xml'
61+
name: Test Results (Java ${{ matrix.java }} on ${{ matrix.os }})
62+
path: '**/build/test-results/test/TEST-*.xml'
4163
...

0 commit comments

Comments
 (0)