Skip to content
Latchkey

CI/CD for hapi with GitHub Actions

Run hapi lab tests with coverage and ship the API.

hapi is a configuration-centric Node framework with its own lab test runner and code assertion library. This recipe runs lab with a coverage threshold, then builds and deploys.

What the pipeline does

  • install deps with npm ci
  • lint with eslint
  • run lab with a coverage threshold
  • build the app
  • deploy a Node bundle or container

The workflow

lab -t 90 fails the build if coverage drops below 90 percent. -L runs the linter built into lab.

.github/workflows/ci.yml
name: CI
on:
  push:
    branches: [main]
  pull_request:
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 20
          cache: npm
      - run: npm ci
      - run: npx lab -t 90 -L
      - run: npm run build --if-present
      - uses: actions/upload-artifact@v4
        with:
          name: app
          path: .

Caching and speed

cache: npm covers installs. lab runs tests in parallel by default, so the suite is fast; CI time is dominated by install on small services. For larger services, cheaper managed runners such as Latchkey keep frequent runs inexpensive.

Deploying

Deploy a Docker image to ECS, Cloud Run, Fly.io, or Kubernetes, or run the app directly on a Node host with npm ci --omit=dev and a process manager. hapi servers expose a health route easily, so wire it into your load balancer health checks.

Key takeaways

  • lab -t 90 enforces a coverage threshold in CI.
  • -L runs hapi lab built-in linting.
  • Deploy a container image or a Node bundle.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →