CI/CD with GitHub Actions

Run lint, type checks, tests and builds on every pull request, and deploy automatically when main is green.

Intermediate · about 5 hours · difficulty 3/5

Learn first: Git and GitHub, API Integration Tests with a Real Database, Environments, Config and Secrets

Continuous integration means every push is checked automatically. Continuous delivery means a green main branch can go to production without manual steps. Together they let small teams ship daily without fear.

A typical pipeline

  1. Install dependencies with a cached npm ci.
  2. Lint and type-check (tsc --noEmit).
  3. Run unit and integration tests, with PostgreSQL as a service container.
  4. Build the app.
  5. On main only: apply migrations and deploy (or let Vercel or Render deploy on push once checks pass).

GitHub Actions basics

  • Workflows live in .github/workflows as YAML files.
  • Triggers: push, pull_request, schedule, manual dispatch.
  • Jobs run on fresh runners; steps run commands or reusable actions.
  • Secrets are stored in repository settings and injected as environment variables.
  • Branch protection requires checks to pass before merging.

Keep it fast

Cache dependencies, run independent jobs in parallel, and keep slow E2E tests in a separate job. A pipeline that takes 20 minutes gets ignored.

Pitfalls

  • Printing secrets in logs.
  • Flaky tests that everyone reruns until green, which hides real failures.
  • Deploying from a laptop instead of from CI.

You are ready to move on when every pull request on your project runs lint, type checks, tests against PostgreSQL and a build, and main deploys automatically only when all checks pass.

Key concepts

  • Workflows, jobs and steps
  • Triggers: push and pull_request
  • Dependency caching
  • Service containers for PostgreSQL
  • Secrets in CI
  • Branch protection
  • Automated deploys and migrations
  • Dependabot

Mini project

Create a GitHub Actions workflow for your portal that caches dependencies, lints, type-checks, runs tests against a PostgreSQL service container, builds, and blocks merges to main unless all checks pass.

Check yourself

Why run tests against a real PostgreSQL service in CI instead of mocking the database?

Free resources