@@ -42,17 +42,36 @@ const getChangedSampleFolders = (): string[] => {
4242
4343 // Execute the script from the project root.
4444 const projectRoot = path . join ( __dirname , '..' ) ;
45- const output = execSync ( `sh ${ scriptPath } ` , { cwd : projectRoot , encoding : 'utf-8' } ) ;
45+ //const output = execSync(`sh ${scriptPath}`, { cwd: projectRoot, encoding: 'utf-8' });
46+ const baseRefForScript = process . env . GIT_BASE_REF ;
47+ let commandToExecute = `bash ${ scriptPath } ` ; // Use bash to ensure consistency with shebang
48+ if ( baseRefForScript ) {
49+ commandToExecute = `bash ${ scriptPath } "${ baseRefForScript } "` ;
50+ }
51+ console . log ( `Executing: ${ commandToExecute } ` ) ;
52+ const output = execSync ( commandToExecute , { cwd : projectRoot , encoding : 'utf-8' } ) ;
4653
47- // Get all folder names outputted by the script
48- const rawChangedFolders = output . trim ( ) . split ( '\n' ) ;
49- // Filter out empty strings that might result from multiple newlines or a trailing newline
50- const changedFolders = rawChangedFolders . filter ( folder => folder . trim ( ) . length > 0 ) ;
51-
52- if ( changedFolders . length === 0 ) {
53- // This means find-changes.sh ran successfully and reported no changes.
54- console . log ( "find-changes.sh reported no changed folders. Skipping tests." ) ;
55- return [ ] ;
54+ const outputLines = output . trim ( ) . split ( '\n' ) ;
55+ const changedFolders : string [ ] = [ ] ;
56+ const markerLine = "Changed (added or modified) subfolders in 'samples/':" ;
57+ let foundMarker = false ;
58+
59+ for ( const line of outputLines ) {
60+ if ( foundMarker ) {
61+ const folderName = line . trim ( ) ;
62+ if ( folderName . length > 0 ) {
63+ changedFolders . push ( folderName ) ;
64+ }
65+ }
66+ if ( line . trim ( ) === markerLine ) {
67+ foundMarker = true ;
68+ }
69+ }
70+
71+ if ( ! foundMarker || changedFolders . length === 0 ) {
72+ console . log ( "No changed sample folders identified from find-changes.sh output in the expected format. Skipping tests." ) ;
73+ console . log ( "Full output from find-changes.sh for debugging:\n" , output ) ;
74+ return [ ] ;
5675 }
5776
5877 // Validate that changed folders actually exist in samplesDir
@@ -61,17 +80,19 @@ const getChangedSampleFolders = (): string[] => {
6180 return fs . existsSync ( folderPath ) && fs . statSync ( folderPath ) . isDirectory ( ) ;
6281 } ) ;
6382
64- if ( validChangedFolders . length === 0 && changedFolders . length > 0 && changedFolders [ 0 ] !== "" ) {
65- console . warn ( "find-changes.sh outputted folder names, but none are valid sample directories. Running for all samples." ) ;
66- return [ ] ;
83+ if ( validChangedFolders . length === 0 ) {
84+ console . warn ( "Folder names were extracted from find-changes.sh output, but none are valid sample directories. Skipping tests." ) ;
85+ console . log ( "Extracted folder names that were considered invalid:" , changedFolders ) ;
86+ console . log ( "Full output from find-changes.sh for debugging:\n" , output ) ;
87+ return [ ] ; // Fallback to do nothing
6788 }
6889
6990 console . log ( "Running tests only for changed samples: " , validChangedFolders ) ;
7091 return validChangedFolders ;
7192
7293 } catch ( error ) {
73- console . error ( "Error running find-changes.sh, falling back to all samples :" , error ) ;
74- return getAllSampleFolders ( ) ;
94+ console . error ( "Error running find-changes.sh. Skipping tests :" , error ) ;
95+ return [ ] ; // Fallback to do nothing
7596 }
7697} ;
7798
0 commit comments