Skip to content

Commit

Permalink
Add coverage upload workflow
Browse files Browse the repository at this point in the history
Because of credentials needed to upload to Codacy we need to add a
separate workflow which is executed in the context of the target
repository to see the credentials for uploading
  • Loading branch information
Spacetown committed Aug 18, 2024
1 parent 239ca42 commit 4336f19
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/gcovr-ci-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ jobs:
name: "diffs-${{ inputs.container && format('docker-{0}', inputs.gcc) || format('{0}-{1}-{2}', inputs.os, inputs.gcc, inputs.python-version) }}"
path: tests/diff.zip

- name: Upload coverage report
if: ${{ env.USE_COVERAGE == 'true' }}
uses: actions/upload-artifact@v4
with:
name: "coverage-${{ inputs.container && format('docker-{0}', inputs.gcc) || format('{0}-{1}-{2}', inputs.os, inputs.gcc, inputs.python-version) }}"
path: ./coverage.xml

- name: Upload coverage to Codecov
if: ${{ (github.repository == 'gcovr/gcovr') && (env.USE_COVERAGE == 'true') }}
uses: codecov/codecov-action@v4
Expand Down
51 changes: 51 additions & 0 deletions .github/workflows/upload_coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Upload coverage

on:
workflow_run:
workflows: ['Run GCOVR Ci']
types:
- completed

jobs:
upload:
runs-on: ubuntu-22.04
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
pattern: coverage-*
run-id: ${{ github.event.workflow_run.id }}
# github-token: ${{ secrets.GITHUB_TOKEN }}

- name: 'Download artifact'
uses: actions/[email protected]
with:
script: |
var artifacts = await github.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{github.event.workflow_run.id }},
headers: {
'Authorization': 'Bearer ' + ${{ github.token }}
}
});
var matchArtifacts = artifacts.data.artifacts.filter((artifact) => {
return artifact.name.startsWith("coverage-")
});
for (const artifact of matchArtifacts) {
var download = await github.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: artifact.id,
archive_format: 'zip',
headers: {
'Authorization': 'Bearer ${{ secrets.github-token }}'
}
});
var fs = require('fs');
fs.writeFileSync('${{github.workspace}}/' + artifact.id + '.zip', Buffer.from(download.data));
}
- name: Unzip the artifacts
run: |
unzip coverage*.zip
ls -alR .

0 comments on commit 4336f19

Please sign in to comment.