just: Replace inline scripts with script file calls

This commit is contained in:
Adrian Duke 2026-04-16 13:28:20 +01:00 committed by Fintan Halpenny
parent 421a43376d
commit 083c9d1abc
1 changed files with 5 additions and 79 deletions

View File

@ -81,23 +81,7 @@ check-scripts: (verify-tool "shellcheck")
[group('check')] [group('check')]
[parallel] [parallel]
check-keywords: (verify-tool "rg" "ripgrep") check-keywords: (verify-tool "rg" "ripgrep")
#! /usr/bin/env bash @CHECK="{{CHECK}}" NORMAL="{{NORMAL}}" scripts/just/check-keywords.sh
set -e
echo "{{CHECK}}Checking for forbidden words in staged files...{{NORMAL}}"
# Get staged Rust files
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACMR | grep '\.rs$' || true)
if [ -n "$STAGED_FILES" ]; then
! echo "$STAGED_FILES" | xargs rg --context=3 --fixed-strings 'radicle.xyz'
! echo "$STAGED_FILES" | xargs rg --context=3 --fixed-strings 'radicle.zulipchat.com'
# For `git2::` we need to exclude raw.rs
FILTERED_GIT2=$(echo "$STAGED_FILES" | grep '^crates/radicle/.*\.rs$' | grep -v 'crates/radicle/src/git/raw.rs' || true)
if [ -n "$FILTERED_GIT2" ]; then
! echo "$FILTERED_GIT2" | xargs rg --context=3 --fixed-strings 'git2::'
fi
fi
# Format Nix files # Format Nix files
[group('pre-commit')] [group('pre-commit')]
@ -105,12 +89,7 @@ check-keywords: (verify-tool "rg" "ripgrep")
[group('format')] [group('format')]
[parallel] [parallel]
format-nix: format-nix:
#!/usr/bin/env bash @scripts/just/format-nix.sh
if command -v alejandra >/dev/null 2>&1; then
alejandra --check .
else
echo "⏭️ alejandra not found, skipping Nix formatting."
fi
# Run pre-push checks # Run pre-push checks
[group('hooks')] [group('hooks')]
@ -128,17 +107,7 @@ lint-rust: (verify-tool "cargo")
# Check if required tools are in PATH. # Check if required tools are in PATH.
[private] [private]
verify-tool tool package_name="": verify-tool tool package_name="":
#!/usr/bin/env bash @ERROR="{{ERROR}}" NORMAL="{{NORMAL}}" HINT="{{HINT}}" scripts/just/verify-tool.sh "{{tool}}" "{{package_name}}"
set -e
if ! command -v {{tool}} >/dev/null 2>&1; then
PKG="{{package_name}}"
if [ -z "$PKG" ]; then
PKG="{{tool}}"
fi
echo "{{ERROR}}Missing required tool: {{tool + NORMAL}}"
echo "{{HINT}}Use your systems package manager to install '$PKG'.{{NORMAL}}"
exit 1
fi
# SECURITY: We COPY the hook template instead of symlinking it. This ensures that # SECURITY: We COPY the hook template instead of symlinking it. This ensures that
# checking out an untrusted patch won't overwrite your local git hooks. The copied # checking out an untrusted patch won't overwrite your local git hooks. The copied
@ -148,52 +117,9 @@ verify-tool tool package_name="":
# Install git hooks # Install git hooks
[group('hooks')] [group('hooks')]
install-hooks: install-hooks:
#!/usr/bin/env bash @SUCCESS="{{SUCCESS}}" NORMAL="{{NORMAL}}" scripts/just/install-hooks.sh "{{hook-script}}" "{{hooks}}"
set -e
read -p "Overwrite existing hooks '{{hooks}}'? [y/N] " confirm
[[ "$confirm" == "y" ]] || exit 1
for hook in {{hooks}}; do
if [ -f ".git/hooks/$hook" ]; then
rm ".git/hooks/$hook"
fi
cp {{hook-script}} ".git/hooks/$hook"
chmod +x ".git/hooks/$hook"
done
echo ""
echo "{{SUCCESS}}Hooks installed: {{hooks + NORMAL}}"
# Check for missing or changed hooks # Check for missing or changed hooks
[group('hooks')] [group('hooks')]
check-hooks: check-hooks:
#!/usr/bin/env bash @HINT="{{HINT}}" NORMAL="{{NORMAL}}" WARN="{{WARN}}" scripts/just/check-hooks.sh "{{hook-script}}" "{{hooks}}"
set -e
TEMPLATE="{{hook-script}}"
OUTDATED=()
MISSING=0
TOTAL=0
for hook in {{hooks}}; do
TOTAL=$((TOTAL + 1))
if [ ! -f ".git/hooks/$hook" ]; then
MISSING=$((MISSING + 1))
OUTDATED+=("$hook")
elif ! cmp -s "$TEMPLATE" ".git/hooks/$hook"; then
OUTDATED+=("$hook")
fi
done
if [ "$MISSING" -eq "$TOTAL" ] && [ "$TOTAL" -gt 0 ]; then
echo ""
echo "{{HINT}}No git hooks are installed. Run 'just install-hooks' to install them.{{NORMAL}}"
echo ""
elif [ ${#OUTDATED[@]} -gt 0 ]; then
echo ""
echo "{{WARN}}WARNING: The following git hooks are missing or out of date:{{NORMAL}}"
echo ""
for hook in "${OUTDATED[@]}"; do
echo -e "\t$hook"
done
echo ""
echo "{{HINT}}Check them with 'diff scripts/git-hook-template.sh .git/hooks/<hook name>' then run 'just install-hooks'{{NORMAL}}"
echo ""
fi