Skip to content

Commit 43b8eeb

Browse files
authored
Merge pull request #14664 from github/repo-sync
repo sync
2 parents df125a0 + 6b1f2b5 commit 43b8eeb

11 files changed

+317
-296
lines changed

content/actions/using-workflows/events-that-trigger-workflows.md

Lines changed: 2 additions & 186 deletions
Original file line numberDiff line numberDiff line change
@@ -16,193 +16,9 @@ versions:
1616
shortTitle: Events that trigger workflows
1717
---
1818

19-
{% data reusables.actions.enterprise-beta %}
20-
{% data reusables.actions.enterprise-github-hosted-runners %}
19+
## About events that trigger workflows
2120

22-
## About workflow triggers
23-
24-
Workflow triggers are events that cause a workflow to run. These events can be:
25-
26-
- Events that occur in your workflow's repository
27-
- Events that occur outside of {% data variables.product.product_name %} and trigger a `repository_dispatch` event on {% data variables.product.product_name %}
28-
- Scheduled times
29-
- Manual
30-
31-
For example, you can configure your workflow to run when a push is made to the default branch of your repository, when a release is created, or when an issue is opened.
32-
33-
Workflow triggers are defined with the `on` key. For more information, see "[Workflow syntax for {% data variables.product.prodname_actions %}](/articles/workflow-syntax-for-github-actions#on)."
34-
35-
The following steps occur to trigger a workflow run:
36-
37-
1. An event occurs on your repository. The event has an associated commit SHA and Git ref.
38-
1. {% data variables.product.product_name %} searches the `.github/workflows` directory in your repository for workflow files that are present in the associated commit SHA or Git ref of the event.
39-
40-
1. A workflow run is triggered for any workflows that have `on:` values that match the triggering event. Some events also require the workflow file to be present on the default branch of the repository in order to run.
41-
42-
Each workflow run will use the version of the workflow that is present in the associated commit SHA or Git ref of the event. When a workflow runs, {% data variables.product.product_name %} sets the `GITHUB_SHA` (commit SHA) and `GITHUB_REF` (Git ref) environment variables in the runner environment. For more information, see "[Using environment variables](/actions/automating-your-workflow-with-github-actions/using-environment-variables)."
43-
44-
### Triggering a workflow from a workflow
45-
46-
{% data reusables.github-actions.actions-do-not-trigger-workflows %} For more information, see "[Authenticating with the GITHUB_TOKEN](/actions/configuring-and-managing-workflows/authenticating-with-the-github_token)."
47-
48-
If you do want to trigger a workflow from within a workflow run, you can use a personal access token instead of `GITHUB_TOKEN` to trigger events that require a token. You'll need to create a personal access token and store it as a secret. To minimize your {% data variables.product.prodname_actions %} usage costs, ensure that you don't create recursive or unintended workflow runs. For more information about creating a personal access token, see "[Creating a personal access token](/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token)." For more information about storing a personal access token as a secret, see "[Creating and storing encrypted secrets](/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets)."
49-
50-
For example, the following workflow uses a personal access token (stored as a secret called `MY_TOKEN`) to add a label to an issue via {% data variables.product.prodname_cli %}. Any workflows that run when a label is added will run once this step is performed.
51-
52-
```yaml
53-
on:
54-
issues:
55-
types:
56-
- opened
57-
58-
jobs:
59-
label_issue:
60-
runs-on: ubuntu-latest
61-
steps:
62-
- env:
63-
GITHUB_TOKEN: {% raw %}${{ secrets.MY_TOKEN }}{% endraw %}
64-
ISSUE_URL: {% raw %}${{ github.event.issue.html_url }}{% endraw %}
65-
run: |
66-
gh issue edit $ISSUE_URL --add-label "triage"
67-
```
68-
69-
Conversely, the following workflow uses `GITHUB_TOKEN` to add a label to an issue. It will not trigger any workflows that run when a label is added.
70-
71-
```yaml
72-
on:
73-
issues:
74-
types:
75-
- opened
76-
77-
jobs:
78-
label_issue:
79-
runs-on: ubuntu-latest
80-
steps:
81-
- env:
82-
GITHUB_TOKEN: {% raw %}${{ secrets.GITHUB_TOKEN }}{% endraw %}
83-
ISSUE_URL: {% raw %}${{ github.event.issue.html_url }}{% endraw %}
84-
run: |
85-
gh issue edit $ISSUE_URL --add-label "triage"
86-
```
87-
88-
## Using events to trigger workflows
89-
90-
Use the `on` key to specify what events trigger your workflow. For more information about events you can use, see "[Available events](#available-events)" below.
91-
92-
{% data reusables.github-actions.actions-on-examples %}
93-
94-
## Using event information
95-
96-
Information about the event that triggered a workflow run is available in the `github.event` context. The properties in the `github.event` context depend on the type of event that triggered the workflow. For example, a workflow triggered when an issue is labeled would have information about the issue and label.
97-
98-
### Viewing all properties of an event
99-
100-
Reference the webhook event documentation for common properties and example payloads. For more information, see "[Webhook events and payloads](/developers/webhooks-and-events/webhooks/webhook-events-and-payloads)."
101-
102-
You can also print the entire `github.event` context to see what properties are available for the event that triggered your workflow:
103-
104-
```yaml
105-
jobs:
106-
print_context:
107-
runs-on: ubuntu-latest
108-
steps:
109-
- env:
110-
EVENT_CONTEXT: {% raw %}${{ toJSON(github.event) }}{% endraw %}
111-
run: |
112-
echo $EVENT_CONTEXT
113-
```
114-
115-
### Accessing and using event properties
116-
117-
You can use the `github.event` context in your workflow. For example, the following workflow runs when a pull request that changes `package*.json`, `.github/CODEOWNERS`, or `.github/workflows/**` is opened. If the pull request author (`github.event.pull_request.user.login`) is not `octobot` or `dependabot[bot]`, then the workflow uses the {% data variables.product.prodname_cli %} to label and comment on the pull request (`github.event.pull_request.number`).
118-
119-
```yaml
120-
on:
121-
pull_request:
122-
types:
123-
- opened
124-
paths:
125-
- '.github/workflows/**'
126-
- '.github/CODEOWNERS'
127-
- 'package*.json'
128-
129-
jobs:
130-
triage:
131-
if: >-
132-
github.event.pull_request.user.login != 'octobot' &&
133-
github.event.pull_request.user.login != 'dependabot[bot]'
134-
runs-on: ubuntu-latest
135-
steps:
136-
- name: "Comment about changes we can't accept"
137-
env:
138-
GITHUB_TOKEN: {% raw %}${{ secrets.GITHUB_TOKEN }}{% endraw %}
139-
PR: {% raw %}${{ github.event.pull_request.html_url }}{% endraw %}
140-
run: |
141-
gh pr edit $PR --add-label 'invalid'
142-
gh pr comment $PR --body 'It looks like you edited `package*.json`, `.github/CODEOWNERS`, or `.github/workflows/**`. We do not allow contributions to these files. Please review our [contributing guidelines](https://github.com/octo-org/octo-repo/blob/main/CONTRIBUTING.md) for what contributions are accepted.'
143-
```
144-
145-
For more information about contexts, see "[Contexts](/actions/learn-github-actions/contexts)." For more information about event payloads, see "[Webhook events and payloads](/developers/webhooks-and-events/webhooks/webhook-events-and-payloads)."
146-
147-
## Further controlling how your workflow will run
148-
149-
If you want more granular control than events, event activity types, or event filters provide, you can use conditionals{% ifversion fpt or ghae or ghes > 3.1 or ghec %} and environments{% endif %} to control whether individual jobs or steps in your workflow will run.
150-
151-
### Using conditionals
152-
153-
You can use conditionals to further control whether jobs or steps in your workflow will run. For example, if you want the workflow to run when a specific label is added to an issue, you can trigger on the `issues labeled` event activity type and use a conditional to check what label triggered the workflow. The following workflow will run when any label is added to an issue in the workflow's repository, but the `run_if_label_matches` job will only execute if the label is named `bug`.
154-
155-
```yaml
156-
on:
157-
issues:
158-
types:
159-
- labeled
160-
161-
jobs:
162-
run_if_label_matches:
163-
if: github.event.label.name == 'bug'
164-
runs-on: ubuntu-latest
165-
steps:
166-
- run: echo 'The label was bug'
167-
```
168-
169-
For more information, see "[Expressions](/actions/learn-github-actions/expressions)."
170-
171-
{% ifversion fpt or ghae or ghes > 3.1 or ghec %}
172-
### Using environments to manually trigger workflow jobs
173-
174-
If you want to manually trigger a specific job in a workflow, you can use an environment that requires approval from a specific team or user. First, configure an environment with required reviewers. For more information, see "[Using environments for deployment](/actions/deployment/targeting-different-environments/using-environments-for-deployment)." Then, reference the environment name in a job in your workflow using the `environment:` key. Any job referencing the environment will not run until at least one reviewer approves the job.
175-
176-
For example, the following workflow will run whenever there is a push to main. The `build` job will always run. The `publish` job will only run after the `build` job successfully completes (due to `needs: [build]`) and after all of the rules (including required reviewers) for the environment called `production` pass (due to `environment: production`).
177-
178-
```yaml
179-
on:
180-
push:
181-
branches:
182-
- main
183-
184-
jobs:
185-
build:
186-
runs-on: ubuntu-latest
187-
steps:
188-
- name: build
189-
echo 'building'
190-
191-
publish:
192-
needs: [build]
193-
runs-on: ubuntu-latest
194-
environment: production
195-
steps:
196-
- name: publish
197-
echo 'publishing'
198-
```
199-
200-
{% note %}
201-
202-
{% data reusables.gated-features.environments %}
203-
204-
{% endnote %}
205-
{% endif %}
21+
Workflow triggers are events that cause a workflow to run. For more information about how to use workflow triggers, see "[Triggering a workflow](/actions/using-workflows/triggering-a-workflow)."
20622

20723
## Available events
20824

0 commit comments

Comments
 (0)