From 2c7368f0321193fc1a9e4d611c438ff930c8f1cc Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Tue, 9 Jan 2024 16:53:10 -0500 Subject: [PATCH 1/6] build: replace codecov with python-coverage-comment-action --- .coveragerc | 1 + .github/workflows/ci.yml | 13 ++++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/.coveragerc b/.coveragerc index 6e796b61..bd5e6c63 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,5 +1,6 @@ [run] branch = True +relative_files = True data_file = .coverage source=openedx_events omit = diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 89cdba0c..f1bc7d6e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -36,9 +36,12 @@ jobs: TOXENV: ${{ matrix.toxenv }} run: tox - - name: Run coverage - if: matrix.python-version == '3.8' && matrix.toxenv == 'django42' - uses: codecov/codecov-action@v3 + - name: Report coverage + if: matrix.python-version == '3.8' && matrix.toxenv == 'py38' + uses: py-cov-action/python-coverage-comment-action@v3 with: - flags: unittests - fail_ci_if_error: true + GITHUB_TOKEN: ${{ github.token }} + MINIMUM_GREEN: 90 + MINIMUM_ORANGE: 85 + ANNOTATE_MISSING_LINES: true + ANNOTATION_TYPE: error From a87b886ea0d4ca683db7a0a48115132b5c9424b4 Mon Sep 17 00:00:00 2001 From: Maria Grimaldi Date: Thu, 28 Mar 2024 10:44:30 -0400 Subject: [PATCH 2/6] feat: add test for coverage --- openedx_events/tests/test_tooling.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/openedx_events/tests/test_tooling.py b/openedx_events/tests/test_tooling.py index da480d3d..74425251 100644 --- a/openedx_events/tests/test_tooling.py +++ b/openedx_events/tests/test_tooling.py @@ -379,3 +379,8 @@ def test_load_all_signals(self): OpenEdxPublicSignal.get_signal_by_type('org.openedx.learning.course.enrollment.created.v1'), OpenEdxPublicSignal ) + + +class SirNotAppearingInThisFilm(TestCase): + def never_run(self): + print("Hello") From d73dd3cfb3f4b33263de0ccb46901a66c11012b9 Mon Sep 17 00:00:00 2001 From: Maria Grimaldi Date: Thu, 28 Mar 2024 10:56:54 -0400 Subject: [PATCH 3/6] feat: make coverage run --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f1bc7d6e..194396b5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,7 +37,7 @@ jobs: run: tox - name: Report coverage - if: matrix.python-version == '3.8' && matrix.toxenv == 'py38' + if: matrix.python-version == '3.8' && matrix.toxenv == 'django32' uses: py-cov-action/python-coverage-comment-action@v3 with: GITHUB_TOKEN: ${{ github.token }} From aa0bc8ba6b5490d8dd6f75b61e090d0b7ff84a41 Mon Sep 17 00:00:00 2001 From: Maria Grimaldi Date: Thu, 28 Mar 2024 11:04:18 -0400 Subject: [PATCH 4/6] temp: give permissions to coverage step --- .github/workflows/ci.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 194396b5..908a4014 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,6 +17,17 @@ jobs: os: [ubuntu-20.04] python-version: ['3.8'] toxenv: ["quality", "docs", "django32", "django42"] + permissions: + # Gives the action the necessary permissions for publishing new + # comments in pull requests. + pull-requests: write + # Gives the action the necessary permissions for editing existing + # comments (to avoid publishing multiple comments in the same PR) + contents: write + # Gives the action the necessary permissions for looking up the + # workflow that launched this workflow, and download the related + # artifact that contains the comment to be published + actions: read steps: - uses: actions/checkout@v4 From 089bffd45af3cbe8a07a734063e16805adf8baeb Mon Sep 17 00:00:00 2001 From: Maria Grimaldi Date: Thu, 28 Mar 2024 11:12:30 -0400 Subject: [PATCH 5/6] refactor: add different workflow to post comment in PR --- .github/workflows/ci.yml | 17 +++++++++++----- .github/workflows/coverage.yml | 36 ++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/coverage.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 908a4014..ebe7ccde 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,13 +21,10 @@ jobs: # Gives the action the necessary permissions for publishing new # comments in pull requests. pull-requests: write - # Gives the action the necessary permissions for editing existing + # Gives the action the necessary permissions for pushing data to the + # python-coverage-comment-action branch, and for editing existing # comments (to avoid publishing multiple comments in the same PR) contents: write - # Gives the action the necessary permissions for looking up the - # workflow that launched this workflow, and download the related - # artifact that contains the comment to be published - actions: read steps: - uses: actions/checkout@v4 @@ -48,6 +45,7 @@ jobs: run: tox - name: Report coverage + id: coverage_comment if: matrix.python-version == '3.8' && matrix.toxenv == 'django32' uses: py-cov-action/python-coverage-comment-action@v3 with: @@ -56,3 +54,12 @@ jobs: MINIMUM_ORANGE: 85 ANNOTATE_MISSING_LINES: true ANNOTATION_TYPE: error + + - name: Store Pull Request comment to be posted + 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 diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml new file mode 100644 index 00000000..a36cf242 --- /dev/null +++ b/.github/workflows/coverage.yml @@ -0,0 +1,36 @@ +# .github/workflows/coverage.yml +name: Post coverage comment + +on: + workflow_run: + workflows: ["Python CI"] + types: + - completed + +jobs: + test: + name: Run tests & display coverage + runs-on: ubuntu-latest + if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' + permissions: + # Gives the action the necessary permissions for publishing new + # comments in pull requests. + pull-requests: write + # Gives the action the necessary permissions for editing existing + # comments (to avoid publishing multiple comments in the same PR) + contents: write + # Gives the action the necessary permissions for looking up the + # workflow that launched this workflow, and download the related + # artifact that contains the comment to be published + 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 }} + # Update those if you changed the default values: + # COMMENT_ARTIFACT_NAME: python-coverage-comment-action + # COMMENT_FILENAME: python-coverage-comment-action.txt From 37acb157b6208e74b2c82ba1a0724f4aec1f884a Mon Sep 17 00:00:00 2001 From: Maria Grimaldi Date: Thu, 28 Mar 2024 11:25:33 -0400 Subject: [PATCH 6/6] refactor: run on workflow success --- .github/workflows/coverage.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index a36cf242..793f0250 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -11,7 +11,7 @@ jobs: test: name: Run tests & display coverage runs-on: ubuntu-latest - if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' + if: ${{ github.event.workflow_run.conclusion == 'success' }} permissions: # Gives the action the necessary permissions for publishing new # comments in pull requests.