Skip to content

Commit ef69f90

Browse files
docs: document merge_group branch filters
1 parent 7cbca58 commit ef69f90

File tree

2 files changed

+67
-2
lines changed

2 files changed

+67
-2
lines changed

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
@@ -366,14 +366,17 @@ on:
366366

367367
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/collaborating-with-pull-requests/incorporating-changes-from-a-pull-request/merging-a-pull-request-with-a-merge-queue).
368368

369-
For example, you can run a workflow when the `checks_requested` activity has occurred.
369+
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).
370+
371+
For example, the following workflow runs when the `checks_requested` activity occurs for a merge group that targets `main`.
370372

371373
```yaml
372374
on:
373375
pull_request:
374-
branches: [ "main" ]
376+
branches: [main]
375377
merge_group:
376378
types: [checks_requested]
379+
branches: [main]
377380
```
378381

379382
## `milestone`

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

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

7373
{% data reusables.actions.workflows.triggering-workflow-branches4 %}
7474

75+
## `on.merge_group.<branches|branches-ignore>`
76+
77+
When using the `merge_group` event, you can configure a workflow to run only for merge groups that target specific branches.
78+
79+
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.
80+
81+
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).
82+
83+
### Example: Including branches
84+
85+
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:
86+
87+
* A branch named `main`
88+
* A branch whose name starts with `releases/`
89+
90+
```yaml
91+
on:
92+
merge_group:
93+
types: [checks_requested]
94+
branches:
95+
- main
96+
- 'releases/**'
97+
```
98+
99+
### Example: Excluding branches
100+
101+
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:
102+
103+
* A branch named `canary`
104+
* A branch whose name matches `releases/**-alpha`, like `releases/beta/3-alpha` <!-- markdownlint-disable-line outdated-release-phase-terminology -->
105+
106+
```yaml
107+
on:
108+
merge_group:
109+
types: [checks_requested]
110+
branches-ignore:
111+
- canary
112+
- 'releases/**-alpha'
113+
```
114+
115+
### Example: Including and excluding branches
116+
117+
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.
118+
119+
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.
120+
121+
The order that you define patterns matters.
122+
123+
* A matching negative pattern (prefixed with `!`) after a positive match will exclude the branch.
124+
* A matching positive pattern after a negative match will include the branch again.
125+
126+
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 -->
127+
128+
```yaml
129+
on:
130+
merge_group:
131+
types: [checks_requested]
132+
branches:
133+
- 'releases/**'
134+
- '!releases/**-alpha'
135+
```
136+
75137
## `on.push.<branches|tags|branches-ignore|tags-ignore>`
76138

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

0 commit comments

Comments
 (0)