CI 및 기타 연동 설정
CI 파이프라인에서 Oxfmt를 돌려 포맷 차이 있으면 빌드가 실패하도록 설정하는 것이 좋습니다.
이 페이지에서는 git pre-commit hook 같은 다른 연동도 다룹니다.
CI
GitHub Actions
먼저 package.json에 아직 없다면 fmt:check 스크립트를 추가합니다.
json
{
"scripts": {
"fmt:check": "oxfmt --check"
}
}GitHub Actions 워크플로에 job을 추가합니다.
yaml
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
# 또는 yarn, npm 등
- run: pnpm install --frozen-lockfile
- run: pnpm run fmt:check포맷 문제 자동 수정
PR 전에 Oxfmt를 자주 잊고, pre-commit hook을 쓰지 못하는 경우 autofix.ci로 CI에서 자동 수정 단계를 넣을 수 있습니다.
자세한 내용은 https://autofix.ci/setup를 보고, 해당 GitHub App도 설치해야 합니다.
아래는 사용할 수 있는 GitHub Actions 예시입니다.
yaml
name: autofix.ci # 이 이름을 써야 합니다.
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
# 또는 yarn, npm 등
- run: pnpm install --frozen-lockfile
# 차이가 있으면 autofix.ci가 커밋합니다. 없다면 package.json에 `fmt` 스크립트가 있는지 확인하세요.
- run: pnpm run fmt
# NOTE: 버전 번호 대신 최신 SHA를 쓰는 것을 강력히 권장합니다. (https://autofix.ci/setup 참고.)
- uses: autofix-ci/action@1.3.2GitLab CI
GitLab CI를 쓰면 포맷 검사를 파이프라인에 넣을 수 있습니다.
먼저 package.json에 fmt:check를 추가합니다.
json
{
"scripts": {
"fmt:check": "oxfmt --check"
}
}.gitlab-ci.yml에 job을 추가합니다.
yml
oxfmt:
image: node:lts
stage: test
before_script:
# 또는 pnpm, yarn 등
- npm install
script:
- npm run fmt:check패키지 매니저 캐시를 넣어 설치를 빠르게 할 수도 있습니다.
Pre-commit hook
스테이징된 파일만 자동 포맷하려면 oxfmt --no-error-on-unmatched-pattern을 사용합니다. 지원 파일을 모두 포맷하고, 패턴에 맞는 파일이 없을 때 에러 내지 않습니다(예: Ruby만 스테이징된 경우).
파일을 쓰지 않고 검증만 할 때는 --check를 씁니다.
lint-staged를 쓴다면 package.json에 다음을 추가합니다.
json
{
"lint-staged": {
"*": "oxfmt --no-error-on-unmatched-pattern"
}
}의존성 설치 시 hook을 자동으로 깔려면 husky도 함께 쓸 수 있습니다.