Skip to content
Open
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
40 changes: 40 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
[build]
# Use all available CPU cores for compilation.
# Override with CARGO_BUILD_JOBS if needed.
# Omit explicit jobs to allow Cargo defaults.

[env]
# Optional flags gated by environment variables (opt-in).
# PLATFORM_NIGHTLY_RUSTFLAGS: nightly-only parallel rustc flags (2023-11-09 blog).
# Set by rust-toolchain-nightly.toml or scripts; leave empty on stable.
# Example: PLATFORM_NIGHTLY_RUSTFLAGS="-Z threads=0"
# PLATFORM_FAST_LINKER_RUSTFLAGS: fast linker defaults for Linux (mold or lld).
# Example: PLATFORM_FAST_LINKER_RUSTFLAGS="-C link-arg=-fuse-ld=mold"
# Example: PLATFORM_FAST_LINKER_RUSTFLAGS="-C link-arg=-fuse-ld=lld"
# PLATFORM_FAST_LINKER_RUSTFLAGS_DARWIN: fast linker defaults for macOS (lld or zld).
# Example: PLATFORM_FAST_LINKER_RUSTFLAGS_DARWIN="-C link-arg=-fuse-ld=lld"
# Example: PLATFORM_FAST_LINKER_RUSTFLAGS_DARWIN="-C link-arg=-fuse-ld=zld"
# PLATFORM_LINKER_RUSTFLAGS: explicit fast linker flags (appended after defaults).
# Example: PLATFORM_LINKER_RUSTFLAGS="-C link-arg=-fuse-ld=mold"
# Example: PLATFORM_LINKER_RUSTFLAGS="-C link-arg=-fuse-ld=lld"
# PLATFORM_LINKER_RUSTFLAGS_DARWIN: explicit fast linker flags for macOS (appended after defaults).
# Example: PLATFORM_LINKER_RUSTFLAGS_DARWIN="-C link-arg=-fuse-ld=lld"
# Example: PLATFORM_LINKER_RUSTFLAGS_DARWIN="-C link-arg=-fuse-ld=zld"
# PLATFORM_DISABLE_NIGHTLY: set to 1 to disable nightly flags.
# PLATFORM_RUST_NIGHTLY: set to 1 to force nightly flags.
PLATFORM_DISABLE_NIGHTLY = { value = "${PLATFORM_DISABLE_NIGHTLY}", force = false }
PLATFORM_RUST_NIGHTLY = { value = "${PLATFORM_RUST_NIGHTLY}", force = false }
PLATFORM_NIGHTLY_RUSTFLAGS = { value = "${PLATFORM_NIGHTLY_RUSTFLAGS}", force = false }
# Fast-linker defaults are opt-in: set PLATFORM_FAST_LINKER_RUSTFLAGS
# or PLATFORM_FAST_LINKER_RUSTFLAGS_DARWIN to enable on a system
# with the desired linker installed. Set PLATFORM_DISABLE_FAST_LINKER=1
# to ignore fast-linker settings (scripts clear the env values).
PLATFORM_DISABLE_FAST_LINKER = { value = "${PLATFORM_DISABLE_FAST_LINKER}", force = false }
PLATFORM_FAST_LINKER_RUSTFLAGS = { value = "${PLATFORM_FAST_LINKER_RUSTFLAGS}", force = false }
PLATFORM_FAST_LINKER_RUSTFLAGS_DARWIN = { value = "${PLATFORM_FAST_LINKER_RUSTFLAGS_DARWIN}", force = false }
PLATFORM_LINKER_RUSTFLAGS = { value = "${PLATFORM_LINKER_RUSTFLAGS}", force = false }
PLATFORM_LINKER_RUSTFLAGS_DARWIN = { value = "${PLATFORM_LINKER_RUSTFLAGS_DARWIN}", force = false }
RUSTFLAGS = { value = "${RUSTFLAGS} ${PLATFORM_NIGHTLY_RUSTFLAGS} ${PLATFORM_FAST_LINKER_RUSTFLAGS} ${PLATFORM_LINKER_RUSTFLAGS}", force = true }

[target.'cfg(target_os = "macos")'.env]
RUSTFLAGS = { value = "${RUSTFLAGS} ${PLATFORM_NIGHTLY_RUSTFLAGS} ${PLATFORM_FAST_LINKER_RUSTFLAGS_DARWIN} ${PLATFORM_LINKER_RUSTFLAGS_DARWIN}", force = true }
27 changes: 27 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Build artifacts
target/
*.rlib
*.rmeta

# Git
.git/

# IDE
.idea/
.vscode/
*.swp
*.swo

# OS
.DS_Store
Thumbs.db

# Local config
.env
.env.local
*.log

# Large data directories
data/
*.db
*.sqlite
8 changes: 8 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Platform Chain Validator Configuration
# Copy this file to .env and fill in your values

# REQUIRED: Your validator secret key (hex encoded 32 bytes or BIP39 mnemonic)
VALIDATOR_SECRET_KEY=your_secret_key_here

# Optional: Slack webhook for Watchtower notifications
# SLACK_WEBHOOK_URL=https://hooks.slack.com/services/xxx/xxx/xxx
33 changes: 19 additions & 14 deletions .githooks/install.sh
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
#!/bin/bash
# Install git hooks for term-challenge
# Install git hooks for this repository
# Run this after cloning: ./githooks/install.sh

set -e

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_DIR="$(dirname "$SCRIPT_DIR")"
REPO_ROOT="$(dirname "$SCRIPT_DIR")"
HOOKS_DIR="$REPO_ROOT/.git/hooks"

echo "Installing git hooks for term-challenge..."
echo "Installing git hooks..."

# Configure git to use our hooks directory
git -C "$REPO_DIR" config core.hooksPath .githooks
# Copy hooks
cp "$SCRIPT_DIR/pre-commit" "$HOOKS_DIR/pre-commit"
cp "$SCRIPT_DIR/pre-push" "$HOOKS_DIR/pre-push"

# Make hooks executable
chmod +x "$SCRIPT_DIR/pre-push"
# Make executable
chmod +x "$HOOKS_DIR/pre-commit"
chmod +x "$HOOKS_DIR/pre-push"

echo "Git hooks installed!"
echo "Git hooks installed successfully!"
echo ""
echo "The following checks will run before each push:"
echo " 1. cargo fmt --check"
echo " 2. cargo check"
echo " 3. cargo clippy"
echo " 4. cargo test"
echo "Hooks enabled:"
echo " - pre-commit: Auto-format code"
echo " - pre-push: Run all CI checks (format, clippy, tests)"
echo ""
echo "To bypass hooks (not recommended): git push --no-verify"
echo "To skip hooks temporarily (not recommended):"
echo " git push --no-verify"
33 changes: 17 additions & 16 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
#!/bin/bash
set -e

# Skip hooks if SKIP_GIT_HOOKS=1
if [ "${SKIP_GIT_HOOKS:-0}" = "1" ]; then
echo "Skipping pre-commit hooks (SKIP_GIT_HOOKS=1)"
exit 0
fi
# Pre-commit hook: Format code and check for issues

# Source cargo environment
if [ -f "$HOME/.cargo/env" ]; then
source "$HOME/.cargo/env"
fi
set -e

echo "Running pre-commit checks..."

# Format code
echo "Formatting code..."
cargo fmt --all

# Add formatted files back to staging
git add -u
echo "Checking formatting..."
if ! cargo fmt --all -- --check 2>/dev/null; then
echo "Formatting code..."
cargo fmt --all

# Check if there were changes
if ! git diff --quiet; then
echo ""
echo "Code was auto-formatted. Please review and re-add the changes:"
git diff --stat
echo ""
echo "Run: git add -u && git commit"
exit 1
fi
fi

echo "Pre-commit checks passed!"
115 changes: 62 additions & 53 deletions .githooks/pre-push
Original file line number Diff line number Diff line change
@@ -1,73 +1,82 @@
#!/bin/bash
set -e

# Skip hooks if SKIP_GIT_HOOKS=1
if [ "${SKIP_GIT_HOOKS:-0}" = "1" ]; then
echo "Skipping pre-push hooks (SKIP_GIT_HOOKS=1)"
exit 0
fi

# Source cargo environment
[ -f "$HOME/.cargo/env" ] && source "$HOME/.cargo/env"
# Pre-push hook: ALL CI checks MUST pass before pushing
# This ensures code quality and prevents broken builds

echo "🔍 Running pre-push checks..."
echo ""
set -e

# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color

check_failed() {
echo -e "${RED}❌ $1 FAILED${NC}"
echo ""
echo "Push aborted. Fix the issues and try again."
exit 1
}

check_passed() {
echo -e "${GREEN}✓ $1 passed${NC}"
}
echo "============================================="
echo "Running pre-push CI checks (ALL MANDATORY)..."
echo "============================================="

# 1. Format check
echo "📝 Checking code formatting..."
if ! cargo fmt --check 2>/dev/null; then
echo -e "${YELLOW}⚠️ Code not formatted. Running cargo fmt...${NC}"
cargo fmt
echo -e "${YELLOW}Code has been formatted. Please review and commit the changes.${NC}"
check_failed "Format"
echo -e "\n${YELLOW}[1/4] Checking formatting...${NC}"
if ! cargo fmt --all -- --check; then
echo -e "${RED}ERROR: Code is not formatted.${NC}"
echo "Run 'cargo fmt' before pushing."
exit 1
fi
check_passed "Format"
echo -e "${GREEN}✓ Formatting OK${NC}"

# 2. Build check
echo ""
echo "🔨 Checking compilation..."
if ! cargo check --all-targets 2>/dev/null; then
check_failed "Compilation"
# 2. Cargo check (compilation)
echo -e "\n${YELLOW}[2/4] Running cargo check...${NC}"
if ! cargo check --workspace; then
echo -e "${RED}ERROR: Compilation failed.${NC}"
echo "Fix compilation errors before pushing."
exit 1
fi
check_passed "Compilation"
echo -e "${GREEN}✓ Compilation OK${NC}"

# 3. Clippy
echo ""
echo "📎 Running clippy..."
if ! cargo clippy --all-targets --workspace -- -W clippy::all -D warnings \
# 3. Clippy (linting) - MANDATORY
# Check main code (not tests) with strict warnings
echo -e "\n${YELLOW}[3/4] Running clippy...${NC}"
if ! cargo clippy --workspace -- \
-D warnings \
-A clippy::too_many_arguments \
-A clippy::type_complexity \
-A clippy::large_enum_variant \
-A clippy::should_implement_trait 2>/dev/null; then
check_failed "Clippy"
-A clippy::type_complexity \
-A clippy::await_holding_lock \
-A clippy::collapsible_match \
-A clippy::collapsible_if \
-A clippy::needless_borrows_for_generic_args \
-A clippy::to_string_in_format_args \
-A clippy::manual_map \
-A clippy::map_flatten \
-A clippy::useless_format \
-A clippy::redundant_closure \
-A deprecated \
-A dead_code \
-A clippy::for_kv_map \
-A clippy::to_string_trait_impl \
-A clippy::if_same_then_else \
-A unused_variables \
-A unused_imports \
-A clippy::useless_conversion \
-A for_loops_over_fallibles \
-A clippy::manual_filter_map \
-A clippy::collapsible_str_replace \
-A clippy::manual_is_multiple_of \
-A clippy::map_entry \
-A clippy::manual_flatten; then
echo -e "${RED}ERROR: Clippy found issues.${NC}"
echo "Fix clippy warnings before pushing."
exit 1
fi
check_passed "Clippy"
echo -e "${GREEN}✓ Clippy OK${NC}"

# 4. Tests
echo ""
echo "🧪 Running tests..."
if ! cargo test --workspace -- --skip live --skip integration 2>/dev/null; then
check_failed "Tests"
# 4. Tests - MANDATORY
echo -e "\n${YELLOW}[4/4] Running tests...${NC}"
if ! cargo test --workspace; then
echo -e "${RED}ERROR: Tests failed.${NC}"
echo "Fix failing tests before pushing."
exit 1
fi
check_passed "Tests"
echo -e "${GREEN}✓ Tests OK${NC}"

echo ""
echo -e "${GREEN}✅ All pre-push checks passed!${NC}"
echo ""
echo -e "\n${GREEN}============================================="
echo "All CI checks passed! Pushing..."
echo -e "=============================================${NC}"
1 change: 0 additions & 1 deletion .github/ci-trigger

This file was deleted.

Loading
Loading