Skip to content

Commit 6cb94db

Browse files
Merge pull request #51009 from v-thpra/azure-triage-fix-1061037
Fix for Customer Feedback 1061037: Extra row in parameters table
2 parents 4878933 + f892a81 commit 6cb94db

File tree

1 file changed

+45
-25
lines changed

1 file changed

+45
-25
lines changed

learn-pr/github/github-actions-automate-tasks/includes/2c-configure-github-actions-workflow.md

Lines changed: 45 additions & 25 deletions
Original file line numberDiff line numberDiff 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.
22

33
## Configure workflows to run for scheduled events
44

55
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.
66

77
:::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":::
88

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:
1010

1111
```yml
1212
on:
@@ -16,7 +16,6 @@ on:
1616
1717
And if you wanted to run a workflow every Sunday at 3:00am, the `schedule` event would look like this:
1818

19-
2019
```yml
2120
on:
2221
schedule:
@@ -27,7 +26,7 @@ You can also use operators to specify a range of values or to dial in your sched
2726

2827
## Configure workflows to run for manual events
2928

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.
3130

3231
```yml
3332
on:
@@ -74,15 +73,17 @@ on:
7473
It enables flexible automation and integration with outside tools, scripts, or systems that need to start workflows in your repo.
7574

7675
### Use cases
76+
7777
- Trigger workflows from external CI/CD tools.
7878

79-
- Coordinate multi-repo deployments (e.g., Repo A finishes build → triggers Repo B).
79+
- Coordinate multi-repo deployments (for example, Repo A finishes build → triggers Repo B).
8080

8181
- Start automation based on external events (webhooks, monitoring alerts, CRON jobs outside GitHub).
8282

8383
- Chain workflow executions between repositories or within monorepos.
8484

8585
### Example workflow that listens to repository_dispatch
86+
8687
```yml
8788
name: Custom Dispatch Listener
8889
@@ -99,31 +100,40 @@ jobs:
99100
echo "Event type: ${{ github.event.action }}"
100101
echo "Payload value: ${{ github.event.client_payload.env }}"
101102
```
103+
102104
### Key elements:
103-
- types: Optional. Defines custom event types like run-tests, deploy-to-prod, etc.
104105

105-
- github.event.client_payload: Access to any additional custom data passed in the dispatch event.
106+
- types: Optional. Defines custom event types like `run-tests`, `deploy-to-prod`, etc.
107+
108+
- github.event.client_payload: Access to any other custom data passed in the dispatch event.
106109

107110
- github.event.action: Name of the event_type sent.
108111

109112
### Triggering the event via API
113+
110114
You must send a POST request to the GitHub REST API v3 endpoint:
115+
111116
```sh
112117
POST https://api.github.com/repos/OWNER/REPO/dispatches
113118
```
119+
114120
#### Authorization
121+
115122
- Requires a personal access token (PAT) with repo scope.
116123
- For organizations, ensure proper access settings for your token.
117124

118125
#### Sample command structure
126+
119127
```sh
120128
curl -X POST \
121129
-H "Accept: application/vnd.github+json" \
122130
-H "Authorization: token YOUR_GITHUB_TOKEN" \
123131
https://api.github.com/repos/OWNER/REPO/dispatches \
124132
-d '{"event_type":"run-tests","client_payload":{"env":"staging"}}'
125133
```
134+
126135
#### Payload structure
136+
127137
```json
128138
{
129139
"event_type": "run-tests",
@@ -133,42 +143,51 @@ curl -X POST \
133143
}
134144
135145
```
146+
136147
#### Parameters
137-
| Field | Type | Description |Required|
138-
|----------------|----------------------------------------------------------|--------------|----------|
139-
| `event_type` | string | A custom name for the event. This maps to the types value in your workflow trigger | Yes
140-
| `client_payload` | object | Arbitrary JSON payload to send custom data to the workflow (github.event.client_payload) | No
141-
| No |
148+
149+
| Field | Type | Description |Required|
150+
|------------------|----------------------|-----------------------------------------------------------------------------------------------|--------|
151+
| `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 |
142153

143154
#### Repository_dispatch parameters breakdown
155+
144156
When making a POST request to the GitHub API endpoint, you must pass a JSON body with two main parameters:
157+
145158
- event_type
146159
- client_payload
147160

148161
##### event_type
149162

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.
151164

152165
- Format:
153166
- Type: string
154167
- Example: "deploy", "run-tests", "sync-db", "build-docker"
155168

156-
- 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.
170+
157171
- Example:
158-
```
172+
173+
```json
159174
- name: Print event type
160175
run: echo "Event type: ${{ github.event.action }}"
161176
```
162177

163178
##### client_payload
164-
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+
165182
- Format:
166183
- Type: object
167184
- Custom keys and values
168185

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.
187+
170188
- Example:
171-
```
189+
190+
```json
172191
- name: Show payload values
173192
run: |
174193
echo "Environment: ${{ github.event.client_payload.env }}"
@@ -177,7 +196,8 @@ This is a free-form JSON object that lets you send custom data along with the di
177196
```
178197

179198
##### Example payload breakdown
180-
```
199+
200+
```json
181201
{
182202
"event_type": "deploy-to-prod",
183203
"client_payload": {
@@ -187,11 +207,11 @@ This is a free-form JSON object that lets you send custom data along with the di
187207
"services": ["web", "api", "worker"]
188208
}
189209
}
190-
191210
```
211+
192212
## Use conditional keywords
193213

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.
195215

196216
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:
197217

@@ -206,7 +226,7 @@ jobs:
206226
...
207227
```
208228

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.
210230

211231
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).
212232

@@ -225,11 +245,11 @@ Disabling a workflow can be useful in some of the following situations:
225245
- You want to pause a workflow that's sending requests to a service that is down.
226246
- You're working on a fork, and you don't need all the functionality of some workflows it includes (like scheduled workflows).
227247

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.
229249

230250
## Use an organization's templated workflow
231251

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.
233253

234254
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.
235255

@@ -251,4 +271,4 @@ steps:
251271
- uses: actions/setup-node@main
252272
```
253273

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

Comments
 (0)