Workflow Syntax and Triggers
|
This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production. |
A workflow file has a small, fixed vocabulary of top-level keys. Most of the craft is in the on block (which events
start it, and with which filters) and in the expression language that decides what runs and with which values. This page
is the syntax reference for both. Jobs, steps and matrices have their own page,
Jobs, Steps and Matrix Builds. The examples extend the
running example, this site’s nightly publish.yml, which today only has a schedule trigger.
Top-level keys
name: publish # label in the Actions tab
run-name: Publish by @${{ github.actor }} # label of each run (expressions allowed)
on: # which events start the workflow
workflow_dispatch:
permissions: # default GITHUB_TOKEN permissions for every job
contents: read
env: # variables for every job and step
NODE_ENV: production
defaults:
run:
shell: bash
working-directory: .
concurrency: # serialize or cancel overlapping runs
group: publish
cancel-in-progress: false
jobs: # the work itself
publish:
runs-on: ubuntu-latest
steps:
- run: echo "done"
| Key | Purpose |
|---|---|
|
Display name; defaults to the file path when omitted. |
|
Display name of each run; can use the |
|
Events, with optional filters. Required. |
|
Scopes of the automatic |
|
Environment variables; a job- or step-level |
|
Default |
|
A group name; only one run per group at a time. See below. |
|
Required. A map of job IDs to job definitions. |
Event flow
For most events the workflow file is read from the commit that triggered it. The notable exceptions are schedule,
workflow_dispatch, repository_dispatch, issue_comment, workflow_run and pull_request_target, which use the file
on the default branch (or for pull_request_target, the base branch).
The on key
on accepts three shapes:
on: push # one event
on: [push, pull_request] # several events, no options
on: # a map, needed for filters and options
push:
branches: [main]
pull_request:
workflow_dispatch:
push and pull_request
on:
push:
branches:
- main
- 'release/**'
- '!release/experimental' # negate with !
tags:
- 'v*.*.*'
paths:
- 'src/**'
- 'pom.xml'
paths-ignore: [] # alternative to paths; do not combine with paths
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
branches: [main]
paths-ignore:
- '**.md'
- 'docs/**'
-
branches/tagsuse glob patterns:*matches within one path segment,**crosses/. Patterns starting with!exclude. Branch and tag filters are combined with or: a push that matches either runs the workflow. -
pathsandpaths-ignorecompare against the changed files. They do not apply to tag pushes. -
pull_requestdefaults to the typesopened,synchronizeandreopened. The commit it runs on is a temporary merge of the head into the base, and secrets are not available to PRs from forks. -
An unfiltered
pushplus an unfilteredpull_requestruns twice for a branch with an open PR; filterpushtomainand release branches to avoid it.
schedule
on:
schedule:
- cron: '0 3 * * *' # minute hour day-of-month month day-of-week, in UTC
- cron: '30 5 * * 1-5' # 05:30 UTC on weekdays
-
Times are always UTC, with no time-zone option, and the shortest interval is five minutes.
-
Scheduled workflows run from the default branch only.
-
Runs are queued on a best-effort basis: during periods of high load they can start minutes late, and occasionally a run is skipped. Do not rely on a cron for exact timing.
-
The
github.event.schedulecontext holds the matching cron string, which lets one workflow behave differently per schedule.
workflow_dispatch
on:
workflow_dispatch:
inputs:
target:
description: Where to publish
type: choice
options: [staging, production]
default: staging
required: true
dry-run:
description: Build without deploying
type: boolean
default: true
version:
description: Version to release
type: string
required: false
Input types are string, boolean, number, choice and environment. Read them with inputs.<name> (typed) or
github.event.inputs.<name> (always a string). There is a documented maximum on the number of inputs, so keep forms
short. Trigger from the CLI:
gh workflow run publish.yml -f target=production -f dry-run=false
gh workflow run publish.yml --ref release_1.4 -f version=1.4.2
workflow_call
Declares the workflow as reusable: other workflows call it with uses:. Inputs, secrets and outputs are declared here;
full coverage is on Reusable
Workflows and Composite Actions.
on:
workflow_call:
inputs:
node-version:
type: string
default: '24'
secrets:
deploy-token:
required: false
outputs:
site-path:
value: ${{ jobs.build.outputs.path }}
Other events
| Event | Fires when | Notes |
|---|---|---|
|
A release is created, published, edited, deleted or prereleased ( |
Runs on the tagged commit; see Tags and Releases. |
|
Another workflow completes ( |
Runs from the default branch with write token and secrets; check |
|
An API call posts an event of a custom |
|
|
Activity on issues, comments or reviews. |
|
|
Like |
Dangerous with untrusted code; see Security Hardening. |
|
A branch or tag is created or deleted. |
Prefer a |
|
Check, commit-status and deployment activity. |
Used by integrations and chat-ops flows. |
|
A pull request enters the merge queue. |
Needed so required checks also run on the queued merge commit. |
Combining them is the normal case. A strengthened publish.yml would add push and manual triggers next to the cron:
on:
schedule:
- cron: '0 3 * * *'
workflow_dispatch:
push:
branches: [main]
paths:
- 'antora-playbook.yml'
- 'antora.yml'
- 'modules/**'
Contexts and expressions
An expression is written ${{ <expression> }} and evaluated by GitHub before the step runs (or, in if:, directly
without the delimiters). Contexts are the objects an expression can read:
| Context | Typical contents |
|---|---|
|
|
|
Variables set with |
|
Configuration variables defined in repository, environment or organization settings. |
|
Secret values, plus the automatic |
|
Outputs and results of the jobs a job depends on: |
|
The current matrix combination, and strategy settings such as |
|
Outputs, |
|
Job status and container info; runner |
|
Inputs of |
Not every context is available everywhere (for instance secrets cannot be used in jobs.<id>.if, and matrix only
inside a job); the official context-availability table lists each key.
Functions
| Function | Use |
|---|---|
|
Substring or array membership: |
|
|
|
String templating. |
|
|
|
Serialize for debugging, or parse a JSON string into a value (dynamic matrices, typed outputs). |
|
SHA-256 over the matching files, for cache keys. Empty string when nothing matches. |
|
Status checks usable in |
Operators and literals
Literals are booleans, null, numbers and single-quoted strings. Operators: ( ), [] and . (property and index
access), !, <, <=, >, >=, ==, !=, && and ||. Comparisons of different types are coerced to numbers, and
string comparison ignores case. The * object filter pulls a property out of every element, as in
github.event.commits.*.message. The &&/|| pair gives a ternary: ${{ github.ref == 'refs/heads/main' && 'prod' || 'dev' }}
(note it returns the right-hand side when the middle value is falsy).
steps:
- name: Only on tags
if: startsWith(github.ref, 'refs/tags/v')
run: echo "releasing ${GITHUB_REF_NAME}"
- name: Cleanup always
if: always()
run: rm -rf build/tmp
- name: Notify on failure
if: failure() && github.event_name == 'schedule'
run: echo "nightly build failed"
An if: that begins with ! must be quoted, because a leading ! is a YAML tag; and a value such as
if: ${{ ... }} == 'x' is only partly an expression, so write the whole condition inside one expression or none.
Passing data between steps
Steps in a job communicate through files named by environment variables:
steps:
- id: meta
run: |
echo "version=$(date +%Y.%m.%d)" >> "$GITHUB_OUTPUT" # step output
echo "SITE_DIR=build/site" >> "$GITHUB_ENV" # env var for later steps
echo "$HOME/.local/bin" >> "$GITHUB_PATH" # prepend to PATH
- run: echo "Built ${{ steps.meta.outputs.version }} into $SITE_DIR"
- name: Job summary
run: |
{
echo "## Publish result"
echo "Site generated in \`$SITE_DIR\`"
} >> "$GITHUB_STEP_SUMMARY"
-
GITHUB_OUTPUTvalues are read assteps.<id>.outputs.<name>; multi-line values use a delimiter (name<<EOFfollowed by the lines and a closingEOF). -
GITHUB_ENVtakes effect from the next step on, not the current one. -
GITHUB_STEP_SUMMARYaccepts Markdown shown on the run page. -
The older
::set-outputand::set-envcommands are disabled; use the files above.
Workflow commands
Anything a step prints in the form ::command parameters::message is interpreted by the runner:
echo "::notice file=app.js,line=1::Heads up"
echo "::warning::Cache miss, build will be slow"
echo "::error file=src/Main.java,line=42,col=7::Compilation failed"
echo "::add-mask::$GENERATED_TOKEN" # hide a value in all later log output
echo "::group::Install dependencies"
npm ci
echo "::endgroup::"
echo "::debug::Only visible with debug logging enabled"
Annotations (notice, warning, error) appear on the run page and, with file and line, on pull-request diffs.
::add-mask:: only protects values printed after it runs.
Concurrency
concurrency:
group: publish-${{ github.ref }}
cancel-in-progress: true
Runs sharing a group name are limited to one running and one pending; a newer arrival replaces the pending run, and with
cancel-in-progress: true it also cancels the one that is running. The key can be set at workflow level or per job, and
the group string can use expressions. For deployments set cancel-in-progress: false so a half-finished publish is
never killed, while for pull-request CI true saves minutes. For publish.yml the right choice is a single global
group with false, because two builds pushing to gh-pages at once would race.
Common mistakes
-
Writing
on: pushwithbranchesat the wrong indentation: the filter is silently ignored. -
Testing a
scheduleorworkflow_dispatchchange on a feature branch; only the default branch’s file is used. -
Combining
pathsandpaths-ignorefor the same event, which is rejected. -
Using
${{ }}with untrusted fields such asgithub.event.pull_request.titledirectly in arunscript; pass them throughenv:instead (see Security Hardening). -
Expecting
envset throughGITHUB_ENVto be visible in the same step. -
Relying on cron at an exact minute, or forgetting that cron is UTC.