From d799ad412875d1cffa169b44ce6bd873e4a3069c Mon Sep 17 00:00:00 2001 From: Spacetown <40258682+spacetown@users.noreply.github.com> Date: Sat, 17 Aug 2024 23:21:59 +0200 Subject: [PATCH] Add coverage upload workflow 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 --- .github/workflows/gcovr-ci-job.yml | 7 +++++ .github/workflows/upload_coverage.yml | 38 +++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 .github/workflows/upload_coverage.yml diff --git a/.github/workflows/gcovr-ci-job.yml b/.github/workflows/gcovr-ci-job.yml index 44974c143e..195bd1c96a 100644 --- a/.github/workflows/gcovr-ci-job.yml +++ b/.github/workflows/gcovr-ci-job.yml @@ -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 diff --git a/.github/workflows/upload_coverage.yml b/.github/workflows/upload_coverage.yml new file mode 100644 index 0000000000..e4bb7574fe --- /dev/null +++ b/.github/workflows/upload_coverage.yml @@ -0,0 +1,38 @@ +name: Upload coverage + +on: + workflow_run: + workflows: ['Run GCOVR Ci'] + types: + - completed + +jobs: + upload: + runs-on: ubuntu-22.04 + steps: + - name: 'Download artifact' + uses: actions/github-script@v3.1.0 + with: + script: | + var artifacts = await github.actions.listWorkflowRunArtifacts({ + owner: context.repo.owner, + repo: context.repo.repo, + run_id: ${{github.event.workflow_run.id }}, + }); + 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', + }); + 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 .