|
| 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