Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion coverage_comment/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion coverage_comment/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
)
Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading