Skip to content

Coverage Upload

Coverage Upload #4

name: Coverage Upload
on:
workflow_run:
workflows: [testing]
types:
- completed
jobs:
run_tests:
runs-on: ubuntu-latest
steps:
# https://github.com/actions/github-script
# Based on: https://github.com/orgs/community/discussions/34652
- name: 'Download artifact'
uses: actions/github-script@v7
with:
script: |
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id,
});
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
return artifact.name == "coverage-report"
})[0];
let download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
let fs = require('fs');
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/coverage-report.zip`, Buffer.from(download.data));
- name: 'Unzip artifact'
run: unzip coverage-report.zip
# https://github.com/actions/download-artifact
# - name: Download artifact
# id: download-artifact
# uses: actions/download-artifact@v4
# with:
# run-id: ${{ github.event.workflow_run.id }}
# https://github.com/codacy/codacy-coverage-reporter-action
# - name: Run codacy-coverage-reporter
# uses: codacy/codacy-coverage-reporter-action@v1
# with:
# project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
# coverage-reports: coverage.xml
- name: Publish Code Coverage Results
run: |
auth="--project-token ${{ secrets.CODACY_PROJECT_TOKEN }}"
commit_uuid="--commit-uuid ${{ github.event.workflow_run.head_sha }}"
bash <(curl -Ls https://coverage.codacy.com/get.sh) report $auth $commit_uuid --force-coverage-parser go -r coverage.out --partial &&\
bash <(curl -Ls https://coverage.codacy.com/get.sh) final $auth $commit_uuid