feat: enforce lint checks as gate for commits and CI (#54)
All checks were successful
Deploy Feature Branch to Test / PHP Syntax Check (push) Successful in 34s
Deploy Feature Branch to Test / CSS Lint (stylelint) (push) Successful in 1m12s
Deploy Feature Branch to Test / HTML Lint (htmlhint) (push) Successful in 1m10s
Lint / PHP Syntax Check (push) Successful in 32s
Lint / CSS Lint (stylelint) (push) Successful in 1m14s
Lint / HTML Lint (htmlhint) (push) Successful in 1m9s
Lint / PHP Syntax Check (pull_request) Successful in 32s
Lint / CSS Lint (stylelint) (pull_request) Successful in 1m11s
Lint / HTML Lint (htmlhint) (pull_request) Successful in 1m9s
Deploy Feature Branch to Test / Deploy to Test Environment (push) Successful in 24s
All checks were successful
Deploy Feature Branch to Test / PHP Syntax Check (push) Successful in 34s
Deploy Feature Branch to Test / CSS Lint (stylelint) (push) Successful in 1m12s
Deploy Feature Branch to Test / HTML Lint (htmlhint) (push) Successful in 1m10s
Lint / PHP Syntax Check (push) Successful in 32s
Lint / CSS Lint (stylelint) (push) Successful in 1m14s
Lint / HTML Lint (htmlhint) (push) Successful in 1m9s
Lint / PHP Syntax Check (pull_request) Successful in 32s
Lint / CSS Lint (stylelint) (pull_request) Successful in 1m11s
Lint / HTML Lint (htmlhint) (pull_request) Successful in 1m9s
Deploy Feature Branch to Test / Deploy to Test Environment (push) Successful in 24s
- Add PHP syntax check to lint-staged via scripts/lint-php.sh - Add lint:php script to package.json - Update lint script to include PHP checks - Create scripts/safe-commit.sh for AI agent use - Update deploy-test.yml: lint jobs as gate before deploy - Add branch protection for main requiring status checks - Update AGENTS.md with pre-commit hook rules for agents Also addresses #53: CI requires lint checks before merge Co-authored-by: Claw <claw@openclaw.local>
This commit is contained in:
28
scripts/lint-php.sh
Executable file
28
scripts/lint-php.sh
Executable file
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env bash
|
||||
# Pre-commit PHP syntax check for lint-staged
|
||||
# Called with staged .php files as arguments
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
if ! command -v php &>/dev/null; then
|
||||
echo "❌ PHP not found. Install php-cli to commit PHP files."
|
||||
echo " Ubuntu/Debian: sudo apt-get install php-cli"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
errors=0
|
||||
for file in "$@"; do
|
||||
if ! php -l "$file" >/dev/null 2>&1; then
|
||||
echo "❌ Syntax error in $file"
|
||||
php -l "$file"
|
||||
errors=1
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "$errors" -eq 1 ]; then
|
||||
echo ""
|
||||
echo "❌ PHP lint failed. Fix errors before committing."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "✅ PHP syntax OK"
|
||||
37
scripts/safe-commit.sh
Executable file
37
scripts/safe-commit.sh
Executable file
@@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env bash
|
||||
# safe-commit.sh – Commit with pre-commit hooks guaranteed to run
|
||||
# Usage: ./scripts/safe-commit.sh "commit message"
|
||||
#
|
||||
# This script ensures lint checks always execute, even when committing
|
||||
# from non-interactive contexts (CI, AI agents, etc.).
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
if [ -z "${1:-}" ]; then
|
||||
echo "❌ Usage: ./scripts/safe-commit.sh \"commit message\""
|
||||
exit 1
|
||||
fi
|
||||
|
||||
MSG="$1"
|
||||
REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
cd "$REPO_ROOT"
|
||||
|
||||
# Ensure hooks directory exists and is configured
|
||||
if [ -d ".husky" ]; then
|
||||
git config core.hooksPath .husky
|
||||
fi
|
||||
|
||||
# Run lint-staged manually as a safety net (in case hook is skipped)
|
||||
if command -v npx &>/dev/null && [ -f "node_modules/.bin/lint-staged" ]; then
|
||||
echo "🔍 Running pre-commit lint checks..."
|
||||
npx lint-staged || {
|
||||
echo ""
|
||||
echo "❌ Lint checks failed. Commit aborted."
|
||||
echo " Fix the errors above and try again."
|
||||
exit 1
|
||||
}
|
||||
echo "✅ All lint checks passed."
|
||||
fi
|
||||
|
||||
# Commit with hooks enabled (no --no-verify)
|
||||
git commit -m "$MSG"
|
||||
Reference in New Issue
Block a user