From 59e8544279a1d3cc1ff780d376c4ffe83d161a17 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 21 Aug 2025 21:52:26 +0000 Subject: [PATCH 1/2] chore(deps): update pre-commit hook astral-sh/ruff-pre-commit to v0.12.10 (#591) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 536db05d..f134b694 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -18,7 +18,7 @@ repos: - id: check-added-large-files - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.12.9 + rev: v0.12.10 hooks: - id: ruff args: [--fix] From 93c307d8425ffd2cc67c0e138eff7eebf827b6fd Mon Sep 17 00:00:00 2001 From: Olivier Lacroix Date: Sun, 24 Aug 2025 15:01:21 +1000 Subject: [PATCH 2/2] Handle Merge Queues --- README.md | 40 ++++++++++++++++++++++++++++++++++++ coverage_comment/activity.py | 3 ++- coverage_comment/main.py | 2 +- tests/unit/test_activity.py | 1 + 4 files changed, 44 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d9df4e60..f7d1e9d0 100644 --- a/README.md +++ b/README.md @@ -215,6 +215,46 @@ jobs: GITHUB_TOKEN: ${{ github.token }} ``` +### Using with merge queues + +If you are using merge queues, you will need to add the `merge_group` event to your workflow's `on:` clause. This will ensure that the action is triggered when a pull request is added to the merge queue. + +You will need to ensure the action is run only _after_ all the actual merge checks have run. Otherwise, coverage data will be incorrectly updated. + +For instance + +```yaml +# .github/workflows/ci.yml +name: CI + +on: + pull_request: + merge_group: + +jobs: + test: + name: Run tests & display coverage + runs-on: ubuntu-latest + permissions: + # Gives the action the necessary permissions for publishing new + # comments in pull requests. + pull-requests: write + # 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 + steps: + - uses: actions/checkout@v4 + + - name: Install everything, run the tests, produce the .coverage file + run: make test # This is the part where you put your own test command + + - name: Coverage comment + uses: py-cov-action/python-coverage-comment-action@v3 + with: + GITHUB_TOKEN: ${{ github.token }} +``` + ### Merging multiple coverage reports In case you have a job matrix and you want the report to be on the global diff --git a/coverage_comment/activity.py b/coverage_comment/activity.py index a134cefe..3fdb5101 100644 --- a/coverage_comment/activity.py +++ b/coverage_comment/activity.py @@ -27,12 +27,13 @@ def find_activity( (event_name == "push" and is_default_branch) or event_name == "schedule" or (event_name == "pull_request" and event_type == "closed") + or event_name == "merge_group" ): if event_name == "pull_request" and event_type == "closed" and not is_pr_merged: raise ActivityNotFound return "save_coverage_data_files" - if event_name not in {"pull_request", "push"}: + if event_name not in {"pull_request", "push", "merge_group"}: raise ActivityNotFound return "process_pr" diff --git a/coverage_comment/main.py b/coverage_comment/main.py index 4d5ce97a..9c4ecd64 100644 --- a/coverage_comment/main.py +++ b/coverage_comment/main.py @@ -83,7 +83,7 @@ def action( except activity_module.ActivityNotFound: log.error( 'This action has only been designed to work for "pull_request", "push", ' - f'"workflow_run" or "schedule" actions, not "{event_name}". Because there ' + f'"workflow_run", "schedule" or "merge_group" actions, not "{event_name}". Because there ' "are security implications. If you have a different usecase, please open an issue, " "we'll be glad to add compatibility." ) diff --git a/tests/unit/test_activity.py b/tests/unit/test_activity.py index e1390f0b..b67627b4 100644 --- a/tests/unit/test_activity.py +++ b/tests/unit/test_activity.py @@ -15,6 +15,7 @@ ("pull_request", True, None, False, "process_pr"), ("pull_request", False, None, False, "process_pr"), ("schedule", False, None, False, "save_coverage_data_files"), + ("merge_group", False, None, False, "save_coverage_data_files"), ], ) def test_find_activity(