GitHub Actions: Workflows & Triggers
GitHub Actions is the CI/CD system most open-source projects and many companies use, so the next lessons go through it in depth. The examples are YAML files that can't run on this site; they follow the current GitHub Actions documentation and use the current major versions of the official actions (actions/checkout@v7, actions/setup-node@v7, actions/cache@v6, actions/upload-artifact@v7, actions/download-artifact@v8). The ideas behind them run as models in the browser.
The vocabulary
| Term | Meaning |
|---|---|
| workflow | a YAML file in .github/workflows/; one file = one workflow |
| event / trigger | what starts it: push, pull_request, workflow_dispatch (a button), schedule (cron), release, workflow_call (called by another workflow) and many more |
| job | a set of steps on one runner (fresh VM or container); jobs run in parallel unless they declare needs |
| step | a shell command (run:) or an action (uses:): reusable code from a repository or the Marketplace |
| runner | the machine: GitHub-hosted (ubuntu-latest, windows-latest, macos-latest, and specific images such as ubuntu-24.04, ubuntu-24.04-arm) or self-hosted |
| context / expression | ${{ github.ref }}, ${{ matrix.os }}, ${{ secrets.X }}: values filled in before a step runs |
A complete CI workflow
# .github/workflows/ci.yml
name: ci
on:
push:
branches: [main, 'release/**']
tags: ['v*']
paths-ignore: ['docs/**', '**.md']
pull_request:
branches: [main]
workflow_dispatch: # a "Run workflow" button, optionally with inputs
permissions:
contents: read # least privilege for the GITHUB_TOKEN (see the security lesson)
jobs:
test:
runs-on: ubuntu-24.04
timeout-minutes: 15 # default is 360
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0 # full history and tags: needed by git describe and release tools
- uses: actions/setup-node@v7
with:
node-version-file: .nvmrc
cache: npm
- run: npm ci
- run: npm test
- name: Describe the build
run: echo "version $(git describe --tags --always)" >> "$GITHUB_STEP_SUMMARY"Details worth knowing:
actions/checkoutfetches one commit by default (fetch-depth: 1). Anything that needs history or tags (version fromgit describe, changelog generation, commitlint ranges) needsfetch-depth: 0. git describe & Version Strings shows the failure.$GITHUB_STEP_SUMMARY,$GITHUB_OUTPUTand$GITHUB_ENVare files: appendkey=valuelines to set step outputs and environment variables for later steps, or Markdown for the run summary.- Pin the runner image (
ubuntu-24.04) for release builds;ubuntu-latestmoves to a new Ubuntu version on GitHub's schedule, which changes compilers and libraries under you.
Triggers and filters
| Trigger | Typical use | Notes |
|---|---|---|
push with branches |
CI on main and release branches | combine with paths/paths-ignore to skip docs-only changes |
push with tags: ['v*'] |
release builds | path filters are not evaluated for tag pushes |
pull_request |
CI for PRs | runs on the merge commit; from forks, the token is read-only and secrets are unavailable |
pull_request_target |
labelling, commenting on fork PRs | runs in the base repository's context with secrets: never check out and run the PR's code in it |
workflow_dispatch |
manual releases, re-deploys | inputs: define a form |
schedule |
nightlies, dependency checks | cron in UTC; can be delayed at busy times; disabled after 60 days of repository inactivity in public repos |
release (types: [published]) |
publish after a human publishes a GitHub Release | the release must be created with a token other than GITHUB_TOKEN to trigger it from another workflow |
workflow_call |
reusable workflows | Reusable Workflows & Composite Actions |
The last row hides an important rule: events caused by the GITHUB_TOKEN don't start new workflow runs (except workflow_dispatch and repository_dispatch). A release job that pushes a tag with the default token will not trigger your on: push: tags workflow. Either do the build in the same workflow (needs), or push with a GitHub App token.
How branch and path filters match
Filters use glob patterns where * matches anything except /, ** matches anything including /, and a pattern starting with ! excludes. Patterns are evaluated in order, and the last matching pattern decides. This model implements those rules and checks a few refs and file lists:
import re
def glob_to_regex(pattern):
out, i = "", 0
while i < len(pattern):
if pattern.startswith("**", i):
out += ".*"; i += 2
elif pattern[i] == "*":
out += "[^/]*"; i += 1
elif pattern[i] == "?":
out += "[^/]"; i += 1
else:
out += re.escape(pattern[i]); i += 1
return re.compile("^" + out + "quot;)
def matches(patterns, name):
result = False
for p in patterns: # in order; the last match wins
negate = p.startswith("!")
if glob_to_regex(p.lstrip("!")).match(name):
result = not negate
return result
branches = ["main", "release/**", "!release/**-experimental"]
for ref in ["main", "release/1.5", "release/v2/hotfix", "release/2.0-experimental", "feature/login"]:
print(f"branch {ref:<26} -> {'run' if matches(branches, ref) else 'skip'}")
tags = ["v[0-9]*"]
# GitHub's patterns support character classes too; this model treats [...] as a regex class
for tag in ["v1.4.2", "v2.0.0-rc.1", "nightly-2026-01-15", "version-1"]:
print(f"tag {tag:<26} -> {'run' if re.match('^v[0-9][^/]*