Cheat sheet · Systems and cloud
CI/CD and GitHub Actions cheat sheet
Write a GitHub Actions workflow, keep secrets safe, and choose a deployment strategy.
- Sections
- 6
- Items
- 26
- Area
- Systems and cloud
- Download
- PNG, PDF
Cheat sheet
CI/CD and GitHub Actions
Write a GitHub Actions workflow, keep secrets safe, and choose a deployment strategy.
Workflow file
.github/workflows/ci.yml- Where the workflow lives
name: CI- A label for the workflow
on: [push, pull_request]- When it runs
jobs: build: runs-on: ubuntu-latest- A job and the machine it runs on
steps:- The list of steps in the job
Common steps
- uses: actions/checkout@v4- Get your code
- uses: actions/setup-node@v4 with: { node-version: 22 }- Install Node.js
- run: npm ci- Run a command
- run: npm test- Run the tests
- uses: actions/upload-artifact@v4- Keep a file from the run
More controls
needs: build- Run this job after another one
if: github.ref == 'refs/heads/main'- Run only on main
strategy: { matrix: { node: [20, 22] } }- Repeat a job for several versions
cache: npm- Reuse downloaded packages to go faster
env: { NAME: value }- Set a variable
Secrets
${{ secrets.API_KEY }}- Use a secret saved in the repository settings
permissions: { contents: read }- Give the job only the access it needs
Pipeline stages
Build- Compile or bundle the app
Test- Unit, integration and lint checks
Scan- Check packages and code for known problems
Deploy- Send the build to an environment
Deployment strategies
Rolling- Replace instances a few at a time
Blue-green- Run a new copy beside the old one, then switch traffic at once
Canary- Send a small share of users to the new version first
Feature flag- Ship the code turned off, turn it on later
Rollback- Return to the last good version quickly
Remember
- Keep the pipeline under ten minutes. Slow pipelines get skipped.
- Never print a secret in a log. Use the secrets store and give each job the least access.
Learn it properly
A cheat sheet helps you remember. These lessons explain the ideas step by step, with examples.