mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-29 04:08:12 +08:00
124 lines
4.8 KiB
YAML
124 lines
4.8 KiB
YAML
# There are 8 fix-capable jobs and 6 pure-check jobs.
|
|
# Dual-mode pre-commit: by default (local dev) jobs fix and stage changes
|
|
# (`stage_fixed: true` batches the `git add` per job to avoid the index lock
|
|
# that parallel `git add` calls would hit). In CI, set LEFTHOOK_CHECK_ONLY=1
|
|
# to skip --fix on every fix-capable job. With no files modified, `stage_fixed`
|
|
# becomes a no-op, so CI only verifies and exits non-zero on issues.
|
|
#
|
|
# NOTE: every `run:` block is written in POSIX-sh-compatible syntax
|
|
# (`[` ... `]` with `=` for string compare) instead of bash `[[` ...
|
|
# `]]`. Lefthook executes scripts via `/bin/sh`, which is `dash` on
|
|
# most Linux CI runners and would otherwise fail with
|
|
# `sh: 1: [[: not found`. Keeping the hooks POSIX avoids pinning
|
|
# lefthook to bash and keeps them portable to macOS/Linux/containers.
|
|
pre-commit:
|
|
parallel: true
|
|
jobs:
|
|
- name: end-of-file-fixer
|
|
stage_fixed: true
|
|
run: |
|
|
if [ "${LEFTHOOK_CHECK_ONLY:-}" = "1" ]; then
|
|
python3 tools/hooks/check_files.py eof
|
|
else
|
|
python3 tools/hooks/check_files.py eof --fix
|
|
fi
|
|
- name: trailing-whitespace
|
|
stage_fixed: true
|
|
run: |
|
|
if [ "${LEFTHOOK_CHECK_ONLY:-}" = "1" ]; then
|
|
python3 tools/hooks/check_files.py trailing-whitespace
|
|
else
|
|
python3 tools/hooks/check_files.py trailing-whitespace --fix
|
|
fi
|
|
- name: mixed-line-ending
|
|
stage_fixed: true
|
|
run: |
|
|
if [ "${LEFTHOOK_CHECK_ONLY:-}" = "1" ]; then
|
|
python3 tools/hooks/check_files.py mixed-line-ending
|
|
else
|
|
python3 tools/hooks/check_files.py mixed-line-ending --fix
|
|
fi
|
|
- name: ruff
|
|
glob: "*.py"
|
|
stage_fixed: true
|
|
run: |
|
|
if [ "${LEFTHOOK_CHECK_ONLY:-}" = "1" ]; then
|
|
ruff check {staged_files}
|
|
else
|
|
ruff check --fix {staged_files}
|
|
fi
|
|
- name: ruff-format
|
|
glob: "*.py"
|
|
stage_fixed: true
|
|
run: |
|
|
if [ "${LEFTHOOK_CHECK_ONLY:-}" = "1" ]; then
|
|
ruff format --check {staged_files}
|
|
else
|
|
ruff format {staged_files}
|
|
fi
|
|
- name: gofmt
|
|
glob: "*.go"
|
|
stage_fixed: true
|
|
run: |
|
|
if [ "${LEFTHOOK_CHECK_ONLY:-}" = "1" ]; then
|
|
unformatted=$(gofmt -l {staged_files})
|
|
if [ -n "$unformatted" ]; then
|
|
echo "The following Go files are not gofmt'd:"
|
|
echo "$unformatted"
|
|
exit 1
|
|
fi
|
|
else
|
|
gofmt -w {staged_files}
|
|
fi
|
|
- name: web-checks
|
|
group:
|
|
piped: true
|
|
jobs:
|
|
- name: web-deps
|
|
glob: "web/**/*.{css,less,json,js,jsx,ts,tsx}"
|
|
run: |
|
|
# Install ONLY oxfmt + oxlint (prebuilt Rust binaries) into an isolated
|
|
# dir inside web/node_modules. This skips the full React dev-toolchain
|
|
# `npm ci`, which was the dominant CI cost of the old prettier/eslint
|
|
# setup. oxfmt/oxlint read web/.oxfmtrc.json / web/.oxlintrc.json from cwd.
|
|
HOOKBIN=web/node_modules/.hookbin
|
|
if [ ! -x "$HOOKBIN/node_modules/.bin/oxfmt" ] \
|
|
|| [ ! -x "$HOOKBIN/node_modules/.bin/oxlint" ]; then
|
|
echo '==> installing oxfmt + oxlint only (no full web toolchain)'
|
|
mkdir -p "$HOOKBIN"
|
|
[ -f "$HOOKBIN/package.json" ] \
|
|
|| printf '{"name":"hookbin","version":"1.0.0","private":true}\n' > "$HOOKBIN/package.json"
|
|
npm install --prefix "$HOOKBIN" --no-audit --no-fund --save-dev oxfmt oxlint
|
|
fi
|
|
- name: web-oxfmt
|
|
glob: "web/**/*.{css,less,json,js,jsx,ts,tsx}"
|
|
exclude: ["web/**/*.min.js", "web/**/*.min.css"]
|
|
root: "web/"
|
|
stage_fixed: true
|
|
run: |
|
|
if [ "${LEFTHOOK_CHECK_ONLY:-}" = "1" ]; then
|
|
node_modules/.hookbin/node_modules/.bin/oxfmt --check {staged_files}
|
|
else
|
|
node_modules/.hookbin/node_modules/.bin/oxfmt {staged_files}
|
|
fi
|
|
- name: web-oxlint
|
|
glob: "web/**/*.{js,jsx,ts,tsx}"
|
|
root: "web/"
|
|
stage_fixed: true
|
|
run: |
|
|
if [ "${LEFTHOOK_CHECK_ONLY:-}" = "1" ]; then
|
|
node_modules/.hookbin/node_modules/.bin/oxlint {staged_files}
|
|
else
|
|
node_modules/.hookbin/node_modules/.bin/oxlint --fix {staged_files}
|
|
fi
|
|
- name: check-yaml
|
|
run: python3 tools/hooks/check_files.py yaml
|
|
- name: check-json
|
|
run: python3 tools/hooks/check_files.py json
|
|
- name: check-case-conflict
|
|
run: python3 tools/hooks/check_files.py case-conflict
|
|
- name: check-merge-conflict
|
|
run: python3 tools/hooks/check_files.py merge-conflict
|
|
- name: check-symlinks
|
|
run: python3 tools/hooks/check_files.py symlinks
|