Skip to content
jshacks.dev
Tooling

Add a lint and test workflow to GitHub Actions

Run lint, type check and tests as parallel jobs in GitHub Actions, and cancel older runs on the same branch when a new commit arrives.

1 min read
Summarize in AI

Separate jobs run side by side, so one failure does not hide the others, and the wall-clock time is the slowest job, not the sum.

.github/workflows/ci.ymlYAML
name: CI
on:
  push:
    branches: [main]
  pull_request:

concurrency:
  group: ci-${{ github.ref }}
  cancel-in-progress: true

jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with: { node-version: 24, cache: npm }
      - run: npm ci
      - run: npm run lint
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with: { node-version: 24, cache: npm }
      - run: npm ci
      - run: npm test

The concurrency block gives runs on the same ref one group, and cancel-in-progress stops the older run when a newer commit lands. That saves minutes on a branch you push to often. See the concurrency docs.

Each job installs dependencies again, which costs a few seconds with a cache. Do not cancel runs on main, where you want every commit checked, so scope the cancel to pull requests if that matters.

Also inTesting
Share

More snippets

Testing

Group tests with describe in node test

Group related tests with describe and it from node:test, nest suites, and run setup with beforeEach, all without installing a framework.

1 min read
Tooling

Create a Vite project from a template

Create a Vite project from a template with npm create vite, choose the vanilla-ts or react-ts template and see which files it generates.

1 min read

Get new posts by email

We send one email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.