持续集成
在 CI 环境中运行 Biome 很容易。查看 以了解哪些编辑器支持 Biome。
¥Running Biome in a CI environment is easy. Check out the following examples for some inspiration.
biome check VS biome ci
Section titled “biome check VS biome ci”Biome 提供两个 CLI 命令来运行所有检查:biome check 和 biome ci,但后者应在 CI(持续集成)环境中使用。
¥Biome offers two CLI commands to run all checks: biome check and biome ci, however the latter should be used in CI (Continuous Integration) environments.
与 check 命令相比,ci 命令:
¥Compared to the check command, the ci command:
-
不提供任何
--write/--fix选项。¥Doesn’t provide any
--write/--fixoption. -
与特定运行器集成更佳。例如,在 GitHub 上运行时,诊断信息会使用 GitHub 注解打印。
¥Integrates better with specific runners. For example, when run on GitHub, the diagnostics are printed using the GitHub annotations.
-
允许控制线程数。
¥Allows controlling the number of threads.
-
启用版本控制系统 (VCS) 集成后,它会使用
--changed标志而不是--staged,因为远程仓库没有 “暂存文件” 的概念。¥When VCS integration is enabled, it uses the
--changedflag instead of--staged, because a remote repository doesn’t have the concept of “staged files”.
随着时间的推移,ci 命令将获得越来越多的功能。
¥With time, the ci command will receive more and more features.
GitHub Actions
Section titled “GitHub Actions”我们提供第一方 GitHub 操作 来在你的运行器中设置 Biome。以下是简单的工作流程可能的外观:
¥We provide a first-party GitHub Action to setup Biome in your runner. Here’s what a simple workflow might look like:
name: Code quality
on: push: pull_request:
jobs: quality: runs-on: ubuntu-latest permissions: contents: read steps: - name: Checkout uses: actions/checkout@v5 with: persist-credentials: false - name: Setup Biome uses: biomejs/setup-biome@v2 with: version: latest - name: Run Biome run: biome ci .如果你的 Biome 配置有外部依赖(例如,扩展了某个包中的配置),则需要在运行 Biome 之前设置 Node.js 并使用你首选的包管理器安装依赖:
¥If your Biome configuration has external dependencies (e.g., extends a config from a package), you’ll need to setup Node.js and install dependencies using your preferred package manager before running Biome:
- name: Setup Node.js uses: actions/setup-node@v4 with: node-version: 22 # or your preferred version cache: "npm" # or 'yarn', 'pnpm'- name: Install dependencies run: npm ci # or yarn install --frozen-lockfile, pnpm install --frozen-lockfile¥Third-party actions
这些是其他社区维护的操作,你可以在运行器中使用:
¥These are actions maintained by other communities, that you use in your runner:
-
reviewdog-action-biome:使用 reviewdog 运行 Biome 并对拉取请求发表评论和提交建议。
¥reviewdog-action-biome: run Biome with reviewdog and make comments and commit suggestions on the pull request.
name: reviewdogon: [pull_request]jobs: biome: name: runner / Biome runs-on: ubuntu-latest permissions: contents: read pull-requests: write steps: - uses: actions/checkout@v5 - uses: mongolyy/reviewdog-action-biome@v1 with: github_token: ${{ secrets.github_token }} reporter: github-pr-reviewGitLab CI
Section titled “GitLab CI”以下是一个配置示例:
¥Below is an example configuration:
# Define pipeline stagesstages: - quality
# Lint job configuration: runs code quality checks using Biomelint: image: name: ghcr.io/biomejs/biome:latest # Use the latest Biome Docker image entrypoint: [""] # This is required for the image to work in GitLab CI stage: quality # Run in the quality stage script: - biome ci --reporter=gitlab --colors=off > /tmp/code-quality.json - cp /tmp/code-quality.json code-quality.json artifacts: reports: codequality: - code-quality.json # Collect the code quality report artifact rules: - if: $CI_COMMIT_BRANCH # Run job for commits on branches - if: $CI_MERGE_REQUEST_ID # Run job for merge requestsBiome v2.1 中文网 - 粤ICP备13048890号