AI Hints
Home›CI/CD with GitHub Actions Tutorial›Cheat Sheets and Final Quiz
CI/CD with GitHub Actions · Lesson 130 of 138

Cheat Sheet: Workflow Syntax

All the keys in one place.

⏱ 2 min read▶ Video at 2:31:32🎓 Free
Watch this lesson in the CI/CD with GitHub Actions courseWatch on YouTube ↗Full CI/CD with GitHub Actions course

Here's a cheat sheet of the workflow keys you'll use most. Pause the video, or take a screenshot, and keep it next to you while you write workflows.

Cheat Sheet: Workflow Syntax
From the video: Cheat Sheet: Workflow Syntax
  • The keys you'll use most
  • Pause or screenshot
  • Keep it nearby

Top of the file and jobs

At the top, the name, and on, with the triggers. Push with filters, pull request, schedule, and the manual button. Then permissions, shared env, and concurrency. Each job has runs on, a timeout, and an optional matrix. And steps, which either use an action, or run a command.

cheatsheet-1.ymlyaml
name: CI                         # shown in the Actions tab
on:                              # triggers
  push: { branches: [main], paths: ["src/**"] }
  pull_request:
  schedule: [ { cron: "0 3 * * *" } ]
  workflow_dispatch:
permissions: { contents: read }  # token rights
env: { APP_ENV: test }           # variables for all jobs
concurrency: { group: "ci-${{ github.ref }}", cancel-in-progress: true }
jobs:
  test:
    runs-on: ubuntu-latest       # the runner
    timeout-minutes: 10
    strategy: { matrix: { python: ["3.11", "3.12"] } }
    steps:
      - uses: actions/checkout@v4                # an action
      - run: pytest -q                           # a command
        env: { CI_MODE: strict }

Job features

For a deploy job, needs sets the order. If adds a condition. Environment brings in rules and secrets. Outputs pass values to later jobs, from step outputs. Secrets are read into environment variables. And if failure, runs a step only when something failed.

cheatsheet-2.ymlyaml
  deploy:
    needs: test                          # wait for test
    if: github.ref == 'refs/heads/main'  # only on main
    environment: production              # rules + secrets
    outputs: { tag: "${{ steps.v.outputs.tag }}" }
    steps:
      - id: v
        run: echo "tag=sha-${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT"
      - run: ./deploy.sh ${{ steps.v.outputs.tag }}
        env: { TOKEN: "${{ secrets.DEPLOY_TOKEN }}" }
      - if: failure()
        run: echo "tell the team"

Summary

Triggers, permissions, jobs, steps, needs, conditions, environments, and outputs. That's most of GitHub Actions on two screens. Next, a cheat sheet of patterns.

Key takeaways
  • on: triggers
  • jobs: runs-on, steps
  • needs, if, environment
Next up: Cheat Sheet: Patterns — recipes to reuse