Skip to main content

Lesson 5 of 8

CI Pipeline & Type-Safe Deployment

A production TypeScript CI pipeline enforces type safety, code quality, and test coverage before every merge. The pipeline runs: type check → lint → format check → tests → build. Only then does deployment proceed. This section walks through the complete pipeline and production deployment setup.

11 minBy Priygop Editorial TeamUpdated 2026Peer Reviewed & Verified

CI Pipeline - GitHub Actions for TypeScript

CI Pipeline - GitHub Actions for TypeScript
# .github/workflows/ci.yml ─────────────────────────────────────
# name: CI
# on: [push, pull_request]
#
# jobs:
#   quality:
#     runs-on: ubuntu-latest
#     steps:
#       - uses: actions/checkout@v4
#
#       - name: Setup Node.js
#         uses: actions/setup-node@v4
#         with:
#           node-version: 20
#           cache: npm
#
#       - name: Install dependencies
#         run: npm ci
#
#       - name: Type check (all packages)
#         run: npm run type-check --workspaces
#         # Runs: tsc --noEmit in each package
#         # ❌ BLOCKS merge on ANY type error
#
#       - name: Lint
#         run: npm run lint --workspaces
#         # Runs: eslint src --ext .ts,.tsx
#         # ❌ BLOCKS merge on no-floating-promises, no-explicit-any, etc.
#
#       - name: Format check
#         run: npm run format:check --workspaces
#         # Runs: prettier --check
#         # ❌ BLOCKS merge on unformatted code
#
#       - name: Test
#         run: npm run test:ci --workspaces
#         # Runs: jest --ci --coverage --forceExit
#
#       - name: Upload coverage
#         uses: codecov/codecov-action@v4
#
#       - name: Build
#         run: npm run build --workspaces
#         # Production build - catches any bundler issues

# ── Deployment - Docker + esbuild ────────────────────────────
# FROM node:20-alpine AS builder
# WORKDIR /app
# COPY package*.json ./
# RUN npm ci
# COPY . .
# RUN npm run build --workspace=packages/server
# # Output: dist/server/index.js (bundled, no TS)
#
# FROM node:20-alpine AS runner
# WORKDIR /app
# COPY --from=builder /app/dist/server ./dist
# COPY --from=builder /app/packages/server/package.json .
# RUN npm install --production
# CMD ["node", "dist/index.js"]

// ── Health check endpoint - deployment readiness ─────────────
// src/server/routes/health.ts
import { Router }  from "express";
import { config }  from "@/config/env";

export const healthRouter: Router = Router();

healthRouter.get("/", (_req, res) => {
  res.json({
    status:   "ok",
    env:      config.NODE_ENV,
    version:  process.env.npm_package_version ?? "0.0.0",
    uptime:   Math.floor(process.uptime()),
    timestamp: new Date().toISOString(),
  });
});

healthRouter.get("/ready", async (_req, res) => {
  try {
    await db.query("SELECT 1");   // DB connectivity check
    res.json({ status: "ready" });
  } catch {
    res.status(503).json({ status: "not ready", reason: "Database unavailable" });
  }
});

Common Mistakes

  • Running tests without `--forceExit` in CI - Jest sometimes keeps open handles (HTTP servers, DB connections) in tests. `--forceExit` ensures the CI job doesn't hang indefinitely.
  • Building without running type-check first - a Vite/esbuild build completes even with type errors. Always run `tsc --noEmit` before `vite build` in CI to catch type errors before deployment.
  • Not using `npm ci` in CI (using `npm install` instead) - `npm ci` installs exactly what's in `package-lock.json` for reproducibility. `npm install` may update the lockfile, causing different dependency versions in CI vs local.

Tip

Tip

Practice CI Pipeline TypeSafe Deployment in small, isolated examples before integrating into larger projects. Breaking concepts into small experiments builds genuine understanding faster than reading alone.

Diagram
Loading diagram…

Visual architecture and concepts for CI Pipeline & Type-Safe Deployment

Practice Task

Note

Practice Task - (1) Write a working example of CI Pipeline TypeSafe Deployment from scratch without looking at notes. (2) Modify it to handle an edge case (empty input, null value, or error state). (3) Share your solution in the Priygop community for feedback.

Quick Quiz

Common Mistake

Warning

A common mistake with CI Pipeline TypeSafe Deployment is skipping edge case testing - empty inputs, null values, and unexpected data types. Always validate boundary conditions to write robust, production-ready typescript code.

Key Takeaways

  • A production TypeScript CI pipeline enforces type safety, code quality, and test coverage before every merge.
  • Running tests without `--forceExit` in CI - Jest sometimes keeps open handles (HTTP servers, DB connections) in tests. `--forceExit` ensures the CI job doesn't hang indefinitely.
  • Building without running type-check first - a Vite/esbuild build completes even with type errors. Always run `tsc --noEmit` before `vite build` in CI to catch type errors before deployment.
  • Not using `npm ci` in CI (using `npm install` instead) - `npm ci` installs exactly what's in `package-lock.json` for reproducibility. `npm install` may update the lockfile, causing different dependency versions in CI vs local.

Hands-on Practice Tools for this Course

Test what you learn using these free in-browser developer utilities (no signup required).

All 40+ Tools

Topics in This Module

0/8 done