Skip to content
Merged

211 #321

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/scripts/install-hooks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash
# SPDX-FileCopyrightText: 2025 RAprogramm <andrey.rozanov.vl@gmail.com>
#
# SPDX-License-Identifier: MIT

set -euo pipefail

REPO_ROOT="$(git rev-parse --show-toplevel)"
HOOKS_DIR="$REPO_ROOT/.git/hooks"
PRE_COMMIT_SCRIPT="$REPO_ROOT/.github/scripts/pre-commit"

if [ ! -f "$PRE_COMMIT_SCRIPT" ]; then
echo "Error: pre-commit script not found at $PRE_COMMIT_SCRIPT"
exit 1
fi

echo "Installing pre-commit hook..."
cp "$PRE_COMMIT_SCRIPT" "$HOOKS_DIR/pre-commit"
chmod +x "$HOOKS_DIR/pre-commit"

echo "✅ Pre-commit hook installed successfully!"
echo ""
echo "The hook will run the following checks before each commit:"
echo " - rustfmt (nightly)"
echo " - REUSE compliance"
echo " - clippy (all features, all targets)"
echo " - tests (all features)"
echo " - cargo audit"
echo " - cargo deny (advisories, bans, licenses, sources)"
echo " - README.md generation"
66 changes: 66 additions & 0 deletions .github/scripts/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env bash
# SPDX-FileCopyrightText: 2025 RAprogramm <andrey.rozanov.vl@gmail.com>
#
# SPDX-License-Identifier: MIT

set -euo pipefail

echo "🔧 Ensuring nightly rustfmt is available..."
if ! rustup toolchain list | grep -q "^nightly"; then
rustup toolchain install nightly >/dev/null
fi
rustup component add rustfmt --toolchain nightly >/dev/null

echo "🧹 Checking formatting with rustfmt..."
cargo +nightly fmt --all -- --check

echo "📜 Checking REUSE compliance..."
if command -v reuse &> /dev/null; then
reuse lint
else
echo "⚠️ Warning: reuse tool not installed, skipping license compliance check"
echo " Install with:"
echo " - Arch Linux: paru -S reuse (or sudo pacman -S reuse)"
echo " - pip: pip install reuse"
fi

echo "🔍 Running clippy (all features, all targets)..."
cargo clippy --workspace --all-targets --all-features -- -D warnings

echo "🧪 Running tests (all features)..."
cargo test -vv

echo "🛡️ Running cargo audit..."
if ! command -v cargo-audit >/dev/null 2>&1; then
cargo install --locked cargo-audit >/dev/null
fi
cargo audit

echo "🔒 Running cargo deny..."
if ! command -v cargo-deny >/dev/null 2>&1; then
echo "Installing cargo-deny..."
cargo install --locked cargo-deny --version 0.18.4 >/dev/null
fi
cargo deny check advisories bans licenses sources

# Uncomment if you want to validate SQLx offline data
# echo "📦 Validating SQLx prepare..."
# cargo sqlx prepare --check --workspace

# same deterministic env
export TZ=UTC
export LC_ALL=C.UTF-8
export NO_COLOR=1
export CARGO_TERM_COLOR=never
export SOURCE_DATE_EPOCH=0

# Generate
./.github/scripts/gen_readme.sh

# Stage README if changed
if ! git diff --quiet -- README.md; then
git add README.md
fi

echo "✅ All checks passed!"

Loading
Loading