@@ -22,8 +22,27 @@ interface RunOptions {
2222 */
2323async function isInsideDdevContainer ( ) : Promise < boolean > {
2424 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
2541 const result = await $ `hostname` . quiet ( )
26- return result . toString ( ) . includes ( 'ddev' )
42+ const hostname = result . toString ( ) . trim ( )
43+
44+ // Check for DDEV container indicators
45+ return hostname . includes ( 'ddev' ) || hostname . includes ( 'web' )
2746 } catch ( error ) {
2847 return false
2948 }
@@ -66,8 +85,26 @@ export async function runWithRunner(command: string[], options: RunOptions = {})
6685 LANG : 'C' ,
6786 }
6887
69- // Execute with appropriate stdio handling and clean environment
70- return await $ ( { stdio : quiet ? 'pipe' : 'inherit' , env : cleanEnv } ) `${ fullCommand } `
88+ try {
89+ // Execute with appropriate stdio handling and clean environment
90+ return await $ ( { stdio : quiet ? 'pipe' : 'inherit' , env : cleanEnv } ) `${ fullCommand } `
91+ } 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+
106+ throw error
107+ }
71108}
72109
73110/**
0 commit comments