Skip to content

Commit 63859c4

Browse files
docs: document branch filters for merge_group workflows (#43500)
Co-authored-by: hiromieguchi802-lab <270042125+hiromieguchi802-lab@users.noreply.github.com> Co-authored-by: Ben Ahmady <32935794+subatoi@users.noreply.github.com>
1 parent 95cd2ed commit 63859c4

2 files changed

Lines changed: 67 additions & 2 deletions

File tree

‎content/actions/reference/workflows-and-actions/events-that-trigger-workflows.md‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,14 +384,17 @@ on:
384384

385385
Runs your workflow when a pull request is added to a merge queue, which adds the pull request to a merge group. For more information see [AUTOTITLE](/pull-requests/how-tos/merge-and-close-pull-requests/merging-a-pull-request-with-a-merge-queue).
386386

387-
For example, you can run a workflow when the `checks_requested` activity has occurred.
387+
You can use the `branches` or `branches-ignore` filter to configure your workflow to run only for merge groups that target specific branches. For more information, see [AUTOTITLE](/actions/using-workflows/workflow-syntax-for-github-actions#onmerge_groupbranchesbranches-ignore).
388+
389+
For example, the following workflow runs when the `checks_requested` activity occurs for a merge group that targets `main`.
388390

389391
```yaml
390392
on:
391393
pull_request:
392-
branches: [ "main" ]
394+
branches: [main]
393395
merge_group:
394396
types: [checks_requested]
397+
branches: [main]
395398
```
396399

397400
## `milestone`

‎content/actions/reference/workflows-and-actions/workflow-syntax.md‎

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,68 @@ run-name: Deploy to ${{ inputs.deploy_target }} by @${{ github.actor }}
7878

7979
{% data reusables.actions.workflows.triggering-workflow-branches4 %}
8080

81+
## `on.merge_group.<branches|branches-ignore>`
82+
83+
When using the `merge_group` event, you can configure a workflow to run only for merge groups that target specific branches.
84+
85+
Use the `branches` filter when you want to include branch name patterns or when you want to both include and exclude branch name patterns. Use `branches-ignore` when you only want to exclude branch name patterns. You cannot use both `branches` and `branches-ignore` for the same event in a workflow.
86+
87+
The `branches` and `branches-ignore` filters accept glob patterns that use characters like `*`, `**`, `+`, `?`, `!` and others to match more than one branch name. If a name contains any of these characters and you want a literal match, you need to escape each of these special characters with `\`. For more information about glob patterns, see [AUTOTITLE](/actions/using-workflows/workflow-syntax-for-github-actions#filter-pattern-cheat-sheet).
88+
89+
### Example: Including branches
90+
91+
The patterns defined in `branches` are evaluated against the target branch's name. For example, the following workflow will run whenever there is a `merge_group` event for a merge group that targets:
92+
93+
* A branch named `main`
94+
* A branch whose name starts with `releases/`
95+
96+
```yaml
97+
on:
98+
merge_group:
99+
types: [checks_requested]
100+
branches:
101+
- main
102+
- 'releases/**'
103+
```
104+
105+
### Example: Excluding branches
106+
107+
When a pattern matches the `branches-ignore` pattern, the workflow will not run. The patterns defined in `branches-ignore` are evaluated against the target branch's name. For example, the following workflow will run whenever there is a `merge_group` event unless the merge group targets:
108+
109+
* A branch named `canary`
110+
* A branch whose name matches `releases/**-alpha`, like `releases/beta/3-alpha` <!-- markdownlint-disable-line outdated-release-phase-terminology -->
111+
112+
```yaml
113+
on:
114+
merge_group:
115+
types: [checks_requested]
116+
branches-ignore:
117+
- canary
118+
- 'releases/**-alpha'
119+
```
120+
121+
### Example: Including and excluding branches
122+
123+
You cannot use `branches` and `branches-ignore` to filter the same event in a single workflow. If you want to both include and exclude branch patterns for a single event, use the `branches` filter along with the `!` character to indicate which branches should be excluded.
124+
125+
If you define a branch with the `!` character, you must also define at least one branch without the `!` character. If you only want to exclude branches, use `branches-ignore` instead.
126+
127+
The order that you define patterns matters.
128+
129+
* A matching negative pattern (prefixed with `!`) after a positive match will exclude the branch.
130+
* A matching positive pattern after a negative match will include the branch again.
131+
132+
The following workflow will run on `merge_group` events for merge groups that target `releases/10` or `releases/beta/mona`, but not for merge groups that target `releases/10-alpha` or `releases/beta/3-alpha` because the negative pattern `!releases/**-alpha` follows the positive pattern. <!-- markdownlint-disable-line outdated-release-phase-terminology -->
133+
134+
```yaml
135+
on:
136+
merge_group:
137+
types: [checks_requested]
138+
branches:
139+
- 'releases/**'
140+
- '!releases/**-alpha'
141+
```
142+
81143
## `on.push.<branches|tags|branches-ignore|tags-ignore>`
82144

83145
{% data reusables.actions.workflows.run-on-specific-branches-or-tags1 %}

0 commit comments

Comments
 (0)