Skip to content

Commit 4ece11c

Browse files
Brianclaude
andcommitted
fix: resolve bugs in CI workflow and git hooks
- Remove unused esbuild build step from publish workflow (missing dep) - Add prepare script to auto-configure git hooks path - Fix commit-msg hook permissions (was not executable) - Remove main-branch gate so hooks run on all branches - Add package.json for hooks to fix CommonJS/ESM conflict - Add set -euo pipefail for proper error handling in pre-commit - Fix silent git error suppression in shell scripts - Fix return detection regex to handle newlines before value - Add workflow_dispatch, npm cache, and concurrency to workflow Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent a00e39f commit 4ece11c

9 files changed

Lines changed: 29 additions & 16 deletions

File tree

.github/workflows/publish.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ name: Publish to npm with Provenance
33
on:
44
release:
55
types: [published]
6+
workflow_dispatch: # Allow manual triggers for hotfixes
7+
8+
concurrency:
9+
group: publish-${{ github.ref }}
10+
cancel-in-progress: false # Don't cancel in-progress publishes
611

712
jobs:
813
publish:
@@ -19,16 +24,14 @@ jobs:
1924
with:
2025
node-version: '20'
2126
registry-url: 'https://registry.npmjs.org'
27+
cache: 'npm' # Cache npm dependencies for faster builds
2228

2329
- name: Install dependencies
2430
run: npm ci
2531

2632
- name: Run tests
2733
run: npm test
2834

29-
- name: Build browser bundle
30-
run: npx esbuild index.js --bundle --minify --sourcemap --outfile=dist/bri.js
31-
3235
- name: Publish to npm with provenance
3336
run: npm publish --provenance --access public
3437
env:

.hooks/commit-msg

100644100755
File mode changed.

.hooks/pre-commit

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
#!/usr/bin/env bash
2+
set -euo pipefail
23
# .hooks/pre-commit - Pre-commit validation orchestrator for BRI 🐺
34
# This script runs all check scripts in .hooks/pre-commit.d/
45
# Each check script must exit 0 on success, non-zero on failure.
56

6-
# Only run on main branch
7-
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
8-
if [ "$CURRENT_BRANCH" != "main" ]; then
9-
echo "🦍 Skipping pre-commit checks on branch: $CURRENT_BRANCH (checks only run on main)"
10-
exit 0
11-
fi
12-
137
HOOKS_DIR="$(cd "$(dirname "$0")" && pwd)"
148
CHECKS_DIR="$HOOKS_DIR/pre-commit.d"
159

.hooks/pre-commit.d/check-docs.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,10 @@ check_file_documented() {
8585
}
8686

8787
# Get list of staged files (added or modified)
88-
STAGED_FILES=$(git diff --cached --name-only --diff-filter=AM 2>/dev/null || true)
88+
if ! STAGED_FILES=$(git diff --cached --name-only --diff-filter=AM 2>&1); then
89+
echo "❌ Failed to get staged files from git"
90+
exit 1
91+
fi
8992

9093
# Exit early if no staged files
9194
if [ -z "$STAGED_FILES" ]; then
@@ -105,7 +108,7 @@ for file in $STAGED_FILES; do
105108
dir=$(dirname "$file")
106109
while [ "$dir" != "." ] && [ "$dir" != "/" ]; do
107110
# Check if this directory is being newly created (not in HEAD)
108-
if ! git ls-tree -d HEAD "$dir" &>/dev/null 2>&1; then
111+
if ! git ls-tree -d HEAD "$dir" >/dev/null 2>&1; then
109112
# Add to array if not already present
110113
if ! array_contains "$dir" "${NEW_DIRS[@]}"; then
111114
NEW_DIRS+=("$dir")

.hooks/pre-commit.d/check-jsdoc.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ if [ ! -f "$VALIDATOR" ]; then
2222
fi
2323

2424
# Get list of staged JS files (added or modified)
25-
STAGED_FILES=$(git diff --cached --name-only --diff-filter=AM 2>/dev/null | grep '\.js$' || true)
25+
if ! ALL_STAGED=$(git diff --cached --name-only --diff-filter=AM 2>&1); then
26+
echo "❌ Failed to get staged files from git"
27+
exit 1
28+
fi
29+
STAGED_FILES=$(echo "$ALL_STAGED" | grep '\.js$' || true)
2630

2731
# Exit early if no JS files staged
2832
if [ -z "$STAGED_FILES" ]; then

.hooks/pre-commit.d/jsdoc/utils.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ function hasReturnValue(body) {
1818
.replace(/`(?:[^`\\]|\\.)*`/g, '""');
1919

2020
// Check for return with a value (not just "return;" or "return}")
21-
return /return\s+[^;\s}]/.test(cleaned);
21+
// Handles: return value; return\n value; return {obj}; return [arr];
22+
return /return[\s\n]+[^;\s}]/.test(cleaned);
2223
}
2324

2425
/**

.hooks/pre-commit.d/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"type": "commonjs"
3+
}

.hooks/pre-commit.d/utils.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ array_contains() {
3737
}
3838

3939
# Get list of staged files (added or modified)
40+
# Returns 1 if git command fails, 0 otherwise (even if no files)
4041
get_staged_files() {
41-
git diff --cached --name-only --diff-filter=AM 2>/dev/null || true
42+
if ! git diff --cached --name-only --diff-filter=AM 2>&1; then
43+
return 1
44+
fi
45+
return 0
4246
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
},
1515
"scripts": {
1616
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
17-
"test:coverage": "node --experimental-vm-modules node_modules/jest/bin/jest.js --coverage"
17+
"test:coverage": "node --experimental-vm-modules node_modules/jest/bin/jest.js --coverage",
18+
"prepare": "git config core.hooksPath .hooks"
1819
},
1920
"devDependencies": {
2021
"jest": "^29.7.0"

0 commit comments

Comments
 (0)