Skip to content

Commit d4b21d0

Browse files
committed
feat: implement runner.sh for git hooks CI compatibility
- Add generic runner.sh script for DDEV container detection - Simplify hook wrappers to use fixed 'pnpm zx' command via runner - Update test project with new hook implementation - Fix GitHub Actions 'pnpm: command not found' error
1 parent 3c80349 commit d4b21d0

File tree

5 files changed

+44
-74
lines changed

5 files changed

+44
-74
lines changed
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#!/usr/bin/env bash
22

33
# Git hook wrapper for ZX implementation
4-
# This script calls the modern ZX-based commit-msg hook
54

6-
# Call the ZX-based TypeScript hook
7-
pnpm zx "tools/git-hooks/hooks/commit-msg.ts" "$@"
5+
# Get the directory of this script
6+
HOOK_DIR="$(dirname "$0")"
7+
8+
# Use the generic runner script to execute the TypeScript hook
9+
exec "$HOOK_DIR/../shared/runner.sh" pnpm zx "tools/git-hooks/hooks/commit-msg.ts" "$@"
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#!/usr/bin/env bash
22

33
# Git hook wrapper for ZX implementation
4-
# This script calls the modern ZX-based pre-commit hook
54

6-
# Call the ZX-based TypeScript hook
7-
pnpm zx "tools/git-hooks/hooks/pre-commit.ts" "$@"
5+
# Get the directory of this script
6+
HOOK_DIR="$(dirname "$0")"
7+
8+
# Use the generic runner script to execute the TypeScript hook
9+
exec "$HOOK_DIR/../shared/runner.sh" pnpm zx "tools/git-hooks/hooks/pre-commit.ts" "$@"
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#!/usr/bin/env bash
22

33
# Git hook wrapper for ZX implementation
4-
# This script calls the modern ZX-based pre-push hook
54

6-
# Call the ZX-based TypeScript hook
7-
pnpm zx "tools/git-hooks/hooks/pre-push.ts" "$@"
5+
# Get the directory of this script
6+
HOOK_DIR="$(dirname "$0")"
7+
8+
# Use the generic runner script to execute the TypeScript hook
9+
exec "$HOOK_DIR/../shared/runner.sh" pnpm zx "tools/git-hooks/hooks/pre-push.ts" "$@"
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env bash
2+
3+
# Generic runner script - handles DDEV container detection and command execution
4+
5+
# Force color output to preserve colors through shell layers
6+
export FORCE_COLOR=1
7+
export CLICOLOR_FORCE=1
8+
9+
# Check if we're inside a DDEV container
10+
is_inside_container() {
11+
[[ -n "$DDEV_HOSTNAME" || -n "$DDEV_PROJECT" || -n "$DDEV_SITENAME" ]]
12+
}
13+
14+
# Main execution
15+
if [[ $# -lt 1 ]]; then
16+
echo "Usage: $0 <command> [arguments...]" >&2
17+
exit 1
18+
fi
19+
20+
if is_inside_container; then
21+
exec "$@"
22+
elif command -v ddev >/dev/null 2>&1; then
23+
exec ddev exec "$@"
24+
else
25+
exec "$@"
26+
fi

booster/tools/git-hooks/shared/utils.ts

Lines changed: 3 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -18,64 +18,17 @@ interface RunOptions {
1818
}
1919

2020
/**
21-
* Check if we're already inside a DDEV container
22-
*/
23-
async function isInsideDdevContainer(): Promise<boolean> {
24-
try {
25-
// Check for CI environment first - in CI we should use DDEV commands explicitly
26-
if (process.env.CI === 'true' || process.env.GITHUB_ACTIONS === 'true') {
27-
return false // In CI, always use ddev exec commands
28-
}
29-
30-
// Check for DDEV_HOSTNAME environment variable (most reliable)
31-
if (process.env.DDEV_HOSTNAME) {
32-
return true
33-
}
34-
35-
// Check for specific DDEV environment variables
36-
if (process.env.DDEV_PROJECT || process.env.DDEV_SITENAME) {
37-
return true
38-
}
39-
40-
// Check if we're inside a container by examining hostname or other indicators
41-
const result = await $`hostname`.quiet()
42-
const hostname = result.toString().trim()
43-
44-
// Check for DDEV container indicators
45-
return hostname.includes('ddev') || hostname.includes('web')
46-
} catch (error) {
47-
return false
48-
}
49-
}
50-
51-
/**
52-
* Execute command with appropriate runner (DDEV or direct)
21+
* Execute command directly with ZX
5322
* @param command Array of command parts
5423
* @param options Execution options
5524
*/
5625
export async function runWithRunner(command: string[], options: RunOptions = {}): Promise<any> {
5726
const { quiet = false } = options
5827

59-
// Build command array
60-
let fullCommand: string[]
61-
let contextLabel: string
62-
63-
const isInsideContainer = await isInsideDdevContainer()
64-
65-
if (!isInsideContainer) {
66-
// We're not inside a container - run via DDEV
67-
fullCommand = ['ddev', 'exec', ...command]
68-
contextLabel = 'via DDEV'
69-
} else {
70-
// Run directly (already inside container)
71-
fullCommand = command
72-
contextLabel = isInsideContainer ? 'inside DDEV container' : 'direct'
73-
}
74-
7528
// Log command execution if not quiet
7629
if (!quiet) {
7730
const commandStr = command.join(' ')
78-
log.info(`Executing (${contextLabel}): ${commandStr}`)
31+
log.info(`Executing: ${commandStr}`)
7932
}
8033

8134
// Set clean environment to avoid locale warnings
@@ -87,26 +40,11 @@ export async function runWithRunner(command: string[], options: RunOptions = {})
8740

8841
try {
8942
// Execute with appropriate stdio handling and clean environment
90-
return await $({ stdio: quiet ? 'pipe' : 'inherit', env: cleanEnv })`${fullCommand}`
43+
return await $({ stdio: quiet ? 'pipe' : 'inherit', env: cleanEnv })`${command}`
9144
} catch (error: unknown) {
92-
// Add better error context for debugging CI issues
93-
const errorMessage = error instanceof Error ? error.message : String(error)
94-
const commandStr = fullCommand.join(' ')
95-
log.error(`Command failed: ${commandStr}`)
96-
log.error(`Error: ${errorMessage}`)
97-
log.error(`Context: ${contextLabel}`)
98-
log.error(`Working directory: ${process.cwd()}`)
99-
100-
// In CI environments, also log environment details for debugging
101-
if (process.env.CI === 'true' || process.env.GITHUB_ACTIONS === 'true') {
102-
log.error(`CI Environment detected`)
103-
log.error(`Container detection result: inside=${isInsideContainer}`)
104-
}
105-
10645
throw error
10746
}
10847
}
109-
11048
/**
11149
* Logging utilities with consistent formatting
11250
*/

0 commit comments

Comments
 (0)