How to add Github workflows
A quick reference for setting up GitHub Actions workflows.
Structure
Workflows live in .github/workflows/ as YAML files. GitHub picks them up automatically.
name: My Workflow
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: echo "Hello from GitHub Actions"
Key Concepts
- Triggers (
on) — what starts the workflow:push,pull_request,issues,schedule,workflow_dispatch(manual) - Jobs — run in parallel by default; use
needs:to chain them - Steps — sequential commands or actions within a job
- Actions — reusable steps from the marketplace (e.g.,
actions/checkout@v4)
Common Triggers
| Trigger | When it runs |
|---|---|
push |
Code pushed to a branch |
pull_request |
PR opened, updated, or merged |
issues: [labeled] |
A label is added to an issue |
schedule |
Cron-based (e.g., nightly builds) |
workflow_dispatch |
Manual "Run workflow" button |
Permissions
Set fine-grained permissions per job:
permissions:
contents: write
issues: write
Tips
- Use
actions/github-script@v7to run JS with full GitHub API access - Environment variables pass between steps via
core.exportVariable() - Check logs in the repo's Actions tab if something fails