Codecov Comment on PR #7065
This file contains hidden or 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@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1 | |
| 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@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 | |
| 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@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 | |
| 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/codecov-action@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70 # v3.1.1 | |
| 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/codecov-action@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70 # v3.1.1 | |
| 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}} |