Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
manas-yu committed Nov 11, 2024
2 parents e32888e + 971dbec commit 97d0dbb
Showing 1 changed file with 36 additions and 59 deletions.
95 changes: 36 additions & 59 deletions .github/workflows/comment_coverage_report.yml
Original file line number Diff line number Diff line change
@@ -1,81 +1,58 @@
<<<<<<< HEAD
# Contains jobs corresponding to publishing coverage reports generated by code_coverage.yml.

name: Comment Coverage Report

# Controls when the action will run. Triggers the workflow on pull request events
# (opened, synchronize, reopened)

on:
pull_request_target:
types: [opened, synchronize, reopened]
workflow_run:
workflows: ["Code Coverage"] # This must exactly match the name in code_coverage.yml
types:
- completed

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }}
cancel-in-progress: true
permissions:
pull-requests: write
actions: read

jobs:
check_code_coverage_completed:
name: Check code coverage completed
runs-on: ubuntu-latest
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
comment_coverage_report:
name: Comment Code Coverage Report
needs: check_code_coverage_completed
permissions:
pull-requests: write

# The expression if: ${{ !cancelled() }} runs a job or step regardless of its success or failure while responding to cancellations,
# serving as a cancellation-compliant alternative to if: ${{ always() }} in concurrent workflows.
if: ${{ !cancelled() }}
runs-on: ubuntu-latest
if: github.event.workflow_run.conclusion != 'cancelled'
steps:
- name: Find CI workflow run for PR
id: find-workflow-run
- name: Download Coverage Report
uses: dawidd6/action-download-artifact@v3
with:
workflow: Code Coverage
name: final-coverage-report
run_id: ${{ github.event.workflow_run.id }}

- name: Get PR Number
uses: actions/github-script@v7
continue-on-error: true
id: find-pr
with:
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({
const { head_sha } = context.payload.workflow_run;
// Search for PR associated with this commit
const result = await github.rest.repos.listPullRequestsAssociatedWithCommit({
owner,
repo,
workflow_id: 'code_coverage.yml',
event: 'pull_request',
head_sha: '${{ github.event.pull_request.head.sha }}',
commit_sha: 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 succesful workflow run for the PR');
if (result.data.length === 0) {
console.log('No PR found for this commit');
return;
}
core.setOutput('run-id', run.id);
- name: Download Generated Markdown Report
uses: actions/download-artifact@v4
if: ${{ !cancelled() }} # IMPORTANT: Upload reports regardless of success or failure status
with:
name: final-coverage-report
github-token: ${{ secrets.GITHUB_TOKEN }}
run-id: ${{ steps.find-workflow-run.outputs.run-id }}

- name: Upload Coverage Report as PR Comment
// Get the PR number
const prNumber = result.data[0].number;
core.setOutput('pr_number', prNumber);
core.setOutput('found', 'true');
- name: Comment Coverage Report
if: steps.find-pr.outputs.found == 'true'
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ github.event.pull_request.number }}
body-path: 'CoverageReport.md'
issue-number: ${{ steps.find-pr.outputs.pr_number }}
body-file: 'CoverageReport.md'

0 comments on commit 97d0dbb

Please sign in to comment.