You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: learn-pr/github/github-actions-automate-tasks/includes/2c-configure-github-actions-workflow.md
+45-25Lines changed: 45 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,12 @@
1
-
Here, you'll learn some common configurations within a workflow file. You'll also explore the categories of event types, disabling and deleting workflows, and using specific versions of an action for security best practices.
1
+
Here, you learn some common configurations within a workflow file. You also explore the categories of event types, disabling and deleting workflows, and using specific versions of an action for security best practices.
2
2
3
3
## Configure workflows to run for scheduled events
4
4
5
5
As mentioned previously, you can configure your workflows to run when specific activity occurs on GitHub, when an event outside of GitHub happens, or at a scheduled time. The `schedule` event allows you to trigger a workflow to run at specific UTC times using [POSIX cron syntax](https://pubs.opengroup.org/onlinepubs/9699919799/utilities/crontab.html#tag_20_25_07). This cron syntax has five `*` fields, and each field represents a unit of time.
6
6
7
7
:::image type="content" source="../media/scheduled-events.png" alt-text="Diagram of the five unit-of-time fields for scheduling an event in a workflow file." border="false":::
8
8
9
-
For example, if you wanted to run a workflow every 15 minutes, the `schedule` event would look like the following:
9
+
For example, if you wanted to run a workflow every 15 minutes, the `schedule` event would look like the following example:
10
10
11
11
```yml
12
12
on:
@@ -16,7 +16,6 @@ on:
16
16
17
17
And if you wanted to run a workflow every Sunday at 3:00am, the `schedule` event would look like this:
18
18
19
-
20
19
```yml
21
20
on:
22
21
schedule:
@@ -27,7 +26,7 @@ You can also use operators to specify a range of values or to dial in your sched
27
26
28
27
## Configure workflows to run for manual events
29
28
30
-
In addition to scheduled events, you can manually trigger a workflow by using the `workflow_dispatch` event. This event allows you to run the workflow by using the GitHub REST API or by selecting the **Run workflow** button in the **Actions** tab within your repository on GitHub. Using `workflow_dispatch`, you can choose on which branch you want the workflow to run, as well as set optional `inputs` that GitHub will present as form elements in the UI.
29
+
In addition to scheduled events, you can manually trigger a workflow by using the `workflow_dispatch` event. This event allows you to run the workflow by using the GitHub REST API or by selecting the **Run workflow** button in the **Actions** tab within your repository on GitHub. Using `workflow_dispatch`, you can choose on which branch you want the workflow to run, and set optional `inputs` that GitHub presents as form elements in the UI.
31
30
32
31
```yml
33
32
on:
@@ -74,15 +73,17 @@ on:
74
73
It enables flexible automation and integration with outside tools, scripts, or systems that need to start workflows in your repo.
| `event_type` | string| A custom name for the event. This name maps to the types value in your workflow trigger | Yes |
152
+
| `client_payload` | object| Arbitrary JSON payload to send custom data to the workflow (github.event.client_payload)| No |
142
153
143
154
#### Repository_dispatch parameters breakdown
155
+
144
156
When making a POST request to the GitHub API endpoint, you must pass a JSON body with two main parameters:
157
+
145
158
- event_type
146
159
- client_payload
147
160
148
161
##### event_type
149
162
150
-
This is a required custom string you define that GitHub will treat as the "action" or "type" of the dispatch. It’s used to identify what triggered the workflow and filter workflows that are listening for specific types.
163
+
A required custom string that you define. GitHub treats this value as the "action" or "type" of the dispatch. It’s used to identify what triggered the workflow and filter workflows that are listening for specific types.
- Use in Workflow: Used in listening for specific event types and accessing the value inside the workflow. This helps with the reuse of a single workflow for multiple purposes and makes automation more organized and event-driven.
169
+
- Use in Workflow: Used in listening for specific event types and accessing the value inside the workflow. This helps with the reuse of a single workflow for multiple purposes and makes automation more organized and event-driven.
This is a free-form JSON object that lets you send custom data along with the dispatch. You define the structure, and it's accessible inside the workflow.
179
+
180
+
A free-form JSON object that lets you send custom data along with the dispatch. You define the structure, and it's accessible inside the workflow.
181
+
165
182
- Format:
166
183
- Type: object
167
184
- Custom keys and values
168
185
169
-
- Use in Workflow: Used for multi-environment deployments, versioned releases, or passing context from another system or pipeline and enables parameterized workflows, similar to input arguments.
186
+
- Use in Workflow: This object is used for multi-environment deployments, versioned releases, or passing context from another system or pipeline and enables parameterized workflows, similar to input arguments.
@@ -177,7 +196,8 @@ This is a free-form JSON object that lets you send custom data along with the di
177
196
```
178
197
179
198
##### Example payload breakdown
180
-
```
199
+
200
+
```json
181
201
{
182
202
"event_type": "deploy-to-prod",
183
203
"client_payload": {
@@ -187,11 +207,11 @@ This is a free-form JSON object that lets you send custom data along with the di
187
207
"services": ["web", "api", "worker"]
188
208
}
189
209
}
190
-
191
210
```
211
+
192
212
## Use conditional keywords
193
213
194
-
Within your workflow file, you can access context information and evaluate expressions. Although expressions are commonly used with the conditional `if` keyword in a workflow file to determine whether a step should run or not, you can use any supported context and expression to create a conditional. It's important to know that when using conditionals in your workflow, you need to use the specific syntax `${{ <expression> }}`. This tells GitHub to evaluate an expression rather than treat it as a string.
214
+
Within your workflow file, you can access context information and evaluate expressions. Although expressions are commonly used with the conditional `if` keyword in a workflow file to determine whether a step should run or not, you can use any supported context and expression to create a conditional. It's important to know that when using conditionals in your workflow, you need to use the specific syntax `${{ <expression> }}`. This syntax tells GitHub to evaluate an expression rather than treat it as a string.
195
215
196
216
For example, a workflow that uses the `if` conditional to check if the `github.ref` (the branch or tag ref that triggered the workflow run) matches `refs/heads/main`. In order to proceed, the workflow would look something like this:
197
217
@@ -206,7 +226,7 @@ jobs:
206
226
...
207
227
```
208
228
209
-
Notice that in this example, the `${{ }}` are missing from the syntax. With some expressions, as in the case of the `if` conditional, you can omit the expression syntax. GitHub automatically evaluates some of these common expressions, but you can always include them in case you forget which expressions GitHub automatically evaluates.
229
+
Notice that in this example, the `${{ }}` are missing from the syntax. With some expressions, like the `if` conditional, you can omit the expression syntax. GitHub automatically evaluates some of these common expressions, but you can always include them in case you forget which expressions GitHub automatically evaluates.
210
230
211
231
For more information about workflow syntax and expressions, check out [Workflow syntax for GitHub Actions](https://docs.github.com/actions/reference/workflow-syntax-for-github-actions#jobsjob_idstepsif).
212
232
@@ -225,11 +245,11 @@ Disabling a workflow can be useful in some of the following situations:
225
245
- You want to pause a workflow that's sending requests to a service that is down.
226
246
- You're working on a fork, and you don't need all the functionality of some workflows it includes (like scheduled workflows).
227
247
228
-
You can also cancel a workflow run that's in progress in the GitHub UI from the **Actions** tab or by using the GitHub API endpoint `DELETE /repos/{owner}/{repo}/actions/runs/{run_id}`. Keep in mind that when you cancel a workflow run, GitHub will cancel all of its jobs and steps within that run.
248
+
You can also cancel a workflow run that's in progress in the GitHub UI from the **Actions** tab or by using the GitHub API endpoint `DELETE /repos/{owner}/{repo}/actions/runs/{run_id}`. Keep in mind that when you cancel a workflow run, GitHub cancels all of its jobs and steps within that run.
229
249
230
250
## Use an organization's templated workflow
231
251
232
-
If you have a workflow that multiple teams use within an organization, you don't need to re-create the same workflow for each repository. Instead, you can promote consistency across your organization by using a workflow template that's defined in the organization's `.github` repository. Any member within the organization can use an organization template workflow, and any repository within that organization has access to those template workflows.
252
+
If you have a workflow that multiple teams use within an organization, you don't need to re-create the same workflow for each repository. Instead, you can promote consistency across your organization by using a workflow template defined in the organization's `.github` repository. Any member within the organization can use an organization template workflow, and any repository within that organization has access to those template workflows.
233
253
234
254
You can find these workflows by navigating to the **Actions** tab of a repository within the organization, selecting **New workflow**, and then finding the organization's workflow template section titled "Workflows created by *organization name*". For example, the organization called Mona has a template workflow as shown here.
235
255
@@ -251,4 +271,4 @@ steps:
251
271
- uses: actions/setup-node@main
252
272
```
253
273
254
-
Some references are safer than others. For example, referencing a specific branch will run that action off of the latest changes from that branch, which you may or may not want. By referencing a specific version number or commit SHA hash, you're being more specific about the version of the action you're running. For more stability and security, we recommend that you use the commit SHA of a released action within your workflows.
274
+
Some references are safer than others. For example, referencing a specific branch runs that action off of the latest changes from that branch, which you might or might not want. By referencing a specific version number or commit SHA hash, you're being more specific about the version of the action you're running. For more stability and security, we recommend that you use the commit SHA of a released action within your workflows.
0 commit comments