A · FoundationsBeginner55 min read
3. First GitHub Actions workflow
CI/CD Pipelines · 48 pages source format
YAML workflow: on trigger, jobs, steps, runs-on. Install, test, fail loud on red.
What you'll learn
- Workflow structure
- Triggers
- Jobs and steps
- Action marketplace
Hello workflow
on: push, jobs.test, runs-on: ubuntu-latest, steps: checkout, setup, run tests.
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "20"
- run: npm ci
- run: npm testDo this now
Add .github/workflows/ci.yml. Push. See green check on commit.
Clear?
pull_request trigger
Same workflow on PR shows checks before merge. This is the daily loop.
Do this now
Open PR with trivial change. Confirm check runs on PR.
Clear?
Read workflow logs
Expand steps, find failure line, re-run failed jobs. Triage skill #1.
Do this now
Break a test intentionally. Read log. Fix. Re-run.
Clear?
Action versioning
Pin major version: actions/checkout@v4. Avoid @main for supply chain stability.
Do this now
Audit workflow — all actions use version tags.
Clear?