Skip to content

Commit ef3c78b

Browse files
committed
Apply recommended and secure workflow structure
1 parent abd7d1d commit ef3c78b

File tree

2 files changed

+55
-4
lines changed

2 files changed

+55
-4
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ jobs:
2525
cache: 'gradle'
2626
- name: clean build
2727
run: ./gradlew clean build --info --stacktrace
28-
- name: Publish Test Report
28+
- name: Upload Test Results
29+
# see publish-test-results.yml for workflow that publishes test results without security issues for forks
30+
uses: actions/upload-artifact@v3
2931
if: ${{ always() }}
30-
uses: scacap/action-surefire-report@v1
3132
with:
32-
github_token: ${{ secrets.GITHUB_TOKEN }}
33-
report_paths: '**/build/test-results/test/TEST-*.xml'
33+
name: test-results
34+
path: '**/build/test-results/test/TEST-*.xml'
3435
...
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Publish Test results
2+
3+
# WARNING:
4+
# workflow_run provides read-write repo token and access to secrets.
5+
# Do *not* merge changes to this file without the proper review.
6+
# We should only be running trusted code here.
7+
# See https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
8+
# Docs: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#workflow_run
9+
on:
10+
workflow_run:
11+
workflows:
12+
- CI
13+
types:
14+
- completed
15+
16+
jobs:
17+
# Job based on https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
18+
publish-test-results:
19+
runs-on: ubuntu-latest
20+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
21+
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
26+
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
45+
- name: Publish Test Results
46+
uses: scacap/action-surefire-report@v1
47+
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'

0 commit comments

Comments
 (0)