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

name

Display name; defaults to the file path when omitted.

run-name

Display name of each run; can use the github and inputs contexts.

on

Events, with optional filters. Required.

permissions

Scopes of the automatic GITHUB_TOKEN (contents, pull-requests, id-token, pages …​). Setting it narrows everything not listed to none. Can also be set per job.

env

Environment variables; a job- or step-level env overrides it.

defaults

Default shell and working-directory for run steps (per workflow or per job).

concurrency

A group name; only one run per group at a time. See below.

jobs

Required. A map of job IDs to job definitions.

Event flow

flowchart TD A[Event occurs] --> B{Which workflow files on the relevant ref listen for it?} B -->|none| Z[Nothing runs] B -->|one or more| C{Do branch, tag, path and type filters match?} C -->|no| Z C -->|yes| D[Create a workflow run] D --> E{concurrency group busy?} E -->|yes, cancel-in-progress| F[Cancel the older run] E -->|yes, otherwise| G[Queue the new run] E -->|no| H[Run jobs] F --> H G --> H

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 / tags use 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.

  • paths and paths-ignore compare against the changed files. They do not apply to tag pushes.

  • pull_request defaults to the types opened, synchronize and reopened. 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 push plus an unfiltered pull_request runs twice for a branch with an open PR; filter push to main and 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.schedule context 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

release

A release is created, published, edited, deleted or prereleased (types: [published]).

Runs on the tagged commit; see Tags and Releases.

workflow_run

Another workflow completes (types: [completed], workflows: [CI]).

Runs from the default branch with write token and secrets; check github.event.workflow_run.conclusion.

repository_dispatch

An API call posts an event of a custom event_type.

gh api repos/OWNER/REPO/dispatches -f event_type=docs-updated. Payload in github.event.client_payload.

issues, issue_comment, pull_request_review

Activity on issues, comments or reviews.

issue_comment also fires for pull-request comments; check github.event.issue.pull_request.

pull_request_target

Like pull_request but runs in the context of the base branch, with secrets.

Dangerous with untrusted code; see Security Hardening.

create, delete

A branch or tag is created or deleted.

Prefer a push filter on tags for releases.

check_suite, status, deployment

Check, commit-status and deployment activity.

Used by integrations and chat-ops flows.

merge_group

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

github

event_name, ref, ref_name, sha, repository, actor, run_id, run_number, event (the webhook payload), base_ref, head_ref, token.

env

Variables set with env: or GITHUB_ENV.

vars

Configuration variables defined in repository, environment or organization settings.

secrets

Secret values, plus the automatic GITHUB_TOKEN. Not available in if: of a job; masked in logs.

needs

Outputs and results of the jobs a job depends on: needs.build.outputs.version, needs.build.result.

matrix / strategy

The current matrix combination, and strategy settings such as fail-fast.

steps

Outputs, outcome and conclusion of earlier steps in the same job: steps.meta.outputs.tags.

job / runner

Job status and container info; runner os, arch, name, temp, tool_cache.

inputs

Inputs of workflow_dispatch or workflow_call.

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

contains(search, item)

Substring or array membership: contains(github.event.head_commit.message, '[skip ci]').

startsWith(), endsWith()

startsWith(github.ref, 'refs/tags/v').

format('{0}-{1}', a, b)

String templating.

join(array, sep)

join(matrix.os, ', ').

toJSON(value) / fromJSON(string)

Serialize for debugging, or parse a JSON string into a value (dynamic matrices, typed outputs).

hashFiles('**/package-lock.json')

SHA-256 over the matching files, for cache keys. Empty string when nothing matches.

success(), failure(), always(), cancelled()

Status checks usable in if:. A bare if: without one implies success().

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_OUTPUT values are read as steps.<id>.outputs.<name>; multi-line values use a delimiter (name<<EOF followed by the lines and a closing EOF).

  • GITHUB_ENV takes effect from the next step on, not the current one.

  • GITHUB_STEP_SUMMARY accepts Markdown shown on the run page.

  • The older ::set-output and ::set-env commands 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: push with branches at the wrong indentation: the filter is silently ignored.

  • Testing a schedule or workflow_dispatch change on a feature branch; only the default branch’s file is used.

  • Combining paths and paths-ignore for the same event, which is rejected.

  • Using ${{ }} with untrusted fields such as github.event.pull_request.title directly in a run script; pass them through env: instead (see Security Hardening).

  • Expecting env set through GITHUB_ENV to be visible in the same step.

  • Relying on cron at an exact minute, or forgetting that cron is UTC.