|
| 1 | +name: Publish and clean test results |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_run: |
| 5 | + workflows: ["Wokwi tests"] |
| 6 | + types: |
| 7 | + - completed |
| 8 | + |
| 9 | +# No permissions by default |
| 10 | +permissions: { contents: read } |
| 11 | + |
| 12 | +jobs: |
| 13 | + unit-test-results: |
| 14 | + name: Unit Test Results |
| 15 | + if: | |
| 16 | + github.event.workflow_run.conclusion == 'success' || |
| 17 | + github.event.workflow_run.conclusion == 'failure' || |
| 18 | + github.event.workflow_run.conclusion == 'timed_out' |
| 19 | + runs-on: ubuntu-latest |
| 20 | + permissions: |
| 21 | + actions: write |
| 22 | + statuses: write |
| 23 | + checks: write |
| 24 | + pull-requests: write |
| 25 | + steps: |
| 26 | + - name: Download and Extract Artifacts |
| 27 | + uses: dawidd6/action-download-artifact@v6 |
| 28 | + with: |
| 29 | + run_id: ${{ github.event.workflow_run.id }} |
| 30 | + path: ./artifacts |
| 31 | + |
| 32 | + - name: Get original info |
| 33 | + run: | |
| 34 | + original_event=$(cat ./artifacts/parent-artifacts/event.txt) |
| 35 | + original_action=$(cat ./artifacts/parent-artifacts/action.txt) |
| 36 | + original_sha=$(cat ./artifacts/parent-artifacts/sha.txt) |
| 37 | + original_ref=$(cat ./artifacts/parent-artifacts/ref.txt) |
| 38 | + echo "original_event=$original_event" >> $GITHUB_ENV |
| 39 | + echo "original_action=$original_action" >> $GITHUB_ENV |
| 40 | + echo "original_sha=$original_sha" >> $GITHUB_ENV |
| 41 | + echo "original_ref=$original_ref" >> $GITHUB_ENV |
| 42 | +
|
| 43 | + echo "original_event = $original_event" |
| 44 | + echo "original_action = $original_action" |
| 45 | + echo "original_sha = $original_sha" |
| 46 | + echo "original_ref = $original_ref" |
| 47 | +
|
| 48 | + - name: Publish Unit Test Results |
| 49 | + uses: EnricoMi/publish-unit-test-result-action@v2 |
| 50 | + with: |
| 51 | + commit: ${{ env.original_sha }} |
| 52 | + event_file: ./artifacts/parent-artifacts/event_file/event.json |
| 53 | + event_name: ${{ env.original_event }} |
| 54 | + files: ./artifacts/**/*.xml |
| 55 | + action_fail: true |
| 56 | + |
| 57 | + - name: Clean up caches |
| 58 | + uses: actions/github-script@v7 |
| 59 | + with: |
| 60 | + script: | |
| 61 | + const ref = '${{ env.original_ref }}'; |
| 62 | + const key_prefix = 'tests-' + ref + '-'; |
| 63 | +
|
| 64 | + if ('${{ env.original_event }}' == 'pull_request' && '${{ env.original_action }}' != 'closed') { |
| 65 | + console.log('Skipping cache cleanup for open PR'); |
| 66 | + return; |
| 67 | + } |
| 68 | +
|
| 69 | + await github.paginate(github.rest.actions.getActionsCacheList, { |
| 70 | + owner: context.repo.owner, |
| 71 | + repo: context.repo.repo, |
| 72 | + per_page: 100, |
| 73 | + key: key_prefix |
| 74 | + }).then(caches => { |
| 75 | + if (caches) { |
| 76 | + for (const cache of caches) { |
| 77 | + console.log(`Deleting cache: ${cache.key}`); |
| 78 | + github.rest.actions.deleteActionsCacheById({ |
| 79 | + owner: context.repo.owner, |
| 80 | + repo: context.repo.repo, |
| 81 | + cache_id: cache.id |
| 82 | + }); |
| 83 | + } |
| 84 | + } |
| 85 | + }); |
| 86 | +
|
| 87 | + - name: Report conclusion |
| 88 | + uses: actions/github-script@v7 |
| 89 | + if: always() |
| 90 | + with: |
| 91 | + script: | |
| 92 | + const owner = '${{ github.repository_owner }}'; |
| 93 | + const repo = '${{ github.repository }}'.split('/')[1]; |
| 94 | + const sha = '${{ env.original_sha }}'; |
| 95 | + core.debug(`owner: ${owner}`); |
| 96 | + core.debug(`repo: ${repo}`); |
| 97 | + core.debug(`sha: ${sha}`); |
| 98 | + const { context: name, state } = (await github.rest.repos.createCommitStatus({ |
| 99 | + context: 'Runtime Tests / Report results (${{ env.original_event }} -> workflow_run -> workflow_run)', |
| 100 | + owner: owner, |
| 101 | + repo: repo, |
| 102 | + sha: sha, |
| 103 | + state: '${{ job.status }}', |
| 104 | + description: '${{ job.status }}' ? 'Runtime tests successful' : 'Runtime tests failed', |
| 105 | + target_url: 'https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}' |
| 106 | + })).data; |
| 107 | + core.info(`${name} is ${state}`); |
0 commit comments