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.
Prerequisites
Section titled “Prerequisites”- The
hatchrunCLI. See the Quickstart. - A repository with
npm run lint,npm testandnpm run build, or your own commands in their place.
-
Create the file
Section titled “Create the file”Terminal window mkdir -p .hatchruntouch .hatchrun/config.ymlhatchrun reads only this path. An empty file is valid and runs nothing.
-
Add a job
Section titled “Add a job”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-lateststeps:- uses: actions/checkout@v5- uses: actions/setup-node@v4with:node-version: 22- run: npm ci- run: npm testruns-onpicks the machine.uses:steps run GitHub actions, here to check out the code and install Node.run:steps run shell commands. -
Add a workflow
Section titled “Add a workflow”A job runs only when a workflow lists it. Add a
workflows:section that runsteston pushes tomainand on pull requests:.hatchrun/config.yml jobs:test:runs-on: ubuntu-lateststeps:- uses: actions/checkout@v5- uses: actions/setup-node@v4with:node-version: 22- run: npm ci- run: npm testworkflows:ci:on:push:branches: [main]pull_request: {}jobs:- testpull_request: {}means every pull request, with no filters.on:is always a map of events, soon: pushdoes not work here. -
Validate
Section titled “Validate”Terminal window hatchrun validateNo output means the file is valid. Validate after every step from here on.
-
Add a second job and order the jobs
Section titled “Add a second job and order the jobs”Add
lintandbuild. In the workflow,requiresmakesbuildwait untillintandtestboth pass, andbranchesrunsbuildonly onmain:.hatchrun/config.yml jobs:lint:runs-on: ubuntu-lateststeps:- uses: actions/checkout@v5- run: npm ci- run: npm run linttest:runs-on: ubuntu-lateststeps:- uses: actions/checkout@v5- uses: actions/setup-node@v4with:node-version: 22- run: npm ci- run: npm testbuild:runs-on: ubuntu-26.04-4coresteps:- uses: actions/checkout@v5- run: npm ci- run: npm run buildworkflows:ci:on:push:branches: [main]pull_request: {}jobs:- lint- test- build:requires: [lint, test]branches: [main]lintandteststart together.buildstarts when both pass. -
Check what runs where
Section titled “Check what runs where”brancheson a workflow entry matches the event’s ref. For a pull request, that ref is the base branch. A pull request intomaintherefore runsbuildtoo. To build only on pushes, givebuildits own workflow:.hatchrun/config.yml jobs:lint:runs-on: ubuntu-lateststeps:- uses: actions/checkout@v5- run: npm ci- run: npm run linttest:runs-on: ubuntu-lateststeps:- uses: actions/checkout@v5- run: npm ci- run: npm testbuild:runs-on: ubuntu-26.04-4coresteps:- uses: actions/checkout@v5- run: npm ci- run: npm run buildworkflows:pr:on:pull_request: {}jobs:- lint- testmain:on:push:branches: [main]jobs:- lint- test- build:requires: [lint, test]Pull requests run the
prworkflow. Pushes tomainrun themainworkflow, which builds after both checks pass. -
Commit the file
Section titled “Commit the file”Terminal window git add .hatchrun/config.ymlgit 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.
Troubleshooting
Section titled “Troubleshooting”Next steps
Section titled “Next steps”- Reuse config with commands, executors and parameters removes the repeated checkout and install steps.
- Run jobs in order with requires and approvals