fix(ci): publish PR test results from workflow_run

- stop publishing unit test results directly from the pull_request test jobs\n- upload the GitHub event payload from CI so a follow-up workflow can reuse the original PR context\n- add a workflow_run publisher that downloads backend/frontend test artifacts and posts the check runs and PR comments with the permissions Dependabot PRs require\n- keep the reusable test suite focused on executing tests and producing artifacts without failing on comment permissions
This commit is contained in:
James Cox
2026-03-20 17:20:18 -05:00
parent 62be6b152c
commit 11a76bffe1
3 changed files with 97 additions and 2 deletions
+17
View File
@@ -10,6 +10,22 @@ on:
- develop - develop
jobs: jobs:
upload-event-file:
name: Upload Event File
if: ${{ github.event_name != 'push' || !contains(github.event.head_commit.message, '[skip ci]') }}
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Upload GitHub Event Payload
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
with:
name: ci-event-file
path: ${{ github.event_path }}
retention-days: 7
migration-check: migration-check:
name: Flyway Migration Check name: Flyway Migration Check
if: ${{ github.event_name != 'push' || !contains(github.event.head_commit.message, '[skip ci]') }} if: ${{ github.event_name != 'push' || !contains(github.event.head_commit.message, '[skip ci]') }}
@@ -29,6 +45,7 @@ jobs:
checks: write checks: write
with: with:
checkout_ref: ${{ github.sha }} checkout_ref: ${{ github.sha }}
publish_test_results: false
packaging-smoke-test: packaging-smoke-test:
name: Packaging Smoke Test name: Packaging Smoke Test
@@ -0,0 +1,73 @@
name: Test Results - Publish
on:
workflow_run:
workflows:
- CI - Validate
types:
- completed
jobs:
publish-test-results:
name: Publish Test Results
if: ${{ github.event.workflow_run.conclusion == 'success' || github.event.workflow_run.conclusion == 'failure' }}
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
checks: write
pull-requests: write
steps:
- name: Download Workflow Artifacts
uses: actions/download-artifact@f1b1db2786a679e8eff8e5f0383478a629e823fc # v5.0.0
with:
github-token: ${{ github.token }}
repository: ${{ github.repository }}
run-id: ${{ github.event.workflow_run.id }}
path: artifacts
- name: Detect Published Test Artifacts
id: detect
run: |
set -eu
if [ -f "artifacts/ci-event-file/event.json" ]; then
echo "event_file=artifacts/ci-event-file/event.json" >> "$GITHUB_OUTPUT"
else
echo "Missing ci-event-file artifact; cannot publish test results." >&2
exit 1
fi
if find artifacts/backend-test-reports -name '*.xml' -print -quit | grep -q .; then
echo "backend_present=true" >> "$GITHUB_OUTPUT"
else
echo "backend_present=false" >> "$GITHUB_OUTPUT"
fi
if find artifacts/frontend-test-reports -name '*.xml' -print -quit | grep -q .; then
echo "frontend_present=true" >> "$GITHUB_OUTPUT"
else
echo "frontend_present=false" >> "$GITHUB_OUTPUT"
fi
- name: Publish Backend Test Results
if: ${{ steps.detect.outputs.backend_present == 'true' }}
uses: EnricoMi/publish-unit-test-result-action@c950f6fb443cb5af20a377fd0dfaa78838901040 # v2
with:
commit: ${{ github.event.workflow_run.head_sha }}
event_file: ${{ steps.detect.outputs.event_file }}
event_name: ${{ github.event.workflow_run.event }}
files: artifacts/backend-test-reports/**/*.xml
check_name: Backend Test Results
- name: Publish Frontend Test Results
if: ${{ steps.detect.outputs.frontend_present == 'true' }}
uses: EnricoMi/publish-unit-test-result-action@c950f6fb443cb5af20a377fd0dfaa78838901040 # v2
with:
commit: ${{ github.event.workflow_run.head_sha }}
event_file: ${{ steps.detect.outputs.event_file }}
event_name: ${{ github.event.workflow_run.event }}
files: artifacts/frontend-test-reports/**/*.xml
check_name: Frontend Test Results
+7 -2
View File
@@ -7,6 +7,11 @@ on:
description: 'The ref to check out before running tests' description: 'The ref to check out before running tests'
required: true required: true
type: string type: string
publish_test_results:
description: 'Whether to publish test results directly from this workflow'
required: false
type: boolean
default: true
jobs: jobs:
backend-tests: backend-tests:
@@ -41,7 +46,7 @@ jobs:
- name: Publish Backend Test Results - name: Publish Backend Test Results
uses: EnricoMi/publish-unit-test-result-action@c950f6fb443cb5af20a377fd0dfaa78838901040 # v2 uses: EnricoMi/publish-unit-test-result-action@c950f6fb443cb5af20a377fd0dfaa78838901040 # v2
if: always() if: ${{ always() && inputs.publish_test_results }}
with: with:
files: booklore-api/build/test-results/**/*.xml files: booklore-api/build/test-results/**/*.xml
check_name: Backend Test Results check_name: Backend Test Results
@@ -106,7 +111,7 @@ jobs:
- name: Publish Frontend Test Results - name: Publish Frontend Test Results
uses: EnricoMi/publish-unit-test-result-action@c950f6fb443cb5af20a377fd0dfaa78838901040 # v2 uses: EnricoMi/publish-unit-test-result-action@c950f6fb443cb5af20a377fd0dfaa78838901040 # v2
if: always() if: ${{ always() && inputs.publish_test_results }}
with: with:
files: booklore-ui/test-results/vitest-results.xml files: booklore-ui/test-results/vitest-results.xml
check_name: Frontend Test Results check_name: Frontend Test Results