Skip to content

Commit 55f2add

Browse files
authored
fix: Minor fixes to make test workflow work again. (#546)
1 parent 54e5012 commit 55f2add

File tree

3 files changed

+49
-15
lines changed

3 files changed

+49
-15
lines changed

.github/workflows/playwright.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ jobs:
107107
- name: Run All Playwright Tests
108108
run: npx playwright test e2e/samples.spec.ts
109109
env:
110+
# Pass the correct base reference for find-changes.sh
111+
GIT_BASE_REF: ${{ github.event_name == 'pull_request' && github.base_ref || 'origin/main' }}
110112
CI: true
111113

112114
- name: Upload Test Report Artifact

e2e/samples.spec.ts

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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

samples/find-changes.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,17 @@ if [ -z "$UNIQUE_CHANGED_WORKSPACES" ]; then
6262
exit 0
6363
fi
6464

65+
# --- Post-process UNIQUE_CHANGED_WORKSPACES to remove any '-e ' prefix ---
66+
# This addresses an observed issue where folder names might be unexpectedly prefixed.
67+
CLEANED_WORKSPACES_BUFFER=""
68+
while IFS= read -r line; do
69+
if [ -n "$line" ]; then # Process only non-empty lines
70+
cleaned_line=$(echo "$line" | sed 's/^-e[[:space:]]*//') # Match -e followed by zero or more spaces
71+
CLEANED_WORKSPACES_BUFFER+="$cleaned_line\n"
72+
fi
73+
done <<< "$UNIQUE_CHANGED_WORKSPACES"
74+
UNIQUE_CHANGED_WORKSPACES=$(echo -e "$CLEANED_WORKSPACES_BUFFER" | sed '/^$/d') # Remove any trailing empty line
75+
6576
echo "Changed (added or modified) subfolders in '$PROJECTS_ROOT_DIR':"
6677
echo "$UNIQUE_CHANGED_WORKSPACES"
6778

0 commit comments

Comments
 (0)