|
| 1 | +name: Export Coverage Data |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_run: |
| 5 | + # IMPORTANT: Replace "Run Tests and Upload Coverage" with the EXACT name |
| 6 | + # of your workflow file (e.g., ci.yml) or the 'name:' attribute defined in that workflow file. |
| 7 | + workflows: ["Lint & Test"] |
| 8 | + types: |
| 9 | + - completed |
| 10 | +# branches: # Only run for completions on these branches of the source workflow |
| 11 | +# - update-readme # Or your primary development branch |
| 12 | + |
| 13 | +jobs: |
| 14 | + export-coverage: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + # Only run this job if the triggering workflow (Producer) was successful |
| 17 | + # if: ${{ github.event.workflow_run.conclusion == 'success' }} |
| 18 | + steps: |
| 19 | + - name: Checkout repository |
| 20 | + uses: actions/checkout@v4 |
| 21 | + # This checkout is to get the peaceiris/actions-gh-pages action and context, |
| 22 | + # the actual coverage file will be downloaded as an artifact. |
| 23 | + |
| 24 | + - name: Download badge |
| 25 | + uses: actions/download-artifact@v4 |
| 26 | + with: |
| 27 | + # This name MUST match the 'name' provided to 'actions/upload-artifact' |
| 28 | + # in your Producer Workflow. |
| 29 | + name: coverage-badge |
| 30 | + # The artifact is downloaded from the workflow run that triggered this workflow. |
| 31 | + # 'actions/download-artifact' will download it to the root of the workspace |
| 32 | + # if the uploaded artifact was a single file. |
| 33 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 34 | + run_id: ${{ github.event.workflow_run.id }} |
| 35 | + |
| 36 | + # After download, the artifact (e.g., coverage.xml or coverage.json) |
| 37 | + # should be in the root of your workspace. |
| 38 | + # Verify the filename matches what you expect (e.g., coverage.xml or coverage.json). |
| 39 | + |
| 40 | + - name: Deploy coverage report to branch |
| 41 | + uses: peaceiris/actions-gh-pages@v4 |
| 42 | + with: |
| 43 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 44 | + publish_branch: coverage # Branch to push the coverage file to |
| 45 | + # This directory should contain the downloaded artifact. |
| 46 | + # If 'actions/download-artifact' places 'coverage.xml' at the root, '.' is correct. |
| 47 | + publish_dir: . |
| 48 | + # IMPORTANT: This MUST be the actual filename of your coverage report |
| 49 | + # as it exists after being downloaded by 'actions/download-artifact'. |
| 50 | + # e.g., coverage.xml or coverage.json |
| 51 | + keep_files: coverage-badge.svg # Or coverage.json |
| 52 | + user_name: 'github-actions[bot]' |
| 53 | + user_email: 'github-actions[bot]@users.noreply.github.com' |
| 54 | + commit_message: 'chore: Update coverage data from workflow run ${{ github.event.workflow_run.id }}' |
| 55 | + # force_orphan: true # Optional: Create a completely new branch without history |
| 56 | + # allow_empty_commit: false # Default is false, change if needed |
0 commit comments