ML-187: fall back to all checks when run outside git hook
This commit is contained in:
+16
-12
@@ -14,20 +14,24 @@ staged_lines() {
|
|||||||
echo "$STAGED" | tr ' ' '\n'
|
echo "$STAGED" | tr ' ' '\n'
|
||||||
}
|
}
|
||||||
|
|
||||||
# Early exit if no staged files (e.g., --allow-empty)
|
# Determine if we should gate checks on staged files.
|
||||||
if [ -z "$STAGED" ]; then
|
# $STAGED is set by .git/hooks/pre-commit during git commit.
|
||||||
debug_msg "No staged files found, skipping pre-commit checks."
|
# When run directly (e.g., mise run dev:precommit), run all checks.
|
||||||
exit 0
|
if [ -z "${STAGED:-}" ]; then
|
||||||
|
debug_msg "No staged files in context — running all checks."
|
||||||
|
SKIP_GATE=true
|
||||||
|
else
|
||||||
|
SKIP_GATE=false
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# --- Shell scripts ---
|
# --- Shell scripts ---
|
||||||
if staged_lines | grep -qE '^scripts/|^\.shellcheckrc'; then
|
if $SKIP_GATE || staged_lines | grep -qE '^scripts/|^\.shellcheckrc'; then
|
||||||
debug_msg "Running shellcheck..."
|
debug_msg "Running shellcheck..."
|
||||||
fd . 'scripts/' --exclude '*.hurl' -t file --exec shellcheck --color
|
fd . 'scripts/' --exclude '*.hurl' -t file --exec shellcheck --color
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# --- Elixir ---
|
# --- Elixir ---
|
||||||
if staged_lines | grep -qE '^(lib/|test/|config/|mix\.exs|mix\.lock|priv/repo/migrations/|priv/gettext/|\.credo\.exs|\.formatter\.exs|\.sobelow-conf)'; then
|
if $SKIP_GATE || staged_lines | grep -qE '^(lib/|test/|config/|mix\.exs|mix\.lock|priv/repo/migrations/|priv/gettext/|\.credo\.exs|\.formatter\.exs|\.sobelow-conf)'; then
|
||||||
debug_msg "Running credo..."
|
debug_msg "Running credo..."
|
||||||
mix credo --strict
|
mix credo --strict
|
||||||
|
|
||||||
@@ -45,37 +49,37 @@ if staged_lines | grep -qE '^(lib/|test/|config/|mix\.exs|mix\.lock|priv/repo/mi
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# deps.unlock sub-gate: only when mix.exs or mix.lock changed
|
# deps.unlock sub-gate: only when mix.exs or mix.lock changed
|
||||||
if staged_lines | grep -qE '^mix\.exs$|^mix\.lock$'; then
|
if $SKIP_GATE || staged_lines | grep -qE '^mix\.exs$|^mix\.lock$'; then
|
||||||
debug_msg "Checking unused deps..."
|
debug_msg "Checking unused deps..."
|
||||||
mix deps.unlock --unused
|
mix deps.unlock --unused
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# --- Assets (JS/TS/CSS) ---
|
# --- Assets (JS/TS/CSS) ---
|
||||||
if staged_lines | grep -qE '^assets/|^\.pi/extensions/.*\.(ts|js|json)$'; then
|
if $SKIP_GATE || staged_lines | grep -qE '^assets/|^\.pi/extensions/.*\.(ts|js|json)$'; then
|
||||||
debug_msg "Checking assets formatting..."
|
debug_msg "Checking assets formatting..."
|
||||||
prettier --check 'assets/css/**/*.css' 'assets/js/**/*.js' '.pi/extensions/**/*.{ts,js,json}' '!.pi/extensions/**/node_modules/**'
|
prettier --check 'assets/css/**/*.css' 'assets/js/**/*.js' '.pi/extensions/**/*.{ts,js,json}' '!.pi/extensions/**/node_modules/**'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# --- Documentation ---
|
# --- Documentation ---
|
||||||
if staged_lines | grep -qE '^docs/|^README\.md$|^AGENTS\.md$'; then
|
if $SKIP_GATE || staged_lines | grep -qE '^docs/|^README\.md$|^AGENTS\.md$'; then
|
||||||
debug_msg "Checking docs formatting..."
|
debug_msg "Checking docs formatting..."
|
||||||
prettier --check 'docs/**/*.md' 'docs/**/*.livemd' 'README.md' 'AGENTS.md'
|
prettier --check 'docs/**/*.md' 'docs/**/*.livemd' 'README.md' 'AGENTS.md'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# --- Backlog ---
|
# --- Backlog ---
|
||||||
if staged_lines | grep -qE '^backlog/'; then
|
if $SKIP_GATE || staged_lines | grep -qE '^backlog/'; then
|
||||||
debug_msg "Checking backlog formatting..."
|
debug_msg "Checking backlog formatting..."
|
||||||
prettier --check 'backlog/archive/**/*.md' 'backlog/completed/**/*.md' 'backlog/tasks/**/*.md' 'backlog/docs/**/*.md'
|
prettier --check 'backlog/archive/**/*.md' 'backlog/completed/**/*.md' 'backlog/tasks/**/*.md' 'backlog/docs/**/*.md'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# --- Presto ---
|
# --- Presto ---
|
||||||
if staged_lines | grep -qE '^presto/'; then
|
if $SKIP_GATE || staged_lines | grep -qE '^presto/'; then
|
||||||
debug_msg "Checking presto..."
|
debug_msg "Checking presto..."
|
||||||
(cd presto && mise run test)
|
(cd presto && mise run test)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# --- Docker ---
|
# --- Docker ---
|
||||||
if staged_lines | grep -qE '^Dockerfile$|^\.dockerignore$|^compose\.yaml$'; then
|
if $SKIP_GATE || staged_lines | grep -qE '^Dockerfile$|^\.dockerignore$|^compose\.yaml$'; then
|
||||||
debug_msg "Validating Docker image..."
|
debug_msg "Validating Docker image..."
|
||||||
mise run dev:validate-docker-image
|
mise run dev:validate-docker-image
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user