CI/CD turns 'works on my machine' into 'tested and deployed automatically'. GitHub Actions builds it right into your repo — every push runs your pipeline. Here's a production-ready workflow.
A Test-and-Build Pipeline
name: CI
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with: { node-version: 20, cache: npm }
- run: npm ci
- run: npm run lint
- run: npm test
- run: npm run buildDeploy Only on main
deploy:
needs: test
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: ./deploy.sh
env:
DEPLOY_TOKEN: ${{ secrets.DEPLOY_TOKEN }}Best Practices
- Cache dependencies to keep pipelines fast.
- Store credentials in repository Secrets, never in the YAML.
- Require the test job to pass before merging via branch protection.
Solution
Start with just lint + test on pull requests. Add deployment once your test suite is trustworthy — a fast, green pipeline is what makes teams ship confidently.
