diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml new file mode 100644 index 0000000..289e605 --- /dev/null +++ b/.github/workflows/coverage.yml @@ -0,0 +1,43 @@ +name: report coverage + +on: + workflow_run: + workflows: [test] + types: + - completed + +jobs: + report-coverage: + if: ${{ github.event.workflow_run.conclusion == 'success' }} + runs-on: ubuntu-latest + + steps: + - name: download coverage artifact + uses: actions/github-script@v6 + 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" + })[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.zip`, Buffer.from(download.data)); + + - name: unzip artifact + run: unzip coverage.zip + + - name: run codacy-coverage-reporter + uses: codacy/codacy-coverage-reporter-action@v1 + with: + project-token: ${{ secrets.CODACY_PROJECT_TOKEN }} + coverage-reports: coverage.xml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 30c6cd3..2a05218 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -45,9 +45,9 @@ jobs: run: | pytest tests --cov=sparselm --cov-report=xml - - if: ${{ matrix.python_version == 3.11 && github.event_name == 'push' }} - name: codacy-coverage-reporter - uses: codacy/codacy-coverage-reporter-action@v1 + - if: matrix.python_version == '3.11' + name: upload coverage report + uses: actions/upload-artifact@v3 with: - project-token: ${{ secrets.CODACY_PROJECT_TOKEN }} - coverage-reports: coverage.xml + name: coverage + path: coverage.xml