How to Write GitHub Actions YAML
A complete guide to the syntax and structure of GitHub Actions YAML files.
Understanding YAML syntax
YAML relies on strict indentation (spaces, not tabs) to denote structure. GitHub Actions YAML requires specific top-level keys: name, on, and jobs.
The "on" Trigger
The "on" key defines what triggers the workflow. Common triggers include push to specific branches, pull_request, schedule (cron syntax), and workflow_dispatch (manual trigger).
Jobs and Steps
A workflow contains jobs that run in parallel by default. Each job contains sequential steps, which can either use pre-built actions (uses:) or run shell commands (run:).
Using Secrets
Never hardcode credentials in your YAML. Store them in GitHub Repository Secrets and reference them using the syntax ${{ secrets.SECRET_NAME }}.