Codecov Comment on PR #1982
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
name: Codecov Comment on PR | |
# read-write repo token | |
# access to secrets | |
on: | |
workflow_run: | |
workflows: ["API (.NET 8)", "APP (React)"] | |
types: | |
- completed | |
jobs: | |
upload: | |
runs-on: ubuntu-22.04 | |
if: > | |
github.event.workflow_run.event == 'pull_request' && | |
github.event.workflow_run.conclusion == 'success' | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
repository: ${{ github.event.workflow_run.head_repository.full_name }} | |
ref: ${{ github.event.workflow_run.head_branch }} | |
fetch-depth: 0 | |
- name: "Download artifact" | |
uses: actions/github-script@v7 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
var artifacts = await github.rest.actions.listWorkflowRunArtifacts({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
run_id: ${{github.event.workflow_run.id }}, | |
}); | |
var matchArtifact = artifacts.data.artifacts.filter((artifact) => { | |
return artifact.name == "pr-codecov" | |
})[0]; | |
var download = await github.rest.actions.downloadArtifact({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
artifact_id: matchArtifact.id, | |
archive_format: 'zip', | |
}); | |
var fs = require('fs'); | |
fs.writeFileSync('${{github.workspace}}/pr.zip', Buffer.from(download.data)); | |
- run: unzip pr.zip | |
- name: "Comment on PR" | |
id: create-comment | |
uses: actions/github-script@v7 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
var fs = require('fs'); | |
var issue_number = Number(fs.readFileSync('./NR')); | |
await github.rest.issues.createComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: issue_number, | |
body: 'See CodeCov Report Here: https://app.codecov.io/github/bcgov/psp/pull/' + issue_number | |
}); | |
return issue_number; | |
result-encoding: string | |
- name: Codecov(API) | |
if: ${{ github.event.workflow_run.name == 'API (.NET 8)' }} | |
uses: codecov/[email protected] | |
env: | |
CODECOV_TOKEN: ${{ secrets.CODECOV }} | |
with: | |
# User defined upload name. Visible in Codecov UI | |
name: PIMS | |
# Path to coverage file to upload | |
file: ./coverage.opencover.xml | |
# Flag upload to group coverage metrics (e.g. unittests | integration | ui,chrome) | |
flags: unittests | |
env_vars: C# | |
# Specify whether or not CI build should fail if Codecov runs into an error during upload | |
fail_ci_if_error: false | |
override_pr: ${{steps.create-comment.outputs.result}} | |
- name: Codecov(APP) | |
if: ${{ github.event.workflow_run.name == 'APP (React)' }} | |
uses: codecov/[email protected] | |
env: | |
CODECOV_TOKEN: ${{ secrets.CODECOV }} | |
with: | |
# User defined upload name. Visible in Codecov UI | |
name: PIMS | |
# Path to coverage file to upload | |
file: ./coverage-final.json | |
# Flag upload to group coverage metrics (e.g. unittests | integration | ui,chrome) | |
flags: unittests | |
# Environment variables to tag the upload with (e.g. PYTHON | OS,PYTHON) | |
env_vars: javascript | |
# Specify whether or not CI build should fail if Codecov runs into an error during upload | |
fail_ci_if_error: false | |
override_pr: ${{steps.create-comment.outputs.result}} |