TExcelTAD
Home › CI/CD Pipelines & Pipeline Security › Workflows, Jobs & Steps

Workflows, Jobs & Steps

GitHub Actions is GitHub's built-in CI/CD system, and the one most teams meet first. This section teaches it end to end; Release Engineering uses the same syntax for release automation (versions, changelogs, tag-driven releases) and goes deeper into matrices and caching. Workflows can't run on this site (they need GitHub's runners), so the YAML here is non-run, written against the current documentation, and the mechanics behind it run as sessions and models.

The building blocks

Term What it is
workflow a YAML file in .github/workflows/; it has a name, triggers (on) and jobs
job runs on one runner (a fresh VM for GitHub-hosted runners); jobs run in parallel unless linked with needs
step runs inside a job, in order: either a shell command (run) or an action (uses)
action reusable step code: actions/checkout@v7 is the repository actions/checkout at tag v7
runner the machine: ubuntu-24.04, windows-2025, macos-15, ubuntu-24.04-arm, or a self-hosted label
expression ${{ … }}: evaluated by GitHub before the step runs, using contexts (github, env, vars, secrets, needs, matrix, steps, runner, inputs, job)

A first workflow

yaml
# .github/workflows/ci.yml
name: ci
on:
  push:
    branches: [main]
  pull_request:

permissions:
  contents: read                       # least privilege for the automatic GITHUB_TOKEN

env:
  PYTHONUNBUFFERED: '1'                # workflow-level environment, visible to every step

jobs:
  test:
    name: Unit tests
    runs-on: ubuntu-24.04
    timeout-minutes: 15
    steps:
      - uses: actions/checkout@v7      # the repository is NOT on the runner until you check it out
      - uses: actions/setup-python@v7
        with:
          python-version: '3.13'       # quoted: see "Pipeline as Code"
      - name: Install
        run: pip install -r requirements.txt
      - name: Test
        run: |
          python -m pytest -q --junitxml=report.xml
      - name: Describe the commit
        id: describe
        run: echo "short=${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT"
      - run: echo "Tested ${{ steps.describe.outputs.short }}" >> "$GITHUB_STEP_SUMMARY"

Things that surprise newcomers:

  • Every job starts on a clean machine. Files from one job are not in the next unless you pass them as artifacts (Job Graphs, Caches & Artifacts).
  • run: uses bash -e on Linux (precisely bash --noprofile --norc -eo pipefail {0} when you set shell: bash; the default without shell: is bash -e {0}, without pipefail). Set defaults: run: shell: bash at the workflow level to get pipefail everywhere.
  • Expressions are text substitution. ${{ github.event.pull_request.title }} is pasted into the script before bash sees it; that is the script-injection hole covered in Hardening Workflows.
  • $GITHUB_OUTPUT, $GITHUB_ENV, $GITHUB_PATH and $GITHUB_STEP_SUMMARY are files. A step appends lines; the runner reads them after the step ends.

How step outputs work

The runner gives every step a fresh file in $GITHUB_OUTPUT and parses it after the step: name=value lines, or name<<DELIMITER … DELIMITER blocks for multi-line values. The session imitates a runner executing three steps, so you can see the mechanism without GitHub:

bash · try it yourself
declare -A OUTPUTS
run_step() {   # run_step ID SCRIPT: run SCRIPT with its own output file, then parse it like the runner
  local id=$1 script=$2 file name value line delim key
  while [[ $script =~ \$\{\{\ steps\.([a-z]+)\.outputs\.([a-z]+)\ \}\} ]]; do   # expressions first, as text
    key="${BASH_REMATCH[1]}.${BASH_REMATCH[2]}"
    script=${script//"${BASH_REMATCH[0]}"/"${OUTPUTS[$key]}"}
  done
  file=$(mktemp)
  GITHUB_OUTPUT=$file bash -eo pipefail -c "$script"
  while IFS= read -r line; do
    if [[ $line == *'<<'* ]]; then                 # name<<DELIM ... DELIM
      name=${line%%<<*}; delim=${line#*<<}; value=""
      while IFS= read -r line && [[ $line != "$delim" ]]; do value+="${value:+
  

\n'}$line"; done
    else
      name=${line%%=*}; value=${line#*=}
    fi
    OUTPUTS[$id.$name]=$value
  done < "$file"
}
run_step version 'echo "tag=v1.4.0" >> "$GITHUB_OUTPUT"'
run_step notes   '{ echo "text<<EOF"; printf "fix: cart total\nfeat: coupons\n"; echo "EOF"; } >> "$GITHUB_OUTPUT"'
run_step build   'echo "image=shop:${{ steps.version.outputs.tag }}"'
echo "steps.version.outputs.tag  = ${OUTPUTS[version.tag]}"
printf 'steps.notes.outputs.text  =\n%s\n' "${OUTPUTS[notes.text]}"
image=shop:v1.4.0
steps.version.outputs.tag  = v1.4.0
steps.notes.outputs.text  =
fix: cart total
feat: coupons

The third step's ${{ steps.version.outputs.tag }} was replaced by v1.4.0 as text, before bash ran, exactly as GitHub does it: bash never sees an expression. Outputs are always strings: 'true' from a step is not the boolean true in an if: (compare with == 'true').

Contexts you'll use daily

Expression Value (example)
github.event_name push, pull_request, workflow_dispatch
github.ref / github.ref_name refs/heads/main / main (for a tag: refs/tags/v1.4.0 / v1.4.0)
github.sha the commit being built (for pull_request: the merge commit)
github.repository, github.actor acme/shop, the user who triggered the run
runner.os, runner.temp Linux, a temporary directory cleaned after the job
steps.<id>.outputs.<name> outputs of an earlier step in the same job
needs.<job>.outputs.<name> outputs of a job this job needs
vars.NAME, secrets.NAME configuration variables and secrets (next lessons)

Most contexts are also available as environment variables inside steps (GITHUB_SHA, GITHUB_REF_NAME, RUNNER_OS). Prefer the environment variable inside scripts and the expression in YAML keys (if:, with:, runs-on:): that habit avoids injection bugs.

Test yourself

A job writes dist/app.tar.gz. The next job (with needs) can't find it. Why?

  1. needs runs jobs in the same directory
  2. Each job runs on a fresh runner; files must be passed as artifacts
  3. The file was cached
  4. dist/ is ignored by Git

How does a step set an output named tag?

  1. export tag=v1
  2. echo "tag=v1" >> "$GITHUB_OUTPUT"
  3. ::set-env tag=v1
  4. return v1

Where is it safer to use $GITHUB_REF_NAME than ${{ github.ref_name }}?

  1. In if: conditions
  2. Inside run: scripts, where expression text would be pasted into the code
  3. In runs-on
  4. Nowhere