Skip to content

fix: default version populated and fetch summary files only after install attempt #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/main/index.js

Large diffs are not rendered by default.

68 changes: 34 additions & 34 deletions src/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,44 +32,44 @@ function findOrDownloadTool(config: VersionConfig): Promise<string> {
}

export default async function install() {
try {
const { version, password, collation, installArgs, wait, skipOsCheck } = gatherInputs();
// we only support windows for now. But allow crazy people to skip this check if they like...
if (!skipOsCheck && os.platform() !== 'win32') {
throw new Error(`setup-sqlserver only supports Windows runners, got: ${os.platform()}`);
}
const osVersion = await getOsVersion();
if (!VERSIONS.has(version)) {
throw new Error(`Unsupported SQL Version, supported versions are ${Array.from(VERSIONS.keys()).join(', ')}, got: ${version}`);
}
const config = VERSIONS.get(version)!;
// try to fail fast if the OS is not supported
if (config.osSupport) {
const { min, max } = config.osSupport;
// allow checks to be skipped
if (skipOsCheck) {
core.info('Skipping OS checks');
} else if (!osVersion) {
core.notice('Unable to determine OS version, continuing tentatively');
} else if ((min && min > osVersion) || (max && max < osVersion)) {
// construct a helpful error
let message = 'Please use ';
const { version, password, collation, installArgs, wait, skipOsCheck } = gatherInputs();
// we only support windows for now. But allow crazy people to skip this check if they like...
if (!skipOsCheck && os.platform() !== 'win32') {
throw new Error(`setup-sqlserver only supports Windows runners, got: ${os.platform()}`);
}
const osVersion = await getOsVersion();
if (!VERSIONS.has(version)) {
throw new Error(`Unsupported SQL Version, supported versions are ${Array.from(VERSIONS.keys()).join(', ')}, got: ${version}`);
}
const config = VERSIONS.get(version)!;
// try to fail fast if the OS is not supported
if (config.osSupport) {
const { min, max } = config.osSupport;
// allow checks to be skipped
if (skipOsCheck) {
core.info('Skipping OS checks');
} else if (!osVersion) {
core.notice('Unable to determine OS version, continuing tentatively');
} else if ((min && min > osVersion) || (max && max < osVersion)) {
// construct a helpful error
let message = 'Please use ';
if (min) {
message += `windows-${min}`;
}
if (max) {
if (min) {
message += `windows-${min}`;
}
if (max) {
if (min) {
message += ' to ';
}
message += `windows-${max}`;
message += ' to ';
}
message += '.';
throw new Error(`Runner version windows-${osVersion} is not supported for SQL Server ${version}. ${message}`);
message += `windows-${max}`;
}
message += '.';
throw new Error(`Runner version windows-${osVersion} is not supported for SQL Server ${version}. ${message}`);
}
// Initial checks complete - fetch the installer
const toolPath = await core.group(`Fetching install media for ${version}`, () => findOrDownloadTool(config));
const instanceName = 'MSSQLSERVER';
}
// Initial checks complete - fetch the installer
const toolPath = await core.group(`Fetching install media for ${version}`, () => findOrDownloadTool(config));
const instanceName = 'MSSQLSERVER';
try {
// @todo - make sure that the arguments are unique / don't conflict
await core.group('Installing SQL Server', () => exec.exec(`"${toolPath}"`, [
'/q',
Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export interface Inputs {
* @returns {Inputs}
*/
export function gatherInputs(): Inputs {
const version = core.getInput('sqlserver-version').replace(/sql-/i, '');
const version = core.getInput('sqlserver-version').replace(/sql-/i, '') || 'latest';
return {
version: version.toLowerCase() === 'latest' ? '2022' : version,
password: core.getInput('sa-password'),
Expand Down
17 changes: 17 additions & 0 deletions test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,23 @@ describe('utils', () => {
skipOsCheck: false,
});
});
it('constructs input object with default version', () => {
coreStub.getInput.withArgs('sqlserver-version').returns('');
coreStub.getInput.withArgs('sa-password').returns('secret password');
coreStub.getInput.withArgs('db-collation').returns('SQL_Latin1_General_CP1_CI_AS');
coreStub.getMultilineInput.withArgs('install-arguments').returns([]);
coreStub.getBooleanInput.withArgs('wait-for-ready').returns(true);
coreStub.getBooleanInput.withArgs('skip-os-check').returns(false);
const res = utils.gatherInputs();
expect(res).to.deep.equal({
version: '2022',
password: 'secret password',
collation: 'SQL_Latin1_General_CP1_CI_AS',
installArgs: [],
wait: true,
skipOsCheck: false,
});
});
});
describe('.downloadTool()', () => {
let downloadStub: SinonStubbedMember<typeof tc.downloadTool>;
Expand Down