Skip to content

Commit 6aa6d09

Browse files
committed
Fix CI failures and update MSSQL to stable 2019 version
- Fix getSchemaFromBranch to handle missing files in base branch gracefully - Use empty baseline schema when file doesn't exist in main branch - Update MSSQL to stable 2019-CU32-ubuntu-20.04 version (used for sqldef development) - Fix sqlcmd paths for MSSQL 2019 version - Rebuild dist/index.js with all fixes
1 parent 7391844 commit 6aa6d09

File tree

4 files changed

+39
-8
lines changed

4 files changed

+39
-8
lines changed

.github/workflows/example.yaml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,13 @@ jobs:
109109

110110
services:
111111
sqlserver:
112-
image: mcr.microsoft.com/mssql/server:2022-latest
112+
image: mcr.microsoft.com/mssql/server:2019-CU32-ubuntu-20.04
113113
env:
114114
ACCEPT_EULA: Y
115115
SA_PASSWORD: YourStrong@Passw0rd
116116
MSSQL_PID: Developer
117117
options: >-
118-
--health-cmd "/opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -P 'YourStrong@Passw0rd' -Q 'SELECT 1' -No"
118+
--health-cmd "/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P 'YourStrong@Passw0rd' -Q 'SELECT 1'"
119119
--health-interval 10s
120120
--health-timeout 5s
121121
--health-retries 10
@@ -130,13 +130,12 @@ jobs:
130130

131131
- name: Wait for SQL Server
132132
run: |
133-
sudo apt-get update && sudo apt-get install -y mssql-tools18
134133
for i in {1..30}; do
135-
/opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -P 'YourStrong@Passw0rd' -Q 'SELECT 1' -No && break
134+
/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P 'YourStrong@Passw0rd' -Q 'SELECT 1' && break
136135
echo "Waiting for SQL Server..."
137136
sleep 2
138137
done
139-
/opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -P 'YourStrong@Passw0rd' -Q "CREATE DATABASE testdb" -No
138+
/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P 'YourStrong@Passw0rd' -Q "CREATE DATABASE testdb"
140139
141140
- name: Preview MSSQL schema changes
142141
uses: ./

dist/index.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,15 +163,30 @@ function getCommandConfig(command) {
163163
return config;
164164
}
165165
async function getSchemaFromBranch(branch, schemaFile) {
166-
const tempFile = path.join(os.tmpdir(), `schema-${branch}-${Date.now()}.sql`);
166+
const tempFile = path.join(os.tmpdir(), `schema-${branch.replace(/\//g, "-")}-${Date.now()}.sql`);
167+
// Create empty file first to ensure it exists
168+
fs.writeFileSync(tempFile, "");
169+
let exitCode = 0;
167170
await exec.exec("git", ["show", `${branch}:${schemaFile}`], {
168171
silent: true,
172+
ignoreReturnCode: true,
169173
listeners: {
170174
stdout: (data) => {
171175
fs.appendFileSync(tempFile, data);
172176
},
177+
stderr: (data) => {
178+
// Log stderr for debugging but don't fail
179+
core.debug(`git show stderr: ${data.toString()}`);
180+
},
173181
},
182+
}).catch((error) => {
183+
exitCode = error.exitCode || 1;
174184
});
185+
if (exitCode !== 0) {
186+
// If the file doesn't exist in the base branch, return empty schema
187+
core.warning(`Could not find ${schemaFile} in ${branch}, using empty baseline schema`);
188+
fs.writeFileSync(tempFile, "-- Empty baseline schema\n");
189+
}
175190
return tempFile;
176191
}
177192
async function runSqldef(binaryPath, config) {

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: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,17 +136,34 @@ function getCommandConfig(command: string): CommandConfig {
136136
}
137137

138138
async function getSchemaFromBranch(branch: string, schemaFile: string): Promise<string> {
139-
const tempFile = path.join(os.tmpdir(), `schema-${branch}-${Date.now()}.sql`);
139+
const tempFile = path.join(os.tmpdir(), `schema-${branch.replace(/\//g, "-")}-${Date.now()}.sql`);
140140

141+
// Create empty file first to ensure it exists
142+
fs.writeFileSync(tempFile, "");
143+
144+
let exitCode = 0;
141145
await exec.exec("git", ["show", `${branch}:${schemaFile}`], {
142146
silent: true,
147+
ignoreReturnCode: true,
143148
listeners: {
144149
stdout: (data: Buffer) => {
145150
fs.appendFileSync(tempFile, data);
146151
},
152+
stderr: (data: Buffer) => {
153+
// Log stderr for debugging but don't fail
154+
core.debug(`git show stderr: ${data.toString()}`);
155+
},
147156
},
157+
}).catch((error) => {
158+
exitCode = error.exitCode || 1;
148159
});
149160

161+
if (exitCode !== 0) {
162+
// If the file doesn't exist in the base branch, return empty schema
163+
core.warning(`Could not find ${schemaFile} in ${branch}, using empty baseline schema`);
164+
fs.writeFileSync(tempFile, "-- Empty baseline schema\n");
165+
}
166+
150167
return tempFile;
151168
}
152169

0 commit comments

Comments
 (0)