Upload coverage to Codacy #34
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: Upload coverage to Codacy | |
| # Runs after the "Code coverage" workflow so that coverage uploaded for | |
| # pull requests from forks works too: the build runs in the (untrusted) PR | |
| # context without secrets and only produces an artifact; this workflow runs | |
| # from the default branch in the base-repo context, where CODACY_PROJECT_TOKEN | |
| # is available, and does the upload. It never checks out or runs PR code. | |
| on: | |
| workflow_run: | |
| workflows: [ "Code coverage" ] | |
| types: [ completed ] | |
| permissions: | |
| actions: read | |
| contents: read | |
| jobs: | |
| upload: | |
| name: Upload coverage to Codacy | |
| runs-on: ubuntu-24.04 | |
| if: ${{ github.event.workflow_run.conclusion == 'success' }} | |
| env: | |
| CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }} | |
| steps: | |
| - name: Download coverage artifact | |
| uses: actions/download-artifact@v8 | |
| with: | |
| name: coverage-report | |
| path: artifact | |
| run-id: ${{ github.event.workflow_run.id }} | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Read and validate commit SHA | |
| id: meta | |
| run: | | |
| sha="$(cat artifact/commit-sha.txt)" | |
| if ! printf '%s' "$sha" | grep -Eq '^[0-9a-f]{40}$'; then | |
| echo "Invalid commit SHA in artifact: '$sha'" >&2 | |
| exit 1 | |
| fi | |
| echo "sha=$sha" >> "$GITHUB_OUTPUT" | |
| - name: Upload coverage to Codacy | |
| if: ${{ env.CODACY_PROJECT_TOKEN != '' }} | |
| env: | |
| COMMIT_SHA: ${{ steps.meta.outputs.sha }} | |
| run: | | |
| bash <(curl -Ls https://coverage.codacy.com/get.sh) report \ | |
| --force-coverage-parser cobertura \ | |
| --prefix chris_backend/ \ | |
| -r artifact/coverage.xml \ | |
| --commit-uuid "$COMMIT_SHA" |