|
| 1 | +name: Upload test results |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_run: |
| 5 | + workflows: ["Tests and lints"] |
| 6 | + types: [completed] |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: read |
| 10 | + pull-requests: write |
| 11 | + |
| 12 | +jobs: |
| 13 | + upload: |
| 14 | + if: github.event.workflow_run.conclusion != 'cancelled' |
| 15 | + runs-on: ubuntu-latest |
| 16 | + steps: |
| 17 | + - name: Resolve PR number |
| 18 | + id: pr |
| 19 | + uses: actions/github-script@v7 |
| 20 | + with: |
| 21 | + script: | |
| 22 | + const run = context.payload.workflow_run; |
| 23 | + // Prefer PR info embedded in the workflow_run payload |
| 24 | + if (run.pull_requests && run.pull_requests.length > 0) { |
| 25 | + core.setOutput('number', String(run.pull_requests[0].number)); |
| 26 | + } else { |
| 27 | + // Fallback: find PR by commit SHA |
| 28 | + const {owner, repo} = context.repo; |
| 29 | + const {data} = await github.rest.repos.listPullRequestsAssociatedWithCommit({ |
| 30 | + owner, repo, commit_sha: run.head_sha |
| 31 | + }); |
| 32 | + core.setOutput('number', data[0]?.number ? String(data[0].number) : ''); |
| 33 | + } |
| 34 | +
|
| 35 | + - name: Download report artifact |
| 36 | + if: steps.pr.outputs.number != '' |
| 37 | + uses: dawidd6/action-download-artifact@v3 |
| 38 | + with: |
| 39 | + run_id: ${{ github.event.workflow_run.id }} |
| 40 | + name: test-report |
| 41 | + path: ./report |
| 42 | + |
| 43 | + - name: Deploy preview to Cloudflare Pages |
| 44 | + if: steps.pr.outputs.number != '' |
| 45 | + id: pages |
| 46 | + uses: cloudflare/pages-action@v1 |
| 47 | + with: |
| 48 | + apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} |
| 49 | + accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} |
| 50 | + projectName: natrix-test-result |
| 51 | + directory: ./report |
| 52 | + branch: pr-${{ steps.pr.outputs.number }}-${{ github.event.workflow_run.head_sha }} |
| 53 | + gitHubToken: ${{ secrets.GITHUB_TOKEN }} |
| 54 | + |
| 55 | + - name: Comment on PR with preview URL |
| 56 | + if: steps.pr.outputs.number != '' && steps.pages.outputs.url != '' |
| 57 | + uses: marocchino/sticky-pull-request-comment@v2 |
| 58 | + with: |
| 59 | + header: test-report-preview |
| 60 | + number: ${{ steps.pr.outputs.number }} |
| 61 | + message: | |
| 62 | + Test report: ${{ steps.pages.outputs.url }} |
| 63 | +
|
| 64 | + - name: Add to job summary |
| 65 | + if: steps.pages.outputs.url != '' |
| 66 | + run: | |
| 67 | + echo 'Test report preview: ${{ steps.pages.outputs.url }}' >> $GITHUB_STEP_SUMMARY |
0 commit comments