diff --git a/.github/workflows/substrate-claim-checker.yml b/.github/workflows/substrate-claim-checker.yml new file mode 100644 index 0000000000..128522344d --- /dev/null +++ b/.github/workflows/substrate-claim-checker.yml @@ -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 + run: bun install + - 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." diff --git a/tools/git/hooks/commit-msg b/tools/git/hooks/commit-msg new file mode 100644 index 0000000000..84fca72375 --- /dev/null +++ b/tools/git/hooks/commit-msg @@ -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 ---" +exit 0 diff --git a/tools/git/hooks/pre-commit b/tools/git/hooks/pre-commit new file mode 100644 index 0000000000..9d2a14aa1c --- /dev/null +++ b/tools/git/hooks/pre-commit @@ -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 + +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 + +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 diff --git a/tools/setup/common/git-hooks.sh b/tools/setup/common/git-hooks.sh new file mode 100644 index 0000000000..6adfab9a1c --- /dev/null +++ b/tools/setup/common/git-hooks.sh @@ -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 + 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" +done + +echo "--- Git Hooks installed successfully ---" diff --git a/tools/setup/macos.sh b/tools/setup/macos.sh index 7efaeb5224..068c40d0e9 100755 --- a/tools/setup/macos.sh +++ b/tools/setup/macos.sh @@ -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"