Skip to content

Commit ec616b8

Browse files
authored
Merge pull request #50427 from camihmerhar/main
Update to GitHub Action Modules
2 parents e3eca3b + f8c7118 commit ec616b8

File tree

7 files changed

+388
-5
lines changed

7 files changed

+388
-5
lines changed

learn-pr/github/github-actions-automate-tasks/includes/2-github-actions-automate-development-tasks.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,56 @@ Each type of runner has its benefits, but GitHub-hosted runners offer a quicker
167167
### GitHub Actions may have usage limits
168168

169169
GitHub Actions has some usage limits, depending on your GitHub plan and whether your runner is GitHub-hosted or self-hosted. For more information on usage limits, check out [Usage limits, billing, and administration](https://docs.github.com/actions/reference/usage-limits-billing-and-administration) in the GitHub documentation.
170+
171+
## GitHub hosted larger runners
172+
GitHub offers larger runners for workflows that require more resources. These runners are GitHub-hosted and provide increased CPU, memory, and disk space compared to standard runners. They are designed to handle resource-intensive workflows efficiently, ensuring optimal performance for demanding tasks.
173+
174+
### Runner sizes and labels
175+
Larger runners are available in multiple configurations, providing enhanced vCPUs, RAM, and SSD storage to meet diverse workflow requirements. These configurations are ideal for scenarios such as:
176+
- Compiling large codebases with extensive source files.
177+
- Running comprehensive test suites, including integration and end-to-end tests.
178+
- Processing large datasets for data analysis or machine learning tasks.
179+
- Building applications with complex dependencies or large binary outputs.
180+
- Performing high-performance simulations or computational modeling.
181+
- Executing video encoding, rendering, or other multimedia processing workflows.
182+
183+
To use a larger runner, specify the desired runner label in the `runs-on` attribute of your workflow file. For example, to use a runner with 16 vCPUs and 64 GB of RAM, you would set `runs-on: ubuntu-latest-16core`.
184+
185+
```yml
186+
jobs:
187+
build:
188+
runs-on: ubuntu-latest-16core
189+
steps:
190+
- uses: actions/checkout@v2
191+
- name: Build project
192+
run: make build
193+
```
194+
These larger runners maintain compatibility with existing workflows by including the same preinstalled tools as standard `ubuntu-latest` runners.
195+
196+
For more details on runner sizes for larger runners, refer to the GitHub documentation [https://docs.github.com/en/actions/using-github-hosted-runners/using-larger-runners/about-larger-runners#machine-sizes-for-larger-runners]
197+
198+
199+
### Managing larger runners
200+
GitHub provides tools to manage larger runners effectively, ensuring optimal resource utilization and cost management. Here are some key aspects of managing larger runners:
201+
202+
#### Monitoring usage
203+
You can monitor the usage of larger runners through the GitHub Actions usage page in your repository or organization settings. This page provides insights into the number of jobs run, the total runtime, and the associated costs.
204+
205+
#### Managing access
206+
To control access to larger runners, you can configure repository or organization-level policies. This ensures that only authorized workflows or teams can use these high-resource runners.
207+
208+
#### Cost management
209+
Larger runners incur additional costs based on their usage. To manage costs, consider the following:
210+
- Use larger runners only for workflows that require high resources.
211+
- Optimize workflows to reduce runtime.
212+
- Monitor billing details regularly to track expenses.
213+
214+
#### Scaling workflows
215+
If your workflows require frequent use of larger runners, consider scaling strategies such as:
216+
- Using self-hosted runners for predictable workloads.
217+
- Splitting workflows into smaller jobs to distribute the load across standard runners.
218+
219+
220+
221+
222+

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

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,128 @@ on:
6767
types: [rerequested, requested_action]
6868
```
6969

70+
<!-- INFOMAGNUS UPDATES for sub OD 1.1.4 go here. Source Material: https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows#repository_dispatch -->
71+
72+
## Repository_dispatch
73+
`repository_dispatch` is a custom event in GitHub Actions that allows external systems (or even other GitHub workflows) to manually trigger workflows by sending a POST request to the GitHub API.
74+
It enables flexible automation and integration with outside tools, scripts, or systems that need to start workflows in your repo.
75+
76+
### Use cases
77+
- Trigger workflows from external CI/CD tools.
78+
79+
- Coordinate multi-repo deployments (e.g., Repo A finishes build → triggers Repo B).
80+
81+
- Start automation based on external events (webhooks, monitoring alerts, CRON jobs outside GitHub).
82+
83+
- Chain workflow executions between repositories or within monorepos.
84+
85+
### Example workflow that listens to repository_dispatch
86+
```yml
87+
name: Custom Dispatch Listener
88+
89+
on:
90+
repository_dispatch:
91+
types: [run-tests, deploy-to-prod] # Optional filtering
92+
93+
jobs:
94+
run:
95+
runs-on: ubuntu-latest
96+
steps:
97+
- name: Echo the payload
98+
run: |
99+
echo "Event type: ${{ github.event.action }}"
100+
echo "Payload value: ${{ github.event.client_payload.env }}"
101+
```
102+
### Key elements:
103+
- types: Optional. Defines custom event types like run-tests, deploy-to-prod, etc.
104+
105+
- github.event.client_payload: Access to any additional custom data passed in the dispatch event.
106+
107+
- github.event.action: Name of the event_type sent.
108+
109+
### Triggering the event via API
110+
You must send a POST request to the GitHub REST API v3 endpoint:
111+
```sh
112+
POST https://api.github.com/repos/OWNER/REPO/dispatches
113+
```
114+
#### Authorization
115+
- Requires a personal access token (PAT) with repo scope.
116+
- For organizations, ensure proper access settings for your token.
117+
118+
#### Sample command structure
119+
```sh
120+
curl -X POST \
121+
-H "Accept: application/vnd.github+json" \
122+
-H "Authorization: token YOUR_GITHUB_TOKEN" \
123+
https://api.github.com/repos/OWNER/REPO/dispatches \
124+
-d '{"event_type":"run-tests","client_payload":{"env":"staging"}}'
125+
```
126+
#### Payload structure
127+
```json
128+
{
129+
"event_type": "run-tests",
130+
"client_payload": {
131+
"env": "staging"
132+
}
133+
}
134+
135+
```
136+
#### 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 |
142+
143+
#### Repository_dispatch parameters breakdown
144+
When making a POST request to the GitHub API endpoint, you must pass a JSON body with two main parameters:
145+
- event_type
146+
- client_payload
147+
148+
##### event_type
149+
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.
151+
152+
- Format:
153+
- Type: string
154+
- Example: "deploy", "run-tests", "sync-db", "build-docker"
155+
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.
157+
- Example:
158+
```
159+
- name: Print event type
160+
run: echo "Event type: ${{ github.event.action }}"
161+
```
162+
163+
##### 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.
165+
- Format:
166+
- Type: object
167+
- Custom keys and values
168+
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.
170+
- Example:
171+
```
172+
- name: Show payload values
173+
run: |
174+
echo "Environment: ${{ github.event.client_payload.env }}"
175+
echo "Version: ${{ github.event.client_payload.version }}"
176+
177+
```
178+
179+
##### Example payload breakdown
180+
```
181+
{
182+
"event_type": "deploy-to-prod",
183+
"client_payload": {
184+
"env": "production",
185+
"build_id": "build-456",
186+
"initiator": "admin_user",
187+
"services": ["web", "api", "worker"]
188+
}
189+
}
190+
191+
```
70192
## Use conditional keywords
71193
72194
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.
@@ -88,6 +210,8 @@ Notice that in this example, the `${{ }}` are missing from the syntax. With some
88210

89211
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).
90212

213+
<!-- INFOMAGNUS UPDATES for sub OD 1.5.3, 1.5.4., 1.5.5., 1.5.6, 1.5.7, and 1.5.8 go here. Source Material: Infomagnus to find source material and cite -->
214+
91215
## Disable and delete workflows
92216

93217
After adding a workflow to your repository, you might find a situation where you want to temporarily disable the workflow. You can stop a workflow from being triggered without having to delete the file from the repo, either on GitHub or through the GitHub REST API. When you wish to enable the workflow again, you can easily do it using the same methods.

0 commit comments

Comments
 (0)