diff --git a/.github/workflows/lint-caller.yml b/.github/workflows/lint-caller.yml index a4e9e41a..4fee7390 100644 --- a/.github/workflows/lint-caller.yml +++ b/.github/workflows/lint-caller.yml @@ -28,6 +28,9 @@ jobs: # renovate: datasource=github-releases depName=golangci/golangci-lint # golangci-lint-version: "v2.12.2" lint-config-dir: config-sync/files + # config-sync/templates holds a root biome.json for other repositories, + # which Biome rejects as a second root config in this one. + lint-biome-exclude: config-sync/templates/* # This repository has no inline scripts (#537), so it keeps it that way. lint-inline-scripts-blocking: true @@ -46,6 +49,7 @@ jobs: # renovate: datasource=github-releases depName=jdx/mise mise-version: "2026.10.19" lint-config-dir: config-sync/files + lint-biome-exclude: config-sync/templates/* # See the job above. lint-job-mode: single lint-inline-scripts-blocking: true upload-sarif: false diff --git a/.github/workflows/lint-include.yml b/.github/workflows/lint-include.yml index 55ed377d..9b0a69b1 100644 --- a/.github/workflows/lint-include.yml +++ b/.github/workflows/lint-include.yml @@ -106,6 +106,24 @@ on: required: false type: boolean default: false + lint-biome: + description: "Run Biome (JavaScript, TypeScript, JSON and CSS linting and formatting) when the repository has such + files — uploads SARIF" + required: false + type: boolean + default: false + lint-biome-exclude: + description: "Glob pattern for paths to exclude from Biome (a bash pattern on the repository-relative path; * also + matches /)" + required: false + type: string + default: "" + lint-biome-with-eslint: + description: "Run Biome in repositories that configure ESLint too (eslint.config.* or .eslintrc*), where it steps + aside by default" + required: false + type: boolean + default: false lint-config-drift: description: "Check local config files match central DevSecNinja/.github repo" required: false @@ -122,7 +140,7 @@ on: type: boolean default: false upload-sarif: - description: "Upload checkov/trivy/zizmor/ruff results to GitHub code scanning (requires GitHub Advanced Security). + description: "Upload checkov/trivy/zizmor/ruff/biome results to GitHub code scanning (requires GitHub Advanced Security). Set false for private repos without GHAS to gate on exit codes with console output instead." required: false type: boolean @@ -171,6 +189,9 @@ jobs: lint-trivy: ${{ inputs.lint-trivy }} lint-zizmor: ${{ inputs.lint-zizmor }} lint-ruff: ${{ inputs.lint-ruff }} + lint-biome: ${{ inputs.lint-biome }} + lint-biome-exclude: ${{ inputs.lint-biome-exclude }} + lint-biome-with-eslint: ${{ inputs.lint-biome-with-eslint }} lint-config-drift: ${{ inputs.lint-config-drift }} lint-inline-scripts: ${{ inputs.lint-inline-scripts }} lint-inline-scripts-blocking: ${{ inputs.lint-inline-scripts-blocking }} diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 69012017..9a24123f 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -98,6 +98,24 @@ on: required: false type: boolean default: true + lint-biome: + description: "Run Biome (JavaScript, TypeScript, JSON and CSS linting and formatting) when the repository has such + files — uploads SARIF" + required: false + type: boolean + default: true + lint-biome-exclude: + description: "Glob pattern for paths to exclude from Biome (a bash pattern on the repository-relative path; * also + matches /)" + required: false + type: string + default: "" + lint-biome-with-eslint: + description: "Run Biome in repositories that configure ESLint too (eslint.config.* or .eslintrc*), where it steps + aside by default" + required: false + type: boolean + default: false lint-config-drift: description: "Check local config files match central DevSecNinja/.github repo" required: false @@ -117,7 +135,7 @@ on: type: boolean default: false upload-sarif: - description: "Upload checkov/trivy/zizmor/ruff results to GitHub code scanning (requires GitHub Advanced Security). + description: "Upload checkov/trivy/zizmor/ruff/biome results to GitHub code scanning (requires GitHub Advanced Security). Set false for private repos without GHAS to gate on exit codes with console output instead." required: false type: boolean @@ -740,6 +758,70 @@ jobs: sarif_file: ${{ runner.temp }}/ruff.sarif category: ruff + biome: + name: biome + if: ${{ inputs.lint-biome && (inputs.lint-job-mode == 'parallel' || (inputs.lint-job-mode == 'auto' && !github.event.repository.private)) + }} + continue-on-error: ${{ ! inputs.lint-fail-on-error }} + runs-on: ubuntu-24.04 + timeout-minutes: 10 + permissions: + contents: read + security-events: write + steps: + - name: Checkout lint scripts + # The linter scripts ship with this reusable workflow: fetch them from + # the same commit of DevSecNinja/.github that the caller pinned. + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + repository: ${{ job.workflow_repository }} + ref: ${{ job.workflow_sha }} + path: .devsecninja-lint + sparse-checkout: |- + scripts/lint/ + scripts/lint-inline-scripts.py + sparse-checkout-cone-mode: false + persist-credentials: false + + - name: Move lint scripts out of the workspace + # Outside the workspace the caller's linters don't scan them, and the + # code checkout doesn't delete them. + run: mv .devsecninja-lint "${RUNNER_TEMP}/devsecninja-lint" + + - name: Checkout code + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + + - name: Find JavaScript, TypeScript, JSON and CSS files + # Repositories without them skip the mise install and Biome. + id: web-files + env: + STEP_ASIDE_FOR: ${{ !inputs.lint-biome-with-eslint && 'eslint' || '' }} + run: bash "${RUNNER_TEMP}/devsecninja-lint/scripts/lint/detect-language.sh" web + + - name: Install mise + if: ${{ steps.web-files.outputs.found == 'true' }} + uses: jdx/mise-action@c2a87611a18de5b3828c5652fe268e992400cb5c # v4.3.0 + with: + install: true + version: ${{ inputs.mise-version }} + + - name: Run Biome + id: biome + if: ${{ steps.web-files.outputs.found == 'true' }} + env: + UPLOAD_SARIF: ${{ inputs.upload-sarif }} + EXCLUDE_PATTERN: ${{ inputs.lint-biome-exclude }} + run: bash "${RUNNER_TEMP}/devsecninja-lint/scripts/lint/biome.sh" + + - name: Upload SARIF report + if: ${{ !cancelled() && steps.biome.outputs.sarif == 'true' }} + uses: github/codeql-action/upload-sarif@9b3254085494b55a0f7c4c2b3d2d52cc712ce370 # v4.39.1 + with: + sarif_file: ${{ runner.temp }}/biome.sarif + category: biome + config-drift: name: config drift if: ${{ inputs.lint-config-drift && (inputs.lint-job-mode == 'parallel' || (inputs.lint-job-mode == 'auto' && !github.event.repository.private)) @@ -870,11 +952,19 @@ jobs: if: ${{ inputs.lint-ruff }} run: bash "${RUNNER_TEMP}/devsecninja-lint/scripts/lint/detect-language.sh" python + - name: Find JavaScript, TypeScript, JSON and CSS files + # Repositories without them skip Biome (and its mise install). + id: web-files + if: ${{ inputs.lint-biome }} + env: + STEP_ASIDE_FOR: ${{ !inputs.lint-biome-with-eslint && 'eslint' || '' }} + run: bash "${RUNNER_TEMP}/devsecninja-lint/scripts/lint/detect-language.sh" web + - name: Install mise if: >- ${{ inputs.lint-dprint || inputs.lint-yamlfmt || inputs.lint-yamllint || inputs.lint-actionlint || inputs.lint-gitleaks || inputs.lint-shellcheck || inputs.lint-shfmt || inputs.lint-checkov || inputs.lint-trivy || inputs.lint-zizmor - || steps.python-files.outputs.found == 'true' }} + || steps.python-files.outputs.found == 'true' || steps.web-files.outputs.found == 'true' }} uses: jdx/mise-action@c2a87611a18de5b3828c5652fe268e992400cb5c # v4.3.0 with: install: true @@ -1075,6 +1165,24 @@ jobs: sarif_file: ${{ runner.temp }}/ruff.sarif category: ruff + - name: Run Biome + id: biome + if: ${{ steps.web-files.outputs.found == 'true' }} + continue-on-error: true + env: + UPLOAD_SARIF: ${{ inputs.upload-sarif }} + EXCLUDE_PATTERN: ${{ inputs.lint-biome-exclude }} + run: bash "${RUNNER_TEMP}/devsecninja-lint/scripts/lint/biome.sh" + + - name: Upload Biome SARIF report + id: biome-sarif + if: ${{ !cancelled() && steps.biome.outputs.sarif == 'true' }} + continue-on-error: true + uses: github/codeql-action/upload-sarif@9b3254085494b55a0f7c4c2b3d2d52cc712ce370 # v4.39.1 + with: + sarif_file: ${{ runner.temp }}/biome.sarif + category: biome + - name: Check config drift against central repo id: config-drift if: ${{ inputs.lint-config-drift }} diff --git a/.mise.toml b/.mise.toml index 98df7a9c..61060d4a 100644 --- a/.mise.toml +++ b/.mise.toml @@ -3,6 +3,7 @@ min_version = "2026.10.19" [tools] actionlint = "1.7.12" +biome = "2.6.8" cocogitto = "7.0.0" dprint = "0.64.3" gitleaks = "8.30.1" diff --git a/.renovate/customManagers.json5 b/.renovate/customManagers.json5 index 77f032d0..c6fc60f4 100644 --- a/.renovate/customManagers.json5 +++ b/.renovate/customManagers.json5 @@ -1,5 +1,7 @@ { $schema: "https://docs.renovatebot.com/renovate-schema.json", + // Keeps the $schema version of biome.json(c) in step with Biome updates. + extends: ["customManagers:biomeVersions"], customManagers: [ { customType: "regex", diff --git a/biome.json b/biome.json new file mode 100644 index 00000000..5775026c --- /dev/null +++ b/biome.json @@ -0,0 +1,40 @@ +{ + "$schema": "https://biomejs.dev/schemas/2.6.8/schema.json", + "vcs": { + "enabled": true, + "clientKind": "git", + "useIgnoreFile": true + }, + "files": { + "includes": [ + "**/*.{js,mjs,cjs,jsx,ts,mts,cts,tsx,json,jsonc,css}", + "!**/node_modules", + "!apm_modules", + "!.agents", + "!.claude", + "!.cursor", + "!.gemini", + "!.github/agents", + "!.github/chatmodes", + "!.github/instructions", + "!.github/prompts", + "!.github/skills", + "!.kiro", + "!.opencode", + "!.specify", + "!.venv*", + "!.windsurf", + "!!config-sync/templates" + ] + }, + "formatter": { + "indentStyle": "space", + "indentWidth": 2, + "lineWidth": 120 + }, + "linter": { + "rules": { + "preset": "recommended" + } + } +} diff --git a/config-sync/files/dprint.json b/config-sync/files/dprint.json index 92f65210..7925ef4a 100644 --- a/config-sync/files/dprint.json +++ b/config-sync/files/dprint.json @@ -21,7 +21,5 @@ ".specify/**", ".venv*/**" ], - "plugins": [ - "https://plugins.dprint.dev/markdown-0.21.1.wasm" - ] + "plugins": ["https://plugins.dprint.dev/markdown-0.21.1.wasm"] } diff --git a/config-sync/templates/.mise.toml b/config-sync/templates/.mise.toml index 3c179e30..210bd257 100644 --- a/config-sync/templates/.mise.toml +++ b/config-sync/templates/.mise.toml @@ -4,6 +4,7 @@ min_version = "2026.10.19" [tools] actionlint = "1.7.12" +biome = "2.6.8" dprint = "0.64.3" gitleaks = "8.30.1" lefthook = "2.2.2" diff --git a/config-sync/templates/README.md b/config-sync/templates/README.md index 9f81df33..e597551b 100644 --- a/config-sync/templates/README.md +++ b/config-sync/templates/README.md @@ -104,3 +104,17 @@ same generated and vendored paths as the shared `dprint.json`. Config-sync doesn't add it to a repo that configures ruff in `.ruff.toml` or in `[tool.ruff]` of `pyproject.toml`, where `ruff.toml` would take precedence and replace those settings. + +## biome.json + +Config for Biome, which the shared Lint workflow runs when the repo has +JavaScript, TypeScript, JSON or CSS files (`lint-biome`). It limits Biome to +those files, leaving Markdown and YAML to dprint and yamlfmt, indents with two +spaces, wraps at 120 columns, enables the recommended lint rules, respects +`.gitignore` and skips the same generated and vendored paths as the shared +`dprint.json`. Biome's other defaults (double quotes, semicolons) apply; change +them in the repo's copy. JSON allows no comments, so this note replaces the +usual template header. Config-sync doesn't add it to a repo that has +`biome.jsonc`. The `customManagers:biomeVersions` Renovate preset, part of the +shared Renovate config, keeps its `$schema` version in step with the pinned +Biome. diff --git a/config-sync/templates/biome.json b/config-sync/templates/biome.json new file mode 100644 index 00000000..9c8b33e2 --- /dev/null +++ b/config-sync/templates/biome.json @@ -0,0 +1,39 @@ +{ + "$schema": "https://biomejs.dev/schemas/2.6.8/schema.json", + "vcs": { + "enabled": true, + "clientKind": "git", + "useIgnoreFile": true + }, + "files": { + "includes": [ + "**/*.{js,mjs,cjs,jsx,ts,mts,cts,tsx,json,jsonc,css}", + "!**/node_modules", + "!apm_modules", + "!.agents", + "!.claude", + "!.cursor", + "!.gemini", + "!.github/agents", + "!.github/chatmodes", + "!.github/instructions", + "!.github/prompts", + "!.github/skills", + "!.kiro", + "!.opencode", + "!.specify", + "!.venv*", + "!.windsurf" + ] + }, + "formatter": { + "indentStyle": "space", + "indentWidth": 2, + "lineWidth": 120 + }, + "linter": { + "rules": { + "preset": "recommended" + } + } +} diff --git a/docs/architecture.md b/docs/architecture.md index ac5f0245..77353210 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -74,7 +74,7 @@ workflow, so it calls `scripts/apm-materialize/` from its own checkout. ### Lint (`lint.yml`) -Runs up to fourteen linters. By default, linter failures are reported without +Runs up to fifteen linters. By default, linter failures are reported without failing the workflow; set `lint-fail-on-error` to `true` to make lint failures fail the workflow. Toggle individual linters on/off with boolean inputs; all linter toggles default to `true`. @@ -187,6 +187,20 @@ APM-deployed agent files, `node_modules`, `.venv*`). [`ruff.toml` template](../config-sync/templates/ruff.toml) is a starting point. Findings are annotated on the PR, and with `upload-sarif` they also go to code scanning (category `ruff`). +- **Biome** (`lint-biome`, JavaScript, TypeScript, JSON and CSS, after v4.5.0) + runs `biome ci`, which lints and checks formatting and import order without + writing, on the `*.js`, `*.mjs`, `*.cjs`, `*.jsx`, `*.ts`, `*.mts`, `*.cts`, + `*.tsx`, `*.json`, `*.jsonc` and `*.css` files. Biome runs once `biome` 2.4.0 or + later is pinned in the repository's mise config; until then it warns how to opt + in and skips. Biome reads the repository's own `biome.json` or + `biome.jsonc`; config-sync's + [`biome.json` template](../config-sync/templates/biome.json) is a starting + point. Findings are annotated on the PR, and with `upload-sarif` they also go + to code scanning (category `biome`). `lint-biome-exclude` skips more paths, + such as a directory with another root Biome config, which Biome rejects. + Biome steps aside in repositories that configure ESLint (`eslint.config.*`, + `.eslintrc*`), which lint in their own CI with their plugins; set + `lint-biome-with-eslint` to run both. dprint formats only Markdown. **Inline scripts.** Code in a `run:` block is out of reach of linters, formatters and tests, so a `run:` step may hold exactly one line with one @@ -229,7 +243,7 @@ runner's system Python, which ships PyYAML (`ubuntu-24.04`). | `lint-config-dir` | Optional linter config directory. Default: `""`. | | `lint-fail-on-error` | Fail when a linter fails. Default: `false`. | | `lint-job-mode` | `auto`, `single`, or `parallel` (see above). Default: `auto`. v3.3.0+. | -| `upload-sarif` | Upload SARIF (checkov, trivy, zizmor, ruff). Default: `true`. | +| `upload-sarif` | Upload SARIF (checkov, trivy, zizmor, ruff, biome). Default: `true`. | | `lint-dprint` | Markdown formatting (dprint). Default: `true`. | | `lint-yamlfmt` | YAML formatting (yamlfmt). Default: `true`. | | `lint-yamllint` | YAML linting (yamllint). Default: `true`. | @@ -242,6 +256,9 @@ runner's system Python, which ships PyYAML (`ubuntu-24.04`). | `lint-trivy` | Filesystem scan (trivy). Default: `true`. | | `lint-zizmor` | Actions security scan (zizmor). Default: `true`. | | `lint-ruff` | Python linting (ruff, see above). Default: `true`. After v4.5.0. | +| `lint-biome` | JS/TS/JSON/CSS linting (Biome). Default: `true`. After v4.5.0. | +| `lint-biome-exclude` | Bash pattern of paths Biome skips. Default: `""`. After v4.5.0. | +| `lint-biome-with-eslint` | Run Biome next to ESLint. Default: `false`. After v4.5.0. | | `lint-config-drift` | Config-drift check. Default: `false`. | | `lint-inline-scripts` | Inline-script check (see above). Default: `true`. After v4.4.0. | | `lint-inline-scripts-blocking` | Report inline scripts as errors. Default: `false`. After v4.4.0. | diff --git a/scripts/config-sync/sync-files.sh b/scripts/config-sync/sync-files.sh index a63a2ddf..636dd781 100644 --- a/scripts/config-sync/sync-files.sh +++ b/scripts/config-sync/sync-files.sh @@ -86,7 +86,8 @@ apm_owner() { # A template is not bootstrapped when the repository configures the tool in # another file already: ruff.toml would take precedence over [tool.ruff] in -# pyproject.toml and silently replace its settings. +# pyproject.toml and silently replace its settings, and biome.json would sit +# next to the repository's biome.jsonc. configured_elsewhere() { case "$1" in ruff.toml) @@ -99,6 +100,14 @@ configured_elsewhere() { return 0 fi ;; + biome.json) + for config in biome.jsonc .biome.json .biome.jsonc; do + if [ -e "${config}" ]; then + echo "${config}" + return 0 + fi + done + ;; *) ;; esac return 1 diff --git a/scripts/lint/biome.sh b/scripts/lint/biome.sh new file mode 100755 index 00000000..277c198d --- /dev/null +++ b/scripts/lint/biome.sh @@ -0,0 +1,53 @@ +#!/usr/bin/env bash +# +# Lints the repository's JavaScript, TypeScript, JSON and CSS files with Biome +# and checks their formatting (`biome ci`, which never writes to the files). +# A step of .github/workflows/lint.yml, run the same way in both lint modes. +# Biome reads the repository's own config (biome.json or biome.jsonc). +# Env: EXCLUDE_PATTERN (lint-biome-exclude): skip the paths matching this bash +# pattern. UPLOAD_SARIF: also write the findings as SARIF for code scanning, +# and sarif=true to GITHUB_OUTPUT. + +set -eo pipefail + +lint_dir="$(dirname "${BASH_SOURCE[0]}")" +mapfile -d '' listed < <(bash "${lint_dir}/language-files.sh" web) +files=() +for file in "${listed[@]}"; do + # shellcheck disable=SC2053 # EXCLUDE_PATTERN is a pattern, not a string. + if [ -z "${EXCLUDE_PATTERN}" ] || [[ "${file}" != ${EXCLUDE_PATTERN} ]]; then + files+=("${file}") + fi +done +# Without file arguments Biome would check the whole directory. +if [ "${#files[@]}" -eq 0 ]; then + echo "::notice::No JavaScript, TypeScript, JSON or CSS files found; skipping Biome" + exit 0 +fi +# Biome is opt-in per repository: without a pin it warns and skips rather than +# failing. After the guard: a repository whose files are all excluded needs no pin. +if ! mise which biome >/dev/null 2>&1; then + echo "::warning::Skipping Biome: this repository has JavaScript, TypeScript, JSON or CSS files but doesn't pin biome. To lint them, pin it in .mise.toml (Renovate-managed, e.g. 'mise use biome@') and add a biome.json (config-sync's template is a starting point)." + exit 0 +fi +# Multiple reporters and --reporter-file need Biome 2.4.0 or later. +version="$(mise exec -- biome --version 2>/dev/null || true)" +version="${version##* }" +if [ -n "${version}" ] && [ "$(printf '%s\n' 2.4.0 "${version}" | sort -V | head -n 1)" != 2.4.0 ]; then + echo "::warning::Skipping Biome: the shared Lint workflow needs Biome 2.4.0 or later, and this repository pins ${version}. Update the biome pin in .mise.toml." + exit 0 +fi + +# The default reporter shows formatting diffs in the log, the github one +# annotates the PR. --no-errors-on-unmatched: the config may ignore every file. +reporters=(--reporter=default --reporter=github) +if [ "${UPLOAD_SARIF}" = "true" ]; then + reporters+=(--reporter=sarif "--reporter-file=${RUNNER_TEMP}/biome.sarif") +fi + +status=0 +mise exec -- biome ci --no-errors-on-unmatched "${reporters[@]}" -- "${files[@]}" || status=1 +if [ "${UPLOAD_SARIF}" = "true" ] && [ -f "${RUNNER_TEMP}/biome.sarif" ]; then + echo "sarif=true" >>"${GITHUB_OUTPUT}" +fi +exit "${status}" diff --git a/scripts/lint/detect-language.sh b/scripts/lint/detect-language.sh index c7a048eb..f4fab2da 100755 --- a/scripts/lint/detect-language.sh +++ b/scripts/lint/detect-language.sh @@ -3,11 +3,17 @@ # Checks whether the repository has files of language $1, so its linter (and # the mise install it needs) runs only for repositories that have them. # A step of .github/workflows/lint.yml, run the same way in both lint modes. +# Env: STEP_ASIDE_FOR: another kind of language-files.sh, such as eslint; when +# the repository has those files too, the linter steps aside for that tool. # Writes found= to GITHUB_OUTPUT. set -eo pipefail -if [ -n "$(bash "$(dirname "${BASH_SOURCE[0]}")/language-files.sh" "$1" | head -c 1)" ]; then +files_sh="$(dirname "${BASH_SOURCE[0]}")/language-files.sh" +if [ -n "${STEP_ASIDE_FOR}" ] && [ -n "$(bash "${files_sh}" "${STEP_ASIDE_FOR}" | head -c 1)" ]; then + echo "::notice::The repository has ${STEP_ASIDE_FOR} config; skipping the $1 linter" + echo "found=false" >>"${GITHUB_OUTPUT}" +elif [ -n "$(bash "${files_sh}" "$1" | head -c 1)" ]; then echo "found=true" >>"${GITHUB_OUTPUT}" else echo "::notice::No $1 files found; skipping its linter" diff --git a/scripts/lint/language-files.sh b/scripts/lint/language-files.sh index ef7502f6..dc6014cb 100755 --- a/scripts/lint/language-files.sh +++ b/scripts/lint/language-files.sh @@ -13,6 +13,13 @@ set -eo pipefail case "$1" in python) patterns=('**/*.py' '**/*.pyi') ;; +# JavaScript, TypeScript, JSON and CSS: what Biome checks. +web) + patterns=('**/*.js' '**/*.mjs' '**/*.cjs' '**/*.jsx' '**/*.ts' '**/*.mts' '**/*.cts' '**/*.tsx' + '**/*.json' '**/*.jsonc' '**/*.css') + ;; +# ESLint configs: Biome steps aside for repositories that lint with ESLint. +eslint) patterns=('**/eslint.config.*' '**/.eslintrc' '**/.eslintrc.*') ;; *) echo "::error::language-files.sh: unknown language '$1'" >&2 exit 2 diff --git a/tests/config-sync-scripts.sh b/tests/config-sync-scripts.sh index a128c7bb..1a7913e5 100644 --- a/tests/config-sync-scripts.sh +++ b/tests/config-sync-scripts.sh @@ -80,4 +80,10 @@ done sync_templates .ruff.toml "line-length = 100" [ ! -e "${consumer}/ruff.toml" ] || fail "ruff.toml must not be added next to .ruff.toml" -echo "✓ config-sync: sync-files.sh keeps the ruff.toml template out of repositories that configure ruff elsewhere." +[ -e "${consumer}/biome.json" ] || fail "a repository without Biome config must get the biome.json template" +sync_templates biome.jsonc "{}" +[ ! -e "${consumer}/biome.json" ] || fail "biome.json must not be added next to biome.jsonc" +grep -Fq "biome.json skipped: configured in biome.jsonc" "${tmp_dir}/log" || + fail "the skipped biome.json must be logged: $(cat "${tmp_dir}/log")" + +echo "✓ config-sync: sync-files.sh keeps the ruff.toml and biome.json templates out of repositories that configure them elsewhere." diff --git a/tests/lint-include.py b/tests/lint-include.py index 287efc3e..71de8551 100755 --- a/tests/lint-include.py +++ b/tests/lint-include.py @@ -35,7 +35,7 @@ LINT_REF = "$/.github/workflows/lint.yml" # Boolean `lint-*` inputs of lint.yml that are options rather than linters. -NOT_LINTERS = {"lint-fail-on-error", "lint-inline-scripts-blocking"} +NOT_LINTERS = {"lint-fail-on-error", "lint-inline-scripts-blocking", "lint-biome-with-eslint"} LEVELS = {"none": 0, "read": 1, "write": 2} diff --git a/tests/lint-job-modes-contract.sh b/tests/lint-job-modes-contract.sh index 8093677a..ddbd5c32 100755 --- a/tests/lint-job-modes-contract.sh +++ b/tests/lint-job-modes-contract.sh @@ -14,7 +14,7 @@ set -euo pipefail repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" workflow="${repo_root}/.github/workflows/lint.yml" combined_job="all-linters" -linter_jobs=(dprint yamlfmt yamllint actionlint gitleaks go shellcheck shfmt checkov trivy zizmor ruff config-drift inline-scripts) +linter_jobs=(dprint yamlfmt yamllint actionlint gitleaks go shellcheck shfmt checkov trivy zizmor ruff biome config-drift inline-scripts) parallel_guard="(inputs.lint-job-mode == 'parallel' || (inputs.lint-job-mode == 'auto' && !github.event.repository.private))" fail() { diff --git a/tests/lint-scripts.sh b/tests/lint-scripts.sh index 56413a7a..bcb05cd7 100755 --- a/tests/lint-scripts.sh +++ b/tests/lint-scripts.sh @@ -31,6 +31,8 @@ which) [[ " ${FAKE_TOOLS} " == *" $2 "* ]] ;; exec) shift 2 printf '%s: %s\n' "${PWD}" "$*" >>"${MISE_LOG}" + [ -z "${FAKE_STDOUT:-}" ] || echo "${FAKE_STDOUT}" + [ -z "${FAKE_WRITES:-}" ] || touch "${FAKE_WRITES}" exit "${FAKE_EXIT:-0}" ;; *) exit 2 ;; @@ -248,6 +250,65 @@ expect_status 0 "ruff without Python files" expect_out "::notice::No Python files found; skipping ruff" "ruff without Python files" [ -z "${log}" ] || fail "ruff must not run without Python files: ${log}" +# Biome checks the JavaScript, TypeScript, JSON and CSS files in one read-only +# `biome ci` run, which also writes SARIF when asked. +mkdir -p "${code}/.specify" +touch "${code}/a.json" "${code}/b.mjs" "${code}/sub/c.tsx" "${code}/sub/d.css" "${code}/e.md" "${code}/.specify/f.json" +git -C "${code}" add -f -- a.json b.mjs sub/c.tsx sub/d.css e.md .specify/f.json +listed="$(cd "${code}" && bash "${scripts}/language-files.sh" web | tr '\0' '\n')" +[ "${listed}" = $'a.json\nb.mjs\nsub/c.tsx\nsub/d.css' ] || + fail "language-files.sh web must list the JavaScript, TypeScript, JSON and CSS files; got: ${listed}" +# Biome steps aside for ESLint, unless lint-biome-with-eslint clears STEP_ASIDE_FOR. +touch "${code}/sub/.eslintrc" +git -C "${code}" add -f -- sub/.eslintrc +run_in "${code}" "detect-language web" STEP_ASIDE_FOR=eslint +[ "${outputs}" = found=false ] || fail "Biome must step aside for ESLint; got: ${outputs}" +expect_out "::notice::The repository has eslint config; skipping the web linter" "a repository with ESLint" +run_in "${code}" "detect-language web" STEP_ASIDE_FOR= +[ "${outputs}" = found=true ] || fail "lint-biome-with-eslint must run Biome; got: ${outputs}" +git -C "${code}" rm -q --cached sub/.eslintrc +run_in "${code}" "detect-language web" STEP_ASIDE_FOR=eslint +[ "${outputs}" = found=true ] || fail "Biome must run without ESLint; got: ${outputs}" +# Without a biome pin, Biome warns how to opt in and skips instead of failing. +run_in "${code}" biome FAKE_TOOLS="" +expect_status 0 "Biome without its tool" +expect_out "::warning::Skipping Biome: this repository has JavaScript, TypeScript, JSON or CSS files but doesn't pin biome." \ + "Biome without its tool" +expect_out "pin it in .mise.toml" "Biome without its tool" +[ -z "${log}${outputs}" ] || fail "Biome without its tool must not run: ${log} ${outputs}" +# Excluding every file skips Biome before it needs a pin. +run_in "${code}" biome FAKE_TOOLS="" EXCLUDE_PATTERN="*" +expect_status 0 "Biome with every file excluded" +expect_out "::notice::No JavaScript, TypeScript, JSON or CSS files found; skipping Biome" "Biome with every file excluded" +export FAKE_TOOLS="${FAKE_TOOLS} biome" +biome_call="biome ci --no-errors-on-unmatched --reporter=default --reporter=github" +run_in "${code}" biome FAKE_WRITES="${RUNNER_TEMP}/biome.sarif" +expect_status 0 "Biome with SARIF" +expect_log "${biome_call} --reporter=sarif --reporter-file=${RUNNER_TEMP}/biome.sarif -- a.json b.mjs sub/c.tsx sub/d.css" \ + "Biome with SARIF" +[ "${outputs}" = sarif=true ] || fail "Biome must report its SARIF report; got: ${outputs}" +run_in "${code}" biome FAKE_EXIT=1 +expect_status 1 "a failing Biome" +[ -z "${outputs}" ] || fail "Biome must not report a SARIF report it didn't write: ${outputs}" +# Biome before 2.4.0 lacks multiple reporters: it warns and skips. +run_in "${code}" biome FAKE_STDOUT="Version: 2.3.11" +expect_status 0 "Biome 2.3.11" +expect_out "::warning::Skipping Biome: the shared Lint workflow needs Biome 2.4.0 or later, and this repository pins 2.3.11." \ + "Biome 2.3.11" +[[ "${log}" != *"biome ci"* ]] || fail "Biome 2.3.11 must not run: ${log}" +run_in "${code}" biome FAKE_STDOUT="Version: 2.4.0" +expect_log "biome ci" "Biome 2.4.0" +run_in "${code}" biome UPLOAD_SARIF=false +expect_status 0 "Biome without SARIF" +expect_log "${biome_call} -- a.json" "Biome without SARIF" +run_in "${code}" biome UPLOAD_SARIF=false EXCLUDE_PATTERN="sub/*" +[[ "${log}" == *"${biome_call} -- a.json b.mjs" ]] || fail "lint-biome-exclude must skip sub/: ${log}" +git -C "${code}" rm -q --cached a.json b.mjs sub/c.tsx sub/d.css +run_in "${code}" biome +expect_status 0 "Biome without its files" +expect_out "::notice::No JavaScript, TypeScript, JSON or CSS files found; skipping Biome" "Biome without its files" +[ -z "${log}" ] || fail "Biome must not run without its files: ${log}" + # The SARIF filter drops checkov's skipped checks (level none) and tolerates a # missing report. run checkov-sarif-filter diff --git a/tests/workflow-job-conditions.py b/tests/workflow-job-conditions.py index a604b4fa..e47c831d 100755 --- a/tests/workflow-job-conditions.py +++ b/tests/workflow-job-conditions.py @@ -421,6 +421,7 @@ def lint_context(*, mode="auto", private=False, has_repository=True, event_name= "trivy", "zizmor", "ruff", + "biome", "inline-scripts", ) } @@ -445,6 +446,7 @@ def lint_context(*, mode="auto", private=False, has_repository=True, event_name= "trivy", "zizmor", "ruff", + "biome", "inline-scripts", } SINGLE = {"all-linters"} diff --git a/workflow-templates/assign-issue-to-codeowners.properties.json b/workflow-templates/assign-issue-to-codeowners.properties.json index 994adc83..d199c035 100644 --- a/workflow-templates/assign-issue-to-codeowners.properties.json +++ b/workflow-templates/assign-issue-to-codeowners.properties.json @@ -1,5 +1,5 @@ { - "name": "Assign issue to CODEOWNERS", - "description": "Auto-assign newly opened issues to users listed in the CODEOWNERS file.", - "categories": ["Utilities"] + "name": "Assign issue to CODEOWNERS", + "description": "Auto-assign newly opened issues to users listed in the CODEOWNERS file.", + "categories": ["Utilities"] } diff --git a/workflow-templates/autofix.properties.json b/workflow-templates/autofix.properties.json index 13dc382e..2dbed444 100644 --- a/workflow-templates/autofix.properties.json +++ b/workflow-templates/autofix.properties.json @@ -1,6 +1,6 @@ { - "name": "Auto-fix formatting", - "description": "Manually triggered workflow that auto-fixes formatting issues using dprint fmt, yamlfmt, and shfmt --write, then commits and pushes the changes. Supports formatter configs from an optional config directory.", - "categories": ["Continuous integration"], - "filePatterns": ["\\.ya?ml$", "\\.sh$", "\\.md$"] + "name": "Auto-fix formatting", + "description": "Manually triggered workflow that auto-fixes formatting issues using dprint fmt, yamlfmt, and shfmt --write, then commits and pushes the changes. Supports formatter configs from an optional config directory.", + "categories": ["Continuous integration"], + "filePatterns": ["\\.ya?ml$", "\\.sh$", "\\.md$"] } diff --git a/workflow-templates/config-sync.properties.json b/workflow-templates/config-sync.properties.json index e831cf58..b0a0f5d5 100644 --- a/workflow-templates/config-sync.properties.json +++ b/workflow-templates/config-sync.properties.json @@ -1,5 +1,5 @@ { - "name": "Config Sync", - "description": "Pull-based config sync from the central DevSecNinja/.github repository. Opens PRs when config files have changed. No PAT required.", - "categories": ["Utilities"] + "name": "Config Sync", + "description": "Pull-based config sync from the central DevSecNinja/.github repository. Opens PRs when config files have changed. No PAT required.", + "categories": ["Utilities"] } diff --git a/workflow-templates/label-sync.properties.json b/workflow-templates/label-sync.properties.json index b67088e1..b6c39a8f 100644 --- a/workflow-templates/label-sync.properties.json +++ b/workflow-templates/label-sync.properties.json @@ -1,5 +1,5 @@ { - "name": "Label Sync", - "description": "Sync GitHub labels from a labels.yaml config file. Runs daily and on push.", - "categories": ["Utilities"] + "name": "Label Sync", + "description": "Sync GitHub labels from a labels.yaml config file. Runs daily and on push.", + "categories": ["Utilities"] } diff --git a/workflow-templates/labeler.properties.json b/workflow-templates/labeler.properties.json index 6a5321e8..aeb3ab34 100644 --- a/workflow-templates/labeler.properties.json +++ b/workflow-templates/labeler.properties.json @@ -1,5 +1,5 @@ { - "name": "Labeler", - "description": "Auto-label pull requests based on changed file paths and issues based on body content.", - "categories": ["Utilities"] + "name": "Labeler", + "description": "Auto-label pull requests based on changed file paths and issues based on body content.", + "categories": ["Utilities"] } diff --git a/workflow-templates/lint.properties.json b/workflow-templates/lint.properties.json index 4aaefabe..e5d8a40e 100644 --- a/workflow-templates/lint.properties.json +++ b/workflow-templates/lint.properties.json @@ -1,6 +1,6 @@ { - "name": "Lint", - "description": "Centralized linting workflow with config-directory support and toggles for dprint, yamlfmt, yamllint, actionlint, gitleaks, shellcheck, shfmt, checkov, trivy, zizmor, and config-drift checking.", - "categories": ["Continuous integration"], - "filePatterns": ["\\.ya?ml$", "\\.sh$", "\\.md$"] + "name": "Lint", + "description": "Centralized linting workflow with config-directory support and toggles for dprint, yamlfmt, yamllint, actionlint, gitleaks, shellcheck, shfmt, checkov, trivy, zizmor, and config-drift checking.", + "categories": ["Continuous integration"], + "filePatterns": ["\\.ya?ml$", "\\.sh$", "\\.md$"] } diff --git a/workflow-templates/lint.yml b/workflow-templates/lint.yml index 60a9fcc3..b815ee5e 100644 --- a/workflow-templates/lint.yml +++ b/workflow-templates/lint.yml @@ -65,6 +65,10 @@ jobs: # Optional: needs a lint.yml release after v4.5.0; runs only when the # repository has Python files. Pin ruff in your mise config. # lint-ruff: true + # Optional: needs a lint.yml release after v4.5.0; runs only when the + # repository has JavaScript, TypeScript, JSON or CSS files and no ESLint + # config. Pin biome in your mise config. + # lint-biome: true # lint-config-drift: false # Optional: report inline scripts in run: steps. Needs a lint.yml release # after v4.4.0; bump the pin above before uncommenting. diff --git a/workflow-templates/pages.properties.json b/workflow-templates/pages.properties.json index 81592ab3..61709b95 100644 --- a/workflow-templates/pages.properties.json +++ b/workflow-templates/pages.properties.json @@ -1,6 +1,6 @@ { - "name": "Pages", - "description": "Deploy GitHub Pages on the default branch and Cloudflare Pages previews for pull requests.", - "categories": ["Deployment", "Continuous integration"], - "filePatterns": ["package.json", "index.html", "sitemap.xml"] + "name": "Pages", + "description": "Deploy GitHub Pages on the default branch and Cloudflare Pages previews for pull requests.", + "categories": ["Deployment", "Continuous integration"], + "filePatterns": ["package.json", "index.html", "sitemap.xml"] } diff --git a/workflow-templates/release.properties.json b/workflow-templates/release.properties.json index 9f462a34..b85a164c 100644 --- a/workflow-templates/release.properties.json +++ b/workflow-templates/release.properties.json @@ -1,5 +1,5 @@ { - "name": "Release", - "description": "Create a GitHub Release with git-cliff changelog when a version tag is pushed.", - "categories": ["Continuous integration"] + "name": "Release", + "description": "Create a GitHub Release with git-cliff changelog when a version tag is pushed.", + "categories": ["Continuous integration"] } diff --git a/workflow-templates/renovate-pr-cooldown.properties.json b/workflow-templates/renovate-pr-cooldown.properties.json index 4935f588..80696942 100644 --- a/workflow-templates/renovate-pr-cooldown.properties.json +++ b/workflow-templates/renovate-pr-cooldown.properties.json @@ -1,6 +1,6 @@ { - "name": "Renovate PR cooldown", - "description": "Enforces a 14-day PR-age soak for Renovate PRs from registries without a trusted release timestamp (ghcr.io/lscr.io/quay.io) via a required pr-cooldown status check, so they can auto-merge after soaking. Add pr-cooldown to the branch ruleset's required checks.", - "categories": ["Continuous integration", "Dependency management"], - "filePatterns": ["renovate\\.json5?$"] + "name": "Renovate PR cooldown", + "description": "Enforces a 14-day PR-age soak for Renovate PRs from registries without a trusted release timestamp (ghcr.io/lscr.io/quay.io) via a required pr-cooldown status check, so they can auto-merge after soaking. Add pr-cooldown to the branch ruleset's required checks.", + "categories": ["Continuous integration", "Dependency management"], + "filePatterns": ["renovate\\.json5?$"] } diff --git a/workflow-templates/todo-to-issue.properties.json b/workflow-templates/todo-to-issue.properties.json index 01eb3ad5..62d88524 100644 --- a/workflow-templates/todo-to-issue.properties.json +++ b/workflow-templates/todo-to-issue.properties.json @@ -1,5 +1,5 @@ { - "name": "TODO to Issue", - "description": "Automatically convert TODO comments in code to GitHub issues.", - "categories": ["Utilities"] + "name": "TODO to Issue", + "description": "Automatically convert TODO comments in code to GitHub issues.", + "categories": ["Utilities"] }