Sub topic 1
How a workflow file turns events into runs
Prerequisites
This chapter assumes you know the following:
- Basic Git and GitHub usage: branches, commits and pull requests.
- Simple YAML: mappings, lists and indentation.
- The idea of continuous integration (CI), where code is built and tested automatically after each change.
Events, workflows and runs
GitHub Actions is event-driven. Something happens in your repository, and GitHub checks whether any workflow asks to be started by it. Three terms matter here:
- An event is an activity in the repository, such as a push, a new pull request or a clock tick.
- A workflow is a YAML file in
.github/workflows/. Both.ymland.yamlextensions work. - A run is one execution of a workflow, started by one event.
The on key in the workflow file is the link between them. It lists the events that start the workflow.
name: CI
on: push
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: echo "Triggered by ${{ github.event_name }}"Every push to the repository starts one run of this workflow. The github.event_name expression prints push, which shows that the run knows which event started it.
What happens after an event
GitHub does the following for each event:
- It finds the workflow files for the commit the event refers to.
- It compares each file's
onkey with the event. Filters such as branches, tags and paths must match too, and so must the activity type. - For each matching workflow, it creates a run. The run's jobs are queued and picked up by runners.
A workflow that does not match is skipped without any message. This is why a misconfigured trigger is hard to notice. You see no failed run, only a missing one.
Which version of the file is used
The workflow file comes from a specific commit, and which commit depends on the event:
| Event | Workflow file taken from |
|---|---|
| `push` | The commit that was pushed |
| `pull_request` | The pull request's merge commit, which combines the head branch with the base branch |
| `schedule` | The latest commit on the default branch |
| `workflow_dispatch` | The branch or tag you choose when you start the run |
For schedule, the file must be on the default branch before the trigger can fire. workflow_dispatch also needs the file on the default branch before the Run workflow button appears in the web interface.
Where the rest of the plan fits
The rest of this tutorial covers the on key and the four common events:
pushpull_requestscheduleworkflow_dispatch
For each one, it covers the filters that decide whether a matching event creates a run.
Exercise
You add a workflow file with on: schedule to a feature branch, but it never runs on its schedule. What is the likely reason?
Show answer
Scheduled workflows run only from the latest commit on the default branch. The file must be merged into the default branch before the schedule can fire.