Module 71: CI/CD

Lesson 3 of 5 · 15–25 minutes

GitHub Actions

🏠The everyday picture

A set of standing instructions for an office assistant: "whenever a parcel arrives, open it, check the contents against the list, and file the receipt". Nobody has to remember to ask.

📘What it really is

# .github/workflows/ci.yml
name: CI
on:
  pull_request:
  push:
    branches: [main]

permissions:
  contents: read

jobs:
  test:
    runs-on: ubuntu-latest
    services:
      postgres:
        image: postgres:17
        env:
          POSTGRES_PASSWORD: ci-only-password
          POSTGRES_DB: crm_test
        ports: ["5432:5432"]
        options: >-
          --health-cmd "pg_isready"
          --health-interval 5s
    env:
      DATABASE_URL: postgresql://postgres:ci-only-password@localhost:5432/crm_test
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 22
          cache: npm
      - run: npm ci
      - run: npm run typecheck
      - run: npm run lint
      - run: npm run migrate
      - run: npm test
      - run: npm run build

🖱️Try it

Add the CI workflow above to your CRM, adjusted to your scripts. Open a pull request and watch it run. Then break a test on purpose in another pull request, see the red cross and read the log to find the failure. Fix it and see it turn green.

✅Quick check

Where should a registry token for a workflow be stored?

Show the answer

In the repository's Actions secrets, used as ${{ secrets.NAME }}, never in the workflow file.

Why does the workflow start a PostgreSQL service?

Show the answer

So integration tests run against a real database, just like production.

← PreviousAutomated builds
ProLearners Assist