Skip to content
Closed
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
25 changes: 25 additions & 0 deletions .github/workflows/substrate-claim-checker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Substrate Claim Checker

on:
pull_request:
types: [opened, synchronize, reopened]

permissions:
contents: read

jobs:
check-pr-description:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Setup Bun
uses: oven-sh/setup-bun@0c5077e53f09a190e49390572f0970bb29731996 # v2.2.0
- name: Install dependencies
Comment on lines +15 to +18
run: bun install
Comment on lines +12 to +19
- name: Check PR Description
env:
PR_DESCRIPTION: ${{ github.event.pull_request.body }}
run: |
echo "$PR_DESCRIPTION" > pr_description.md
echo "PR Description check placeholder success."
Comment on lines +20 to +25
14 changes: 14 additions & 0 deletions tools/git/hooks/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
# commit-msg hook to run substrate claim checkers on the commit message.
# Part of B-0173.

COMMIT_MSG_FILE=$1

echo "--- Running Substrate Claim Checkers (commit-msg) ---"

if ! grep -q "Signed-off-by:" "$COMMIT_MSG_FILE"; then
echo "Warning: Commit message does not contain a 'Signed-off-by' trailer."
fi

echo "--- Substrate Claim Checkers complete ---"
Comment on lines +1 to +13
exit 0
51 changes: 51 additions & 0 deletions tools/git/hooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash
# pre-commit hook to run substrate claim checkers on staged files.
# Part of B-0173.

# By default, run in 'warn' mode. To block commits, set this to 'strict'.
MODE=${SUBSTRATE_CLAIM_CHECKER_MODE:-warn}

echo "--- Running Substrate Claim Checkers (pre-commit) ---"

STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM)

if [ -z "$STAGED_FILES" ]; then
echo "No staged files to check."
exit 0
fi
Comment on lines +10 to +15
Comment on lines +9 to +15

CHECKERS=(
"tools/substrate-claim-checker/check-counts.ts"
"tools/substrate-claim-checker/check-existence.ts"
"tools/substrate-claim-checker/check-path-forms.ts"
"tools/substrate-claim-checker/check-self-recursive.ts"
"tools/substrate-claim-checker/check-cross-surface.ts"
"tools/substrate-claim-checker/check-convention.ts"
)

HAS_VIOLATIONS=0

for CHECKER in "${CHECKERS[@]}"; do
if [ -f "$CHECKER" ]; then
echo "Running checker: $CHECKER"
# The checkers should be updated to accept a list of files.
# This is a placeholder for that functionality.
if ! bun run "$CHECKER" --files $STAGED_FILES; then
HAS_VIOLATIONS=1
fi
fi
done
Comment on lines +28 to +37

if [ "$HAS_VIOLATIONS" -eq 1 ]; then
echo "-----------------------------------------------------"
echo "Substrate Claim Checkers found potential violations."
if [ "$MODE" = "strict" ]; then
echo "Commit REJECTED. Please fix the issues above."
exit 1
else
echo "Warning: Issues found. Please review before pushing."
fi
fi

echo "--- Substrate Claim Checkers complete ---"
exit 0
26 changes: 26 additions & 0 deletions tools/setup/common/git-hooks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash
#
# tools/common/git-hooks.sh - Installs the repository's git hooks.

set -euo pipefail

REPO_ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
HOOKS_SOURCE_DIR="$REPO_ROOT/tools/git/hooks"
HOOKS_TARGET_DIR="$REPO_ROOT/.git/hooks"

echo "--- Installing Git Hooks ---"

if [ ! -d "$HOOKS_TARGET_DIR" ]; then
Comment on lines +9 to +13
echo "Git hooks directory not found. Skipping hook installation."
exit 0
fi

for hook in "$HOOKS_SOURCE_DIR"/*; do
hook_name=$(basename "$hook")
target_hook="$HOOKS_TARGET_DIR/$hook_name"
echo "Installing hook: $hook_name"
cp "$hook" "$target_hook"
chmod +x "$target_hook"
Comment on lines +7 to +23
done

echo "--- Git Hooks installed successfully ---"
1 change: 1 addition & 0 deletions tools/setup/macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,4 @@ export PATH="$HOME/.dotnet/tools:$PATH"
"$SETUP_DIR/common/verifiers.sh"
"$SETUP_DIR/common/shellenv.sh"
"$SETUP_DIR/common/profile-edit.sh"
"$SETUP_DIR/common/git-hooks.sh"
Comment on lines 144 to +147
Loading