1
0
mirror of synced 2026-01-05 12:07:35 -05:00
Files
docs/data/reusables/github-actions/actions-on-examples.md

75 lines
2.7 KiB
Markdown

### Using a single event
For example, a workflow with the following `on` value will run when a push is made to any branch in the workflow's repository:
```yaml
on: push
```
### Using multiple events
You can specify a single event or multiple events. For example, a workflow with the following `on` value will run when a push is made to any branch in the repository or when someone forks the repository:
```yaml
on: [push, fork]
```
If you specify multiple events, only one of those events needs to occur to trigger your workflow. If multiple triggering events for your workflow occur at the same time, multiple workflow runs will be triggered.
### Using activity types
Some events have activity types that give you more control over when your workflow should run.
For example, the `issue_comment` event has the `created`, `edited`, and `deleted` activity types. If your workflow triggers on the `label` event, it will run whenever a label is created, edited, or deleted. If you specify the `created` activity type for the `label` event, your workflow will run when a label is created but not when a label is edited or deleted.
```yaml
on:
label:
types:
- created
```
If you specify multiple activity types, only one of those event activity types needs to occur to trigger your workflow. If multiple triggering event activity types for your workflow occur at the same time, multiple workflow runs will be triggered. For example, the following workflow triggers when an issue is opened or labeled. If an issue with two labels is opened, three workflow runs will start: one for the issue opened event and two for the two issue labeled events.
```yaml
on:
issue:
types:
- opened
- labeled
```
### Using filters
Some events have filters that give you more control over when your workflow should run.
For example, the `push` event has a `branches` filter that causes your workflow to run only when a push to a branch that matches the `branches` filter occurs, instead of when any push occurs.
```yaml
on:
push:
branches:
- main
- 'releases/**'
```
### Using activity types and filters with multiple events
If you specify activity types or filters for an event and your workflow triggers on multiple events, you must configure each event separately. You must append a colon (`:`) to all events, including events without configuration.
For example, a workflow with the following `on` value will run when:
- A label is created
- A push is made to the `main` branch in the repository
- A push is made to a {% data variables.product.prodname_pages %}-enabled branch
```yaml
on:
label:
types:
- created
push:
branches:
- main
page_build:
```