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 tabon: # triggers push: { branches: [main], paths: ["src/**"] } pull_request: schedule: [ { cron: "0 3 * * *" } ] workflow_dispatch:permissions: { contents: read } # token rightsenv: { APP_ENV: test } # variables for all jobsconcurrency: { 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 }
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"
Triggers, permissions, jobs, steps, needs, conditions, environments, and outputs. That's most of GitHub Actions on two screens. Next, a cheat sheet of patterns.