---
name: configure-github-actions-ci
description: Configures a GitHub Actions workflow that installs dependencies with caching, then runs lint, type-check, tests and build on every push and pull request. Use when the user wants CI, automated tests on PRs, a build pipeline, GitHub workflows, or checks before merging.
license: CC-BY-4.0
metadata:
  category: deployment
  tags: "github-actions,ci,nodejs,testing"
  author: johnny-bravo
  version: "1.0"
  updated: "2026-10-30"
  status: published
---

# Configure GitHub Actions CI

## When to use
- A repo has tests or a build but nothing runs them automatically.

## Steps
1. Create `.github/workflows/ci.yml`:
   ```yaml
   name: CI
   on: [push, pull_request]
   concurrency: { group: ci-${{ github.ref }}, cancel-in-progress: true }
   jobs:
     test:
       runs-on: ubuntu-latest
       steps:
         - uses: actions/checkout@v4
         - uses: actions/setup-node@v4
           with: { node-version: 22, cache: npm }
         - run: npm ci
         - run: npm run lint --if-present
         - run: npx tsc --noEmit --if-present || true
         - run: npm test --if-present
         - run: npm run build --if-present
   ```
2. Add secrets in Settings > Secrets and variables > Actions; reference as `${{ secrets.NAME }}`. Never echo them.
3. Protect `main`: Settings > Branches > require the `CI / test` check to pass before merging.
4. Push a branch, open a PR, confirm the check goes green.

## Gotchas
- `npm ci` needs a committed `package-lock.json`.
- Pull requests from forks do not get secrets; keep tests runnable without them.
- Pin action major versions (`@v4`); do not use `@main`.

## Example prompt
"Run my tests automatically on every PR."
