Advanced GitHub Actions
Course 2, Chapter 8 covered a single straightforward test workflow. Real projects usually need more: testing across multiple versions at once, using credentials safely, avoiding redundant work on every run, and — the natural endpoint — automatically deploying when everything passes.
Matrix Builds — Testing Multiple Configurations at Once
A matrix runs the same job multiple times with different variable combinations — typically used to test against several language versions or operating systems simultaneously, in parallel, rather than one at a time.
This single definition produces three separate, parallel job runs:
os: [ubuntu-latest, windows-latest, macos-latest] alongside node-version) produces every combination automatically — 3 Node versions × 3 operating systems = 9 parallel jobs from a few lines of YAML.
Secrets — Using Credentials Safely in CI
Course 1, Chapter 6 established that secrets never belong in committed code. Actions workflows often genuinely need credentials (a deploy token, an API key for a test run) — GitHub Secrets is the answer: encrypted values stored at the repo or organisation level, injected into workflows at runtime without ever appearing in logs or the YAML file itself.
Set up under Settings → Secrets and variables → Actions → New repository secret. The actual value is never visible again after saving, even to repo admins — only usable inside workflow runs.
Caching — Avoiding Redundant Work
Every job starts on a completely fresh virtual machine (Course 2, Chapter 8) — meaning npm install re-downloads every dependency, every single run, unless you cache them.
The cache: 'npm' option (built directly into setup-node) keys the cache to your lockfile's hash — if package-lock.json hasn't changed since the last run, dependencies restore from cache almost instantly instead of re-downloading.
A Complete Deployment Pipeline
Bringing it together — test, then deploy only if tests pass, only on the main branch:
uses: configuration replaces a hand-written deploy script entirely, and stays maintained as the platform's own deployment process changes.
Reusable Workflows — Avoiding Duplication Across Repos
For teams running near-identical CI across several repositories, a workflow can call another workflow as a reusable building block, rather than copy-pasting the same YAML everywhere.
Chapter 5 Quick Reference
- strategy: matrix: runs the same job across multiple parallel variable combinations
- secrets.<NAME> — encrypted credentials, injected at runtime, masked in logs (but not infallibly — never deliberately print them)
- cache: 'npm' (or equivalent) — skips redundant dependency downloads, keyed to your lockfile hash
- needs: — makes one job wait for another to succeed first, the basis of a test-then-deploy pipeline
- Branch-scoped triggers — restrict deployment-related jobs to main, keeping feature branches test-only
- Check the Marketplace first for deployment to major hosting providers, before hand-writing a deploy script
- Reusable workflows — call a shared workflow definition instead of duplicating YAML across repos
- Next chapter: branch protection, CODEOWNERS, required reviews, and signed commits — securing a serious repo