Skip to content

Commit 0544a9c

Browse files
authored
Merge pull request #592 from olivier-lacroix/feat/merge-queue
2 parents 59e8544 + 93c307d commit 0544a9c

File tree

4 files changed

+44
-2
lines changed

4 files changed

+44
-2
lines changed

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,46 @@ jobs:
215215
GITHUB_TOKEN: ${{ github.token }}
216216
```
217217
218+
### Using with merge queues
219+
220+
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.
221+
222+
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.
223+
224+
For instance
225+
226+
```yaml
227+
# .github/workflows/ci.yml
228+
name: CI
229+
230+
on:
231+
pull_request:
232+
merge_group:
233+
234+
jobs:
235+
test:
236+
name: Run tests & display coverage
237+
runs-on: ubuntu-latest
238+
permissions:
239+
# Gives the action the necessary permissions for publishing new
240+
# comments in pull requests.
241+
pull-requests: write
242+
# Gives the action the necessary permissions for pushing data to the
243+
# python-coverage-comment-action branch, and for editing existing
244+
# comments (to avoid publishing multiple comments in the same PR)
245+
contents: write
246+
steps:
247+
- uses: actions/checkout@v4
248+
249+
- name: Install everything, run the tests, produce the .coverage file
250+
run: make test # This is the part where you put your own test command
251+
252+
- name: Coverage comment
253+
uses: py-cov-action/python-coverage-comment-action@v3
254+
with:
255+
GITHUB_TOKEN: ${{ github.token }}
256+
```
257+
218258
### Merging multiple coverage reports
219259

220260
In case you have a job matrix and you want the report to be on the global

coverage_comment/activity.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,13 @@ def find_activity(
2727
(event_name == "push" and is_default_branch)
2828
or event_name == "schedule"
2929
or (event_name == "pull_request" and event_type == "closed")
30+
or event_name == "merge_group"
3031
):
3132
if event_name == "pull_request" and event_type == "closed" and not is_pr_merged:
3233
raise ActivityNotFound
3334
return "save_coverage_data_files"
3435

35-
if event_name not in {"pull_request", "push"}:
36+
if event_name not in {"pull_request", "push", "merge_group"}:
3637
raise ActivityNotFound
3738

3839
return "process_pr"

coverage_comment/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def action(
8383
except activity_module.ActivityNotFound:
8484
log.error(
8585
'This action has only been designed to work for "pull_request", "push", '
86-
f'"workflow_run" or "schedule" actions, not "{event_name}". Because there '
86+
f'"workflow_run", "schedule" or "merge_group" actions, not "{event_name}". Because there '
8787
"are security implications. If you have a different usecase, please open an issue, "
8888
"we'll be glad to add compatibility."
8989
)

tests/unit/test_activity.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
("pull_request", True, None, False, "process_pr"),
1616
("pull_request", False, None, False, "process_pr"),
1717
("schedule", False, None, False, "save_coverage_data_files"),
18+
("merge_group", False, None, False, "save_coverage_data_files"),
1819
],
1920
)
2021
def test_find_activity(

0 commit comments

Comments
 (0)