Skip to content

Commit d662638

Browse files
committed
Fix CI tests for missing baseline schemas
- Handle missing schema files in base branch gracefully - Skip baseline application when no baseline schema exists - Return empty string instead of creating empty file for missing schemas - Only clean up temp files that actually exist
1 parent 6aa6d09 commit d662638

File tree

3 files changed

+28
-13
lines changed

3 files changed

+28
-13
lines changed

dist/index.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,9 @@ async function getSchemaFromBranch(branch, schemaFile) {
185185
if (exitCode !== 0) {
186186
// If the file doesn't exist in the base branch, return empty schema
187187
core.warning(`Could not find ${schemaFile} in ${branch}, using empty baseline schema`);
188-
fs.writeFileSync(tempFile, "-- Empty baseline schema\n");
188+
// Return empty string to signal no baseline exists
189+
fs.unlinkSync(tempFile);
190+
return "";
189191
}
190192
return tempFile;
191193
}
@@ -281,10 +283,16 @@ async function run() {
281283
else {
282284
core.info(`Using provided baseline schema file: ${actualBaselineFile}`);
283285
}
284-
const baselineConfig = { ...config };
285-
baselineConfig.args = baselineConfig.args.map((arg) => (arg === schemaFile ? actualBaselineFile : arg));
286-
core.info("Applying baseline schema to database");
287-
await runSqldef(binaryPath, baselineConfig);
286+
// Only apply baseline if we have a valid file
287+
if (actualBaselineFile && actualBaselineFile !== "") {
288+
const baselineConfig = { ...config };
289+
baselineConfig.args = baselineConfig.args.map((arg) => (arg === schemaFile ? actualBaselineFile : arg));
290+
core.info("Applying baseline schema to database");
291+
await runSqldef(binaryPath, baselineConfig);
292+
}
293+
else {
294+
core.info("No baseline schema found, skipping baseline application");
295+
}
288296
core.info("Applying desired schema to database");
289297
const output = await runSqldef(binaryPath, config);
290298
if (output.trim()) {
@@ -296,7 +304,7 @@ async function run() {
296304
core.info("No schema changes detected");
297305
await createComment("No schema changes detected.");
298306
}
299-
if (!baselineSchemaFile && fs.existsSync(actualBaselineFile)) {
307+
if (!baselineSchemaFile && actualBaselineFile && actualBaselineFile !== "" && fs.existsSync(actualBaselineFile)) {
300308
fs.unlinkSync(actualBaselineFile);
301309
}
302310
}

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,9 @@ async function getSchemaFromBranch(branch: string, schemaFile: string): Promise<
161161
if (exitCode !== 0) {
162162
// If the file doesn't exist in the base branch, return empty schema
163163
core.warning(`Could not find ${schemaFile} in ${branch}, using empty baseline schema`);
164-
fs.writeFileSync(tempFile, "-- Empty baseline schema\n");
164+
// Return empty string to signal no baseline exists
165+
fs.unlinkSync(tempFile);
166+
return "";
165167
}
166168

167169
return tempFile;
@@ -278,11 +280,16 @@ async function run(): Promise<void> {
278280
core.info(`Using provided baseline schema file: ${actualBaselineFile}`);
279281
}
280282

281-
const baselineConfig = { ...config };
282-
baselineConfig.args = baselineConfig.args.map((arg) => (arg === schemaFile ? actualBaselineFile : arg));
283+
// Only apply baseline if we have a valid file
284+
if (actualBaselineFile && actualBaselineFile !== "") {
285+
const baselineConfig = { ...config };
286+
baselineConfig.args = baselineConfig.args.map((arg) => (arg === schemaFile ? actualBaselineFile : arg));
283287

284-
core.info("Applying baseline schema to database");
285-
await runSqldef(binaryPath, baselineConfig);
288+
core.info("Applying baseline schema to database");
289+
await runSqldef(binaryPath, baselineConfig);
290+
} else {
291+
core.info("No baseline schema found, skipping baseline application");
292+
}
286293

287294
core.info("Applying desired schema to database");
288295
const output = await runSqldef(binaryPath, config);
@@ -296,7 +303,7 @@ async function run(): Promise<void> {
296303
await createComment("No schema changes detected.");
297304
}
298305

299-
if (!baselineSchemaFile && fs.existsSync(actualBaselineFile)) {
306+
if (!baselineSchemaFile && actualBaselineFile && actualBaselineFile !== "" && fs.existsSync(actualBaselineFile)) {
300307
fs.unlinkSync(actualBaselineFile);
301308
}
302309
} else {

0 commit comments

Comments
 (0)