Skip to content
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

chore(deps): bump @actions/core from 1.10.1 to 1.11.1 in the action-tools group #77

Merged
merged 2 commits into from
Oct 8, 2024
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
6 changes: 3 additions & 3 deletions lib/main/index.js

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"typescript": "^5.6.2"
},
"dependencies": {
"@actions/core": "^1.10.0",
"@actions/core": "^1.11.1",
"@actions/exec": "^1.1.1",
"@actions/glob": "^0.5.0",
"@actions/http-client": "^2.2.3",
Expand Down
5 changes: 2 additions & 3 deletions src/install.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os from 'os';
import { basename, dirname, join as joinPaths } from 'path';
import { readFile } from 'fs/promises';
import * as core from '@actions/core';
Expand Down Expand Up @@ -57,8 +56,8 @@ export default async function install() {
installUpdates,
} = 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()}`);
if (!skipOsCheck && core.platform.platform !== 'win32') {
throw new Error(`setup-sqlserver only supports Windows runners, got: ${core.platform.platform}`);
}
const osVersion = await getOsVersion();
if (!VERSIONS.has(version)) {
Expand Down
18 changes: 6 additions & 12 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,17 @@ import * as glob from '@actions/glob';
*/
export async function getOsVersion() {
try {
const systeminfo = await exec.getExecOutput('systeminfo', [], {
silent: true,
});
const systeminfo = await core.platform.getDetails();
// output the systeminfo in debug mode
if (core.isDebug()) {
core.startGroup('systeminfo');
core.debug(systeminfo.stdout);
core.debug(Object.entries(systeminfo).map((tuple) => tuple.join(': ')).join('\n'));
core.endGroup();
}
// try to parse out the os name
const matches = systeminfo.stdout.match(/os name:\s+(.*)/i);
if (matches) {
// parse the "version" (year)
const version = matches[1].match(/([0-9]+)/);
if (version) {
return parseInt(version[1], 10);
}
// parse the "version" (year)
const version = systeminfo.name.match(/([0-9]+)/);
if (version) {
return parseInt(version[1], 10);
}
} catch (e) {
// don't throw errors, so the action can be as permissive as possible
Expand Down
11 changes: 6 additions & 5 deletions test/install.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os from 'node:os';
import fs from 'fs/promises';
import * as core from '@actions/core';
import * as tc from '@actions/tool-cache';
Expand All @@ -16,7 +15,6 @@ use(sinonChai);
describe('install', () => {
let reverts: (() => void)[] = [];
let versionStub: SinonStubbedInstance<Map<string, versions.VersionConfig>>;
let osStub: SinonStubbedInstance<typeof os>;
let coreStub: SinonStubbedInstance<typeof core>;
let utilsStub: SinonStubbedInstance<typeof utils>;
let tcStub: SinonStubbedInstance<typeof tc>;
Expand Down Expand Up @@ -82,12 +80,13 @@ describe('install', () => {
utilsStub.downloadBoxInstaller.resolves('C:/tmp/box/setup.exe');
utilsStub.downloadUpdateInstaller.resolves('C:/tmp/exe/sqlupdate.exe');
utilsStub.waitForDatabase.resolves(0);
osStub = stub(os);
osStub.platform.returns('win32');
coreStub = stub(core);
coreStub.group.callsFake((message, cb) => {
return cb();
});
stub(coreStub, 'platform').value({
platform: 'win32',
});
tcStub = stub(tc);
tcStub.find.returns('');
execStub = stub(exec);
Expand All @@ -99,7 +98,9 @@ describe('install', () => {
reverts = [];
});
it('fails if bad os', async () => {
osStub.platform.returns('linux');
stub(coreStub, 'platform').value({
platform: 'linux',
});
try {
await install();
} catch (e) {
Expand Down
157 changes: 28 additions & 129 deletions test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,137 +14,41 @@ import * as utils from '../src/utils';
import * as crypto from '../src/crypto';
use(sinonChai);

const windows2022 = `
Host Name: fv-az618-92
OS Name: Microsoft Windows Server 2022 Datacenter
OS Version: 10.0.20348 N/A Build 20348
OS Manufacturer: Microsoft Corporation
OS Configuration: Standalone Server
OS Build Type: Multiprocessor Free
Registered Owner: N/A
Registered Organization: N/A
Product ID: 00454-60000-00001-AA926
Original Install Date: 8/8/2023, 9:08:26 AM
System Boot Time: 8/9/2023, 3:13:18 PM
System Manufacturer: Microsoft Corporation
System Model: Virtual Machine
System Type: x64-based PC
Processor(s): 1 Processor(s) Installed.
[01]: Intel64 Family 6 Model 79 Stepping 1 GenuineIntel ~2295 Mhz
BIOS Version: American Megatrends Inc. 090008 , 12/7/2018
Windows Directory: C:\\Windows
System Directory: C:\\Windows\\system32
Boot Device: \\Device\\HarddiskVolume1
System Locale: en-us;English (United States)
Input Locale: en-us;English (United States)
Time Zone: (UTC) Coordinated Universal Time
Total Physical Memory: 7,168 MB
Available Physical Memory: 5,426 MB
Virtual Memory: Max Size: 8,959 MB
Virtual Memory: Available: 7,373 MB
Virtual Memory: In Use: 1,586 MB
Page File Location(s): D:\\pagefile.sys
Domain: WORKGROUP
Logon Server: \\\\fv-az618-92
Hotfix(s): 5 Hotfix(s) Installed.
[01]: KB5028852
[02]: KB5028858
[03]: KB5011048
[04]: KB5028171
[05]: KB5028317
Network Card(s): 1 NIC(s) Installed.
[01]: Microsoft Hyper-V Network Adapter
Connection Name: Ethernet
DHCP Enabled: Yes
DHCP Server: 168.63.129.16
IP address(es)
[01]: 10.1.0.141
[02]: fe80::deb6:64f:8300:ef77
Hyper-V Requirements: A hypervisor has been detected. Features required for Hyper-V will not be displayed.
`;

const windows2019 = `
Host Name: fv-az276-691
OS Name: Microsoft Windows Server 2019 Datacenter
OS Version: 10.0.17763 N/A Build 17763
OS Manufacturer: Microsoft Corporation
OS Configuration: Standalone Server
OS Build Type: Multiprocessor Free
Registered Owner: N/A
Registered Organization: N/A
Product ID: 00430-00000-00000-AA138
Original Install Date: 8/3/2023, 10:11:03 AM
System Boot Time: 8/9/2023, 3:19:20 PM
System Manufacturer: Microsoft Corporation
System Model: Virtual Machine
System Type: x64-based PC
Processor(s): 1 Processor(s) Installed.
[01]: Intel64 Family 6 Model 63 Stepping 2 GenuineIntel ~2394 Mhz
BIOS Version: American Megatrends Inc. 090008 , 12/7/2018
Windows Directory: C:\\Windows
System Directory: C:\\Windows\\system32
Boot Device: \\Device\\HarddiskVolume1
System Locale: en-us;English (United States)
Input Locale: en-us;English (United States)
Time Zone: (UTC) Coordinated Universal Time
Total Physical Memory: 7,168 MB
Available Physical Memory: 5,543 MB
Virtual Memory: Max Size: 8,959 MB
Virtual Memory: Available: 7,426 MB
Virtual Memory: In Use: 1,533 MB
Page File Location(s): D:\\pagefile.sys
Domain: WORKGROUP
Logon Server: \\\\fv-az276-691
Hotfix(s): 6 Hotfix(s) Installed.
[01]: KB5028855
[02]: KB4486153
[03]: KB4589208
[04]: KB5004424
[05]: KB5028168
[06]: KB5028316
Network Card(s): 2 NIC(s) Installed.
[01]: Hyper-V Virtual Ethernet Adapter
Connection Name: vEthernet (nat)
DHCP Enabled: No
IP address(es)
[01]: 172.27.224.1
[02]: fe80::39cd:87ac:c9ad:cd5e
[02]: Microsoft Hyper-V Network Adapter
Connection Name: Ethernet 2
DHCP Enabled: Yes
DHCP Server: 168.63.129.16
IP address(es)
[01]: 10.1.36.0
[02]: fe80::ae04:627e:a23b:d046
Hyper-V Requirements: A hypervisor has been detected. Features required for Hyper-V will not be displayed.
`;
describe('utils', () => {
let coreStub: SinonStubbedInstance<typeof core>;
let platformStub: SinonStubbedInstance<typeof core.platform>;
beforeEach('stub core', () => {
platformStub = stub(core.platform);
coreStub = stub(core);
});
afterEach('restore stubs', () => {
restore();
});
describe('.getOsVersion()', () => {
let getExecOutput: SinonStubbedMember<typeof exec.getExecOutput>;
beforeEach('stub debs', () => {
getExecOutput = stub(exec, 'getExecOutput');
getExecOutput.withArgs('systeminfo').resolves({
exitCode: 0,
stdout: windows2019,
stderr: '',
platformStub.getDetails.resolves({
name: 'Microsoft Windows Server 2019 Datacenter',
platform: 'win32',
arch: 'x64',
version: '10.0.17763',
isWindows: true,
isMacOS: false,
isLinux: false,
});
});
it('correctly returns for windows-2019', async () => {
const out = await utils.getOsVersion();
expect(out).to.equal(2019);
});
it('correctly returns for windows-2022', async () => {
getExecOutput.withArgs('systeminfo').resolves({
exitCode: 0,
stdout: windows2022,
stderr: '',
platformStub.getDetails.resolves({
name: 'Microsoft Windows Server 2022 Datacenter',
platform: 'win32',
arch: 'x64',
version: '10.0.20348',
isWindows: true,
isMacOS: false,
isLinux: false,
});
const out = await utils.getOsVersion();
expect(out).to.equal(2022);
Expand All @@ -154,30 +58,25 @@ describe('utils', () => {
await utils.getOsVersion();
expect(coreStub.isDebug).to.have.callCount(1);
expect(coreStub.startGroup).to.have.been.calledOnceWith('systeminfo');
expect(coreStub.debug).to.have.been.calledOnceWith(windows2019);
expect(coreStub.debug).to.have.been.calledOnceWith("name: Microsoft Windows Server 2019 Datacenter\nplatform: win32\narch: x64\nversion: 10.0.17763\nisWindows: true\nisMacOS: false\nisLinux: false");
expect(coreStub.endGroup).to.have.callCount(1);
});
it('fails gracefully when error is thrown', async () => {
const err = new Error('synthetic error');
getExecOutput.withArgs('systeminfo').rejects(err);
platformStub.getDetails.rejects(err);
const res = await utils.getOsVersion();
expect(res).to.equal(null);
expect(coreStub.warning).to.have.been.calledOnceWithExactly(err);
});
it('fails gracefully with bad output', async () => {
getExecOutput.withArgs('systeminfo').resolves({
exitCode: 0,
stdout: 'os name: not a number',
stderr: '',
});
const res = await utils.getOsVersion();
expect(res).to.equal(null);
});
it('fails gracefully with no output', async () => {
getExecOutput.withArgs('systeminfo').resolves({
exitCode: 0,
stdout: '',
stderr: '',
platformStub.getDetails.resolves({
name: 'not a number',
platform: 'win32',
arch: 'x64',
version: '10.0.20348',
isWindows: true,
isMacOS: false,
isLinux: false,
});
const res = await utils.getOsVersion();
expect(res).to.equal(null);
Expand Down