Skip to content

Commit 1e527da

Browse files
authored
Merge pull request #3 from dhensby/pulls/fix-default-version
fix: default version populated and fetch summary files only after install attempt
2 parents 1956129 + 382ee7d commit 1e527da

File tree

4 files changed

+53
-36
lines changed

4 files changed

+53
-36
lines changed

lib/main/index.js

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/install.ts

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -32,44 +32,44 @@ function findOrDownloadTool(config: VersionConfig): Promise<string> {
3232
}
3333

3434
export default async function install() {
35-
try {
36-
const { version, password, collation, installArgs, wait, skipOsCheck } = gatherInputs();
37-
// we only support windows for now. But allow crazy people to skip this check if they like...
38-
if (!skipOsCheck && os.platform() !== 'win32') {
39-
throw new Error(`setup-sqlserver only supports Windows runners, got: ${os.platform()}`);
40-
}
41-
const osVersion = await getOsVersion();
42-
if (!VERSIONS.has(version)) {
43-
throw new Error(`Unsupported SQL Version, supported versions are ${Array.from(VERSIONS.keys()).join(', ')}, got: ${version}`);
44-
}
45-
const config = VERSIONS.get(version)!;
46-
// try to fail fast if the OS is not supported
47-
if (config.osSupport) {
48-
const { min, max } = config.osSupport;
49-
// allow checks to be skipped
50-
if (skipOsCheck) {
51-
core.info('Skipping OS checks');
52-
} else if (!osVersion) {
53-
core.notice('Unable to determine OS version, continuing tentatively');
54-
} else if ((min && min > osVersion) || (max && max < osVersion)) {
55-
// construct a helpful error
56-
let message = 'Please use ';
35+
const { version, password, collation, installArgs, wait, skipOsCheck } = gatherInputs();
36+
// we only support windows for now. But allow crazy people to skip this check if they like...
37+
if (!skipOsCheck && os.platform() !== 'win32') {
38+
throw new Error(`setup-sqlserver only supports Windows runners, got: ${os.platform()}`);
39+
}
40+
const osVersion = await getOsVersion();
41+
if (!VERSIONS.has(version)) {
42+
throw new Error(`Unsupported SQL Version, supported versions are ${Array.from(VERSIONS.keys()).join(', ')}, got: ${version}`);
43+
}
44+
const config = VERSIONS.get(version)!;
45+
// try to fail fast if the OS is not supported
46+
if (config.osSupport) {
47+
const { min, max } = config.osSupport;
48+
// allow checks to be skipped
49+
if (skipOsCheck) {
50+
core.info('Skipping OS checks');
51+
} else if (!osVersion) {
52+
core.notice('Unable to determine OS version, continuing tentatively');
53+
} else if ((min && min > osVersion) || (max && max < osVersion)) {
54+
// construct a helpful error
55+
let message = 'Please use ';
56+
if (min) {
57+
message += `windows-${min}`;
58+
}
59+
if (max) {
5760
if (min) {
58-
message += `windows-${min}`;
59-
}
60-
if (max) {
61-
if (min) {
62-
message += ' to ';
63-
}
64-
message += `windows-${max}`;
61+
message += ' to ';
6562
}
66-
message += '.';
67-
throw new Error(`Runner version windows-${osVersion} is not supported for SQL Server ${version}. ${message}`);
63+
message += `windows-${max}`;
6864
}
65+
message += '.';
66+
throw new Error(`Runner version windows-${osVersion} is not supported for SQL Server ${version}. ${message}`);
6967
}
70-
// Initial checks complete - fetch the installer
71-
const toolPath = await core.group(`Fetching install media for ${version}`, () => findOrDownloadTool(config));
72-
const instanceName = 'MSSQLSERVER';
68+
}
69+
// Initial checks complete - fetch the installer
70+
const toolPath = await core.group(`Fetching install media for ${version}`, () => findOrDownloadTool(config));
71+
const instanceName = 'MSSQLSERVER';
72+
try {
7373
// @todo - make sure that the arguments are unique / don't conflict
7474
await core.group('Installing SQL Server', () => exec.exec(`"${toolPath}"`, [
7575
'/q',

src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export interface Inputs {
5656
* @returns {Inputs}
5757
*/
5858
export function gatherInputs(): Inputs {
59-
const version = core.getInput('sqlserver-version').replace(/sql-/i, '');
59+
const version = core.getInput('sqlserver-version').replace(/sql-/i, '') || 'latest';
6060
return {
6161
version: version.toLowerCase() === 'latest' ? '2022' : version,
6262
password: core.getInput('sa-password'),

test/utils.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,23 @@ describe('utils', () => {
234234
skipOsCheck: false,
235235
});
236236
});
237+
it('constructs input object with default version', () => {
238+
coreStub.getInput.withArgs('sqlserver-version').returns('');
239+
coreStub.getInput.withArgs('sa-password').returns('secret password');
240+
coreStub.getInput.withArgs('db-collation').returns('SQL_Latin1_General_CP1_CI_AS');
241+
coreStub.getMultilineInput.withArgs('install-arguments').returns([]);
242+
coreStub.getBooleanInput.withArgs('wait-for-ready').returns(true);
243+
coreStub.getBooleanInput.withArgs('skip-os-check').returns(false);
244+
const res = utils.gatherInputs();
245+
expect(res).to.deep.equal({
246+
version: '2022',
247+
password: 'secret password',
248+
collation: 'SQL_Latin1_General_CP1_CI_AS',
249+
installArgs: [],
250+
wait: true,
251+
skipOsCheck: false,
252+
});
253+
});
237254
});
238255
describe('.downloadTool()', () => {
239256
let downloadStub: SinonStubbedMember<typeof tc.downloadTool>;

0 commit comments

Comments
 (0)