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 Actions runs workflows written in YAML files in
.github/workflows/. A workflow has: - triggers (
on:): a push, a pull request, a schedule, or a manual button; - jobs that run on fresh virtual machines (runners);
-
steps inside each job: ready-made actions (
uses:) or shell commands (run:). -
A CI workflow for your API:
# .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
-
The
services:block starts a real PostgreSQL just for the job, so your integration tests (Module 59) run against a real database. The password is throwaway, used only inside this temporary machine. -
Secrets: real secrets (registry tokens, deploy keys) go in the repository's Settings → Secrets and variables → Actions, used as
${{ secrets.NAME }}. GitHub hides them in logs. Never write them into workflow files. -
Least privilege:
permissions: contents: readgives the workflow only what it needs (more in Module 78). -
Pin actions to a version (
@v4), or for extra safety to a full commit SHA, because an action is someone else's code running with your secrets. -
Results show on every pull request as a green tick or red cross, with logs for each step.
- Public repositories get free Actions minutes; private repositories get a monthly allowance, so check your plan.
🖱️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.
