Skip to content

Commit 5450e16

Browse files
committed
chore(nix): add git hook installer and pre-commit/pre-push scripts that run inside nix devShell
1 parent 5f52cba commit 5450e16

3 files changed

Lines changed: 62 additions & 73 deletions

File tree

.githooks/pre-commit

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# Pre-commit hook: run formatting, clippy and tests inside Nix devShell if available
5+
if command -v nix >/dev/null 2>&1; then
6+
echo "🔧 Running pre-commit checks inside Nix devShell..."
7+
nix develop --command just pre-commit
8+
else
9+
echo "⚠️ Nix not found; running pre-commit via just (may fail if native deps missing)..."
10+
just pre-commit
11+
fi
12+
13+
exit 0
114
#!/bin/bash
215

316
# Pre-commit hook for Singularity Language Registry

.githooks/pre-push

Lines changed: 12 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,12 @@
1-
#!/bin/bash
2-
3-
# Pre-push hook for Singularity Language Registry
4-
# Final checks before pushing to remote
5-
6-
set -e
7-
8-
echo "🚀 Running pre-push checks..."
9-
10-
# Colors for output
11-
RED='\033[0;31m'
12-
GREEN='\033[0;32m'
13-
YELLOW='\033[1;33m'
14-
NC='\033[0m' # No Color
15-
16-
# Get the remote and branch being pushed to
17-
remote="$1"
18-
url="$2"
19-
20-
# Check which branch we're pushing to
21-
while read local_ref local_sha remote_ref remote_sha; do
22-
branch=$(echo "$remote_ref" | sed 's/refs\/heads\///')
23-
24-
echo "📍 Pushing to branch: $branch"
25-
26-
# Prevent direct push to main
27-
if [ "$branch" = "main" ]; then
28-
echo -e "${RED}❌ Direct push to main branch is not allowed!${NC}"
29-
echo -e "${YELLOW}Please create a pull request from development or a feature branch.${NC}"
30-
echo ""
31-
echo "Steps:"
32-
echo "1. git checkout -b feature/your-feature"
33-
echo "2. git push origin feature/your-feature"
34-
echo "3. Create a PR on GitHub"
35-
exit 1
36-
fi
37-
38-
# Run comprehensive tests before push
39-
echo "🧪 Running comprehensive tests..."
40-
if ! cargo test --all-features --release; then
41-
echo -e "${RED}❌ Tests failed!${NC}"
42-
exit 1
43-
fi
44-
45-
# Check for outdated dependencies
46-
echo "📦 Checking dependencies..."
47-
if command -v cargo-outdated &> /dev/null; then
48-
cargo outdated || true
49-
fi
50-
51-
# Security audit
52-
echo "🔐 Running security audit..."
53-
if command -v cargo-audit &> /dev/null; then
54-
if ! cargo audit; then
55-
echo -e "${YELLOW}⚠️ Security vulnerabilities found!${NC}"
56-
echo "Consider fixing before pushing"
57-
read -p "Continue anyway? (y/N) " -n 1 -r
58-
echo
59-
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
60-
exit 1
61-
fi
62-
fi
63-
fi
64-
65-
# Documentation check
66-
echo "📚 Checking documentation..."
67-
if ! cargo doc --all-features --no-deps; then
68-
echo -e "${RED}❌ Documentation build failed!${NC}"
69-
exit 1
70-
fi
71-
done
72-
73-
echo -e "${GREEN}✅ All pre-push checks passed!${NC}"
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# Pre-push hook that runs the project's pre-push task. If Nix is available
5+
# we'll run the command inside the devShell so native libraries are provided.
6+
if command -v nix >/dev/null 2>&1; then
7+
echo "🏗️ Running pre-push checks inside Nix devShell (nix develop)..."
8+
nix develop --command just pre-push
9+
else
10+
echo "⚠️ Nix not found; running pre-push via just (may fail if native deps missing)..."
11+
just pre-push
12+
fi

setup-hooks.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,40 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# Install repository git hooks to use the Nix devShell for heavy checks.
5+
# This will create .githooks/pre-push and configure git to use .githooks as
6+
# the hooks directory (via core.hooksPath). Running the pre-push hook will
7+
# prefer `nix develop --command just pre-push` so native deps like OpenSSL
8+
# are available when clippy and the build run.
9+
10+
HOOK_DIR=".githooks"
11+
mkdir -p "$HOOK_DIR"
12+
13+
cat > "$HOOK_DIR/pre-push" <<'EOF'
14+
#!/usr/bin/env bash
15+
set -euo pipefail
16+
17+
# Pre-push hook that runs the project's pre-push task. If Nix is available
18+
# we'll run the command inside the devShell so native libraries are provided.
19+
if command -v nix >/dev/null 2>&1; then
20+
echo "🏗️ Running pre-push checks inside Nix devShell (nix develop)..."
21+
nix develop --command just pre-push
22+
else
23+
echo "⚠️ Nix not found; running pre-push via just (may fail if native deps missing)..."
24+
just pre-push
25+
fi
26+
EOF
27+
28+
chmod +x "$HOOK_DIR/pre-push"
29+
30+
# Configure git to use the .githooks directory (safe to re-run)
31+
git config core.hooksPath "$HOOK_DIR" || true
32+
33+
echo "Installed git hooks to $HOOK_DIR and set core.hooksPath."
34+
35+
echo "Tip: run 'nix develop' or 'direnv allow' to enter the devShell before heavy builds."
36+
37+
exit 0
138
#!/bin/bash
239

340
# Setup git hooks for the Singularity Language Registry

0 commit comments

Comments
 (0)