GitHub Actions: From First Workflow to Reusable
GitHub Actions in 30 minutes: enough to ship; the reusable pattern is what scales it across an org.
Step 1: First workflow
# .github/workflows/ci.yml
on: [push]
jobs:
test:
runs-on: ubuntu-latest
steps:
- run: echo "hello"
Step 2: Real CI
- Add: checkout, setup-node, npm install, npm test.
- Configure caching for node_modules.
Step 3: Make it reusable
Refactor: workflow_call trigger; inputs for variation.
Move to a shared repo; tag the version.
Step 4: Consume from other repos
jobs:
ci:
uses: org/shared-ci/.github/workflows/ci.yml@v1
with:
node-version: 20
One source of truth; many consumers.
Antipatterns
- Copy-pasted workflows across 50 repos. Drift.
- Pinning to @main. Surprise breakage.
- Reusable workflow as 100% rigid. Inputs allow flexibility.
What to do this week
Three moves. (1) Run the tutorial end-to-end on your own laptop / sandbox. (2) Apply the pattern to one production workload. (3) Document the variations you needed; share with the team.