Skip to content

Guides / Write your first config by hand

Write your first config by hand

This guide builds a config for a Node.js project from an empty file. At the end it lints and tests every pull request, and builds on main after the tests pass.

  • The hatchrun CLI. See the Quickstart.
  • A repository with npm run lint, npm test and npm run build, or your own commands in their place.
  1. Terminal window
    mkdir -p .hatchrun
    touch .hatchrun/config.yml

    hatchrun reads only this path. An empty file is valid and runs nothing.

  2. A job is a list of steps that runs on one machine. Add a jobs: section with one job:

    .hatchrun/config.yml
    jobs:
    test:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v5
    - uses: actions/setup-node@v4
    with:
    node-version: 22
    - run: npm ci
    - run: npm test

    runs-on picks the machine. uses: steps run GitHub actions, here to check out the code and install Node. run: steps run shell commands.

  3. A job runs only when a workflow lists it. Add a workflows: section that runs test on pushes to main and on pull requests:

    .hatchrun/config.yml
    jobs:
    test:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v5
    - uses: actions/setup-node@v4
    with:
    node-version: 22
    - run: npm ci
    - run: npm test
    workflows:
    ci:
    on:
    push:
    branches: [main]
    pull_request: {}
    jobs:
    - test

    pull_request: {} means every pull request, with no filters. on: is always a map of events, so on: push does not work here.

  4. Terminal window
    hatchrun validate

    No output means the file is valid. Validate after every step from here on.

  5. Add lint and build. In the workflow, requires makes build wait until lint and test both pass, and branches runs build only on main:

    .hatchrun/config.yml
    jobs:
    lint:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v5
    - run: npm ci
    - run: npm run lint
    test:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v5
    - uses: actions/setup-node@v4
    with:
    node-version: 22
    - run: npm ci
    - run: npm test
    build:
    runs-on: ubuntu-26.04-4core
    steps:
    - uses: actions/checkout@v5
    - run: npm ci
    - run: npm run build
    workflows:
    ci:
    on:
    push:
    branches: [main]
    pull_request: {}
    jobs:
    - lint
    - test
    - build:
    requires: [lint, test]
    branches: [main]

    lint and test start together. build starts when both pass.

  6. branches on a workflow entry matches the event’s ref. For a pull request, that ref is the base branch. A pull request into main therefore runs build too. To build only on pushes, give build its own workflow:

    .hatchrun/config.yml
    jobs:
    lint:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v5
    - run: npm ci
    - run: npm run lint
    test:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v5
    - run: npm ci
    - run: npm test
    build:
    runs-on: ubuntu-26.04-4core
    steps:
    - uses: actions/checkout@v5
    - run: npm ci
    - run: npm run build
    workflows:
    pr:
    on:
    pull_request: {}
    jobs:
    - lint
    - test
    main:
    on:
    push:
    branches: [main]
    jobs:
    - lint
    - test
    - build:
    requires: [lint, test]

    Pull requests run the pr workflow. Pushes to main run the main workflow, which builds after both checks pass.

  7. Terminal window
    git add .hatchrun/config.yml
    git commit -m "ci: add hatchrun config"

Expected result: hatchrun validate prints nothing. Once the GitHub App is installed, a pull request shows the check runs lint and test, and a push to main shows lint, test and build.