From 014d32bd28ba5092fdf11fe11298f587463960cd Mon Sep 17 00:00:00 2001 From: Darren Burns Date: Sun, 21 Jul 2024 23:45:34 +0100 Subject: [PATCH] Code coverage comment configuration --- .github/workflows/coverage.yml | 27 +++++++++++++++++++++++++++ .github/workflows/test.yml | 26 ++++++++++++++++++++++---- 2 files changed, 49 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/coverage.yml diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml new file mode 100644 index 00000000..052ec57a --- /dev/null +++ b/.github/workflows/coverage.yml @@ -0,0 +1,27 @@ +# This is a follow up job that runs after the CI job has completed. +# It'll post a code coverage comment on pull requests. +name: Post Coverage Comment + +on: + workflow_run: + workflows: ["Continuous Integration"] + types: + - completed + +jobs: + test: + name: Post Coverage Comment + runs-on: ubuntu-latest + if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' + permissions: + pull-requests: write + contents: write + actions: read + steps: + # !!! DO NOT run actions/checkout here, for security reasons !!! + # For details, refer to https://securitylab.github.com/research/github-actions-preventing-pwn-requests/ + - name: Post comment + uses: py-cov-action/python-coverage-comment-action@v3 + with: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_PR_RUN_ID: ${{ github.event.workflow_run.id }} \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a024ebde..ca6bfe09 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,12 +1,20 @@ -name: Test +name: Continuous Integration + +on: + pull_request: + push: + branches: + - "main" -on: [push, pull_request] env: PYTEST_ADDOPTS: "--color=yes" jobs: build: runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write steps: - uses: actions/checkout@v4 - name: Rye Python Setup @@ -21,11 +29,21 @@ jobs: make test - name: Attach Code Coverage uses: py-cov-action/python-coverage-comment-action@v3.25 + with: + GITHUB_TOKEN: ${{ github.token }} + - name: Save Snapshot Report if: always() - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: snapshot-report-posting path: snapshot_report.html - # TODO - fix file system ordering, see latest snapshot report + - name: Store Pull Request Comment + uses: actions/upload-artifact@v4 + if: steps.coverage_comment.outputs.COMMENT_FILE_WRITTEN == 'true' + with: + # If you use a different name, update COMMENT_ARTIFACT_NAME accordingly + name: python-coverage-comment-action + # If you use a different name, update COMMENT_FILENAME accordingly + path: python-coverage-comment-action.txt \ No newline at end of file