Setup CI and other integrations
You can - and should - set up your CI pipeline to run Oxfmt and fail the build on formatting differences.
This page also covers other integrations you may want to include, like git pre-commit hooks.
CI
GitHub Actions
First, add a fmt:check script to your package.json if you don't have one already:
json
{
"scripts": {
"fmt:check": "oxfmt --check"
}
}
``````yaml [.github/workflows/ci.yml]
name: CI
on:
pull_request:
push:
branches: [main]
permissions: {}
jobs:
format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v6
with:
node-version: lts/*
cache: pnpm
# Or yarn, npm, etc.
- run: pnpm install --frozen-lockfile
- run: pnpm run fmt:check
``````yaml [.github/workflows/autofix.yml]
name: autofix.ci # needs to use this name
on:
pull_request:
push:
branches: ["main"]
permissions:
contents: read
jobs:
autofix:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v6
with:
node-version: lts/*
cache: pnpm
# Or yarn, npm, etc.
- run: pnpm install --frozen-lockfile
# Run oxfmt to write changes, autofix.ci will commit them if there are any differences.
# Be sure to add a `fmt` script to your `package.json` if you haven't already.
- run: pnpm run fmt
# NOTE: It is strongly recommended to use the latest SHA hash for this action instead of the version number. (See https://autofix.ci/setup for more details.)
- uses: autofix-ci/action@1.3.2
``````json [package.json]
{
"scripts": {
"fmt:check": "oxfmt --check"
}
}
``````yml [.gitlab-ci.yml]
oxfmt:
image: node:lts
stage: test
before_script:
# Or pnpm, yarn, etc.
- npm install
script:
- npm run fmt:check
``````json [package.json]
{
"lint-staged": {
"*": "oxfmt --no-error-on-unmatched-pattern"
}
}