Skip to content

Commit

Permalink
Merge pull request #448 from muzimuzhi/merge_group-filters
Browse files Browse the repository at this point in the history
`branchs` and `branches-ignore` filters are available for `merge_group` event
  • Loading branch information
rhysd authored Sep 17, 2024
2 parents ea4d85d + b14cf83 commit 1f5010b
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 25 deletions.
16 changes: 8 additions & 8 deletions docs/checks.md
Original file line number Diff line number Diff line change
Expand Up @@ -1276,14 +1276,14 @@ actionlint validates the Webhook configurations:
- Some filters are only available for specific events as explained in [the official document][specific-paths-doc]
(see the following table).

| Filter name | Events where the filter is available |
|-------------------|-----------------------------------------------|
| `paths` | `push`, `pull_request`, `pull_request_target` |
| `paths-ignore` | `push`, `pull_request`, `pull_request_target` |
| `branches` | `push`, `pull_request`, `pull_request_target` |
| `branches-ignore` | `push`, `pull_request`, `pull_request_target` |
| `tags` | `push` |
| `tags-ignore` | `push` |
| Filter name | Events where the filter is available |
|-------------------|------------------------------------------------------------------------------|
| `paths` | `push`, `pull_request`, `pull_request_target` |
| `paths-ignore` | `push`, `pull_request`, `pull_request_target` |
| `branches` | `merge_group`, `push`, `pull_request`, `pull_request_target`, `workflow_run` |
| `branches-ignore` | `merge_group`, `push`, `pull_request`, `pull_request_target`, `workflow_run` |
| `tags` | `push` |
| `tags-ignore` | `push` |

The table of available Webhooks and their types are defined in [`all_webhooks.go`](../all_webhooks.go). It is generated
by [a script][generate-webhook-events] and kept to the latest by CI workflow triggered weekly.
Expand Down
3 changes: 2 additions & 1 deletion rule_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ func (rule *RuleEvents) checkWebhookEvent(event *WebhookEvent) {
}

// Some filters are available with specific events and exclusive
// - on.merge_group.<branches|branches-ignore>
// - on.<push|pull_request|pull_request_target>.<paths|paths-ignore>
// - on.push.<branches|tags|branches-ignore|tags-ignore>
// - on.<pull_request|pull_request_target>.<branches|branches-ignore>
Expand All @@ -146,7 +147,7 @@ func (rule *RuleEvents) checkWebhookEvent(event *WebhookEvent) {
event.Branches,
event.BranchesIgnore,
hook,
[]string{"push", "pull_request", "pull_request_target", "workflow_run"},
[]string{"merge_group", "push", "pull_request", "pull_request_target", "workflow_run"},
)
rule.checkExclusiveFilters(
event.Tags,
Expand Down
17 changes: 9 additions & 8 deletions testdata/err/exclusive_webhook_filters.out
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
test.yaml:4:5: both "paths" and "paths-ignore" filters cannot be used for the same event "push". note: use '!' to negate patterns [events]
test.yaml:6:5: both "branches" and "branches-ignore" filters cannot be used for the same event "push". note: use '!' to negate patterns [events]
test.yaml:8:5: both "tags" and "tags-ignore" filters cannot be used for the same event "push". note: use '!' to negate patterns [events]
test.yaml:11:5: both "paths" and "paths-ignore" filters cannot be used for the same event "pull_request". note: use '!' to negate patterns [events]
test.yaml:13:5: both "branches" and "branches-ignore" filters cannot be used for the same event "pull_request". note: use '!' to negate patterns [events]
test.yaml:16:5: both "paths" and "paths-ignore" filters cannot be used for the same event "pull_request_target". note: use '!' to negate patterns [events]
test.yaml:18:5: both "branches" and "branches-ignore" filters cannot be used for the same event "pull_request_target". note: use '!' to negate patterns [events]
test.yaml:22:5: both "branches" and "branches-ignore" filters cannot be used for the same event "workflow_run". note: use '!' to negate patterns [events]
test.yaml:4:5: both "branches" and "branches-ignore" filters cannot be used for the same event "merge_group". note: use '!' to negate patterns [events]
test.yaml:7:5: both "paths" and "paths-ignore" filters cannot be used for the same event "push". note: use '!' to negate patterns [events]
test.yaml:9:5: both "branches" and "branches-ignore" filters cannot be used for the same event "push". note: use '!' to negate patterns [events]
test.yaml:11:5: both "tags" and "tags-ignore" filters cannot be used for the same event "push". note: use '!' to negate patterns [events]
test.yaml:14:5: both "paths" and "paths-ignore" filters cannot be used for the same event "pull_request". note: use '!' to negate patterns [events]
test.yaml:16:5: both "branches" and "branches-ignore" filters cannot be used for the same event "pull_request". note: use '!' to negate patterns [events]
test.yaml:19:5: both "paths" and "paths-ignore" filters cannot be used for the same event "pull_request_target". note: use '!' to negate patterns [events]
test.yaml:21:5: both "branches" and "branches-ignore" filters cannot be used for the same event "pull_request_target". note: use '!' to negate patterns [events]
test.yaml:25:5: both "branches" and "branches-ignore" filters cannot be used for the same event "workflow_run". note: use '!' to negate patterns [events]
3 changes: 3 additions & 0 deletions testdata/err/exclusive_webhook_filters.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
on:
merge_group:
branches-ignore: bar
branches: foo
push:
paths: path/to/foo
paths-ignore: path/to/bar
Expand Down
21 changes: 13 additions & 8 deletions testdata/err/invalid_event_filters.out
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
test.yaml:4:5: "paths" filter is not available for pull_request_review event. it is only for push, pull_request, pull_request_target events [events]
test.yaml:5:5: "paths-ignore" filter is not available for pull_request_review event. it is only for push, pull_request, pull_request_target events [events]
test.yaml:6:5: "branches" filter is not available for pull_request_review event. it is only for push, pull_request, pull_request_target, workflow_run events [events]
test.yaml:7:5: "branches-ignore" filter is not available for pull_request_review event. it is only for push, pull_request, pull_request_target, workflow_run events [events]
test.yaml:8:5: "tags" filter is not available for pull_request_review event. it is only for push event [events]
test.yaml:9:5: "tags-ignore" filter is not available for pull_request_review event. it is only for push event [events]
test.yaml:11:5: "tags" filter is not available for pull_request event. it is only for push event [events]
test.yaml:12:5: "tags-ignore" filter is not available for pull_request event. it is only for push event [events]
test.yaml:3:12: invalid activity type "opened" for "merge_group" Webhook event. available types are "checks_requested" [events]
test.yaml:4:5: "paths" filter is not available for merge_group event. it is only for push, pull_request, pull_request_target events [events]
test.yaml:5:5: "paths-ignore" filter is not available for merge_group event. it is only for push, pull_request, pull_request_target events [events]
test.yaml:6:5: "tags" filter is not available for merge_group event. it is only for push event [events]
test.yaml:7:5: "tags-ignore" filter is not available for merge_group event. it is only for push event [events]
test.yaml:10:5: "paths" filter is not available for pull_request_review event. it is only for push, pull_request, pull_request_target events [events]
test.yaml:11:5: "paths-ignore" filter is not available for pull_request_review event. it is only for push, pull_request, pull_request_target events [events]
test.yaml:12:5: "branches" filter is not available for pull_request_review event. it is only for merge_group, push, pull_request, pull_request_target, workflow_run events [events]
test.yaml:13:5: "branches-ignore" filter is not available for pull_request_review event. it is only for merge_group, push, pull_request, pull_request_target, workflow_run events [events]
test.yaml:14:5: "tags" filter is not available for pull_request_review event. it is only for push event [events]
test.yaml:15:5: "tags-ignore" filter is not available for pull_request_review event. it is only for push event [events]
test.yaml:17:5: "tags" filter is not available for pull_request event. it is only for push event [events]
test.yaml:18:5: "tags-ignore" filter is not available for pull_request event. it is only for push event [events]
6 changes: 6 additions & 0 deletions testdata/err/invalid_event_filters.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
on:
merge_group:
types: opened
paths: /path/to/foo.txt
paths-ignore: /path/to/bar.txt
tags: v*.*.*
tags-ignore: deploy/*
pull_request_review:
types: submitted
paths: /path/to/foo.txt
Expand Down
2 changes: 2 additions & 0 deletions testdata/ok/filters_for_specific_events.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
on:
merge_group:
branches: main
push:
branches: main
tags: v*.*.*
Expand Down
2 changes: 2 additions & 0 deletions testdata/ok/filters_ignore_for_specific_events.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
on:
merge_group:
branches-ignore: bar
push:
branches-ignore: test
tags-ignore: deploy/*
Expand Down

0 comments on commit 1f5010b

Please sign in to comment.