From 2c7368f0321193fc1a9e4d611c438ff930c8f1cc Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Tue, 9 Jan 2024 16:53:10 -0500 Subject: [PATCH 1/8] 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 19c388d8cdafb737688cfdda0c39432ecac04228 Mon Sep 17 00:00:00 2001 From: Maria Grimaldi Date: Thu, 28 Mar 2024 10:44:30 -0400 Subject: [PATCH 2/8] feat: add test for coverage --- openedx_events/tests/test_tooling.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/openedx_events/tests/test_tooling.py b/openedx_events/tests/test_tooling.py index da480d3d..77aac7c3 100644 --- a/openedx_events/tests/test_tooling.py +++ b/openedx_events/tests/test_tooling.py @@ -379,3 +379,9 @@ 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") \ No newline at end of file From 1137c3c1c485103d2f0aa9e9036d6063fc6f5563 Mon Sep 17 00:00:00 2001 From: Maria Grimaldi Date: Thu, 28 Mar 2024 10:44:30 -0400 Subject: [PATCH 3/8] feat: add test for coverage --- openedx_events/tests/test_tooling.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/openedx_events/tests/test_tooling.py b/openedx_events/tests/test_tooling.py index 77aac7c3..74425251 100644 --- a/openedx_events/tests/test_tooling.py +++ b/openedx_events/tests/test_tooling.py @@ -381,7 +381,6 @@ def test_load_all_signals(self): ) - class SirNotAppearingInThisFilm(TestCase): def never_run(self): - print("Hello") \ No newline at end of file + print("Hello") From 61f971616ffd2ae5a74c5c927cd8b68c6b3b775b Mon Sep 17 00:00:00 2001 From: Maria Grimaldi Date: Thu, 28 Mar 2024 10:56:54 -0400 Subject: [PATCH 4/8] 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 6a06c5d91ba1476e0bf3190f782c66480f9ceb55 Mon Sep 17 00:00:00 2001 From: Maria Grimaldi Date: Thu, 28 Mar 2024 11:04:18 -0400 Subject: [PATCH 5/8] 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 a6980450d5f80f52fd2b751afb524c61c5e404c5 Mon Sep 17 00:00:00 2001 From: Maria Grimaldi Date: Thu, 28 Mar 2024 11:12:30 -0400 Subject: [PATCH 6/8] 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 a7cf30dfe070cfd7413baf67e6a101aa07682f2f Mon Sep 17 00:00:00 2001 From: Maria Grimaldi Date: Thu, 28 Mar 2024 11:57:57 -0400 Subject: [PATCH 7/8] fix: go back to run in django42 --- .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 ebe7ccde..dbabd36d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -46,7 +46,7 @@ jobs: - name: Report coverage id: coverage_comment - if: matrix.python-version == '3.8' && matrix.toxenv == 'django32' + if: matrix.python-version == '3.8' && matrix.toxenv == 'django42' uses: py-cov-action/python-coverage-comment-action@v3 with: GITHUB_TOKEN: ${{ github.token }} From 75b3d874ebd76095d646ec35282602c2da8bbf22 Mon Sep 17 00:00:00 2001 From: Maria Grimaldi Date: Mon, 1 Apr 2024 09:13:09 -0400 Subject: [PATCH 8/8] refactor: remove fake test for coverage --- openedx_events/tests/test_tooling.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/openedx_events/tests/test_tooling.py b/openedx_events/tests/test_tooling.py index 74425251..da480d3d 100644 --- a/openedx_events/tests/test_tooling.py +++ b/openedx_events/tests/test_tooling.py @@ -379,8 +379,3 @@ 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")