-
Notifications
You must be signed in to change notification settings - Fork 527
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
73 additions
and
97 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,91 @@ | ||
# A separate workflow to comment the coverage report on the pull request | ||
# Contains jobs corresponding to publishing coverage reports generated by code_coverage.yml. | ||
|
||
name: Comment Coverage Report | ||
|
||
# This triggers the workflow when the Code Coverage Report workflow completes | ||
# Controls when the action will run. Triggers the workflow on pull request events | ||
# (opened, synchronize, reopened) | ||
|
||
on: | ||
workflow_run: | ||
workflows: ["Code Coverage Report"] | ||
types: [completed] | ||
pull_request_target: | ||
types: [opened, synchronize, reopened] | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
comment_coverage: | ||
name: Comment Coverage Report on PR | ||
if: ${{ github.event.workflow_run.conclusion == 'success' }} | ||
check_code_coverage_completed: | ||
name: Check code coverage completed | ||
runs-on: ubuntu-latest | ||
outputs: | ||
conclusion: ${{ steps.wait-for-coverage.outputs.run-conclusion }} | ||
steps: | ||
- name: Wait for code coverage to complete | ||
id: wait-for-coverage | ||
uses: ArcticLampyrid/[email protected] | ||
with: | ||
workflow: code_coverage.yml | ||
sha: auto | ||
allowed-conclusions: | | ||
success | ||
failure | ||
action_required | ||
- name: Conclusion Analysis | ||
if: steps.wait-for-coverage.outputs.run-conclusion == 'action_required' | ||
run: | | ||
echo "::warning::Code coverage workflow requires manual approval. After approval, please re-run this workflow to post the coverage report." | ||
comment_coverage_report: | ||
name: Comment Code Coverage Report | ||
needs: check_code_coverage_completed | ||
permissions: | ||
pull-requests: write | ||
|
||
# The expression if: ${{ !cancelled() && needs.check_code_coverage_completed.outputs.conclusion != 'action_required' }} | ||
# ensures that this job only runs if the previous job was not cancelled and does not require manual approval. | ||
# This check prevents running the job unnecessarily when a manual approval is needed. | ||
if: | | ||
!cancelled() && | ||
needs.check_code_coverage_completed.outputs.conclusion != 'action_required' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Get PR information | ||
uses: potiuk/get-workflow-origin@v1_3 | ||
id: source-run-info | ||
- name: Find CI workflow run for PR | ||
id: find-workflow-run | ||
uses: actions/github-script@v7 | ||
continue-on-error: true | ||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
sourceRunId: ${{ github.event.workflow_run.id }} | ||
script: | | ||
// Find the last successful workflow run for the current PR's head | ||
const { owner, repo } = context.repo; | ||
const runsResponse = await github.rest.actions.listWorkflowRuns({ | ||
owner, | ||
repo, | ||
workflow_id: 'code_coverage.yml', | ||
event: 'pull_request', | ||
head_sha: '${{ github.event.pull_request.head.sha }}', | ||
}); | ||
const runs = runsResponse.data.workflow_runs; | ||
runs.sort((a, b) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime()); | ||
const run = runs[0]; | ||
if(!run) { | ||
core.setFailed('Could not find a successful workflow run for the PR'); | ||
return; | ||
} | ||
core.setOutput('run-id', run.id); | ||
- name: Download Coverage Report | ||
uses: dawidd6/action-download-artifact@v3 | ||
- name: Download Generated Markdown Report | ||
uses: actions/download-artifact@v4 | ||
if: ${{ !cancelled() }} # IMPORTANT: Upload reports regardless of success or failure status | ||
with: | ||
name: coverage-report-for-comment | ||
workflow: ${{ github.event.workflow_run.workflow_id }} | ||
run_id: ${{ github.event.workflow_run.id }} | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
name: final-coverage-report | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
run-id: ${{ steps.find-workflow-run.outputs.run-id }} | ||
|
||
- name: Comment on PR | ||
if: steps.source-run-info.outputs.pullRequestNumber != '' | ||
- name: Upload Coverage Report as PR Comment | ||
uses: peter-evans/create-or-update-comment@v4 | ||
with: | ||
issue-number: ${{ steps.source-run-info.outputs.pullRequestNumber }} | ||
issue-number: ${{ github.event.pull_request.number }} | ||
body-path: 'CoverageReport.md' |