Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
14 changes: 14 additions & 0 deletions __tests__/installer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ describe('setup-node', () => {
let parseNodeVersionSpy: jest.SpyInstance;
let isCacheActionAvailable: jest.SpyInstance;
let getExecOutputSpy: jest.SpyInstance;
let execExecSpy: jest.SpyInstance;

beforeEach(() => {
// @actions/core
Expand All @@ -57,6 +58,7 @@ describe('setup-node', () => {
archSpy = jest.spyOn(osm, 'arch');
archSpy.mockImplementation(() => os['arch']);
execSpy = jest.spyOn(cp, 'execSync');
execExecSpy = jest.spyOn(exec, 'exec');

// @actions/tool-cache
findSpy = jest.spyOn(tc, 'find');
Expand Down Expand Up @@ -249,6 +251,18 @@ describe('setup-node', () => {

let expPath = path.join(toolPath, 'bin');

expect(execExecSpy).toHaveBeenCalledWith('node', ['--version']);
expect(execExecSpy).toHaveBeenCalledWith(
'npm',
['--version'],
expect.anything()
);
expect(execExecSpy).toHaveBeenCalledWith(
'yarn',
['--version'],
expect.anything()
);

expect(dlSpy).toHaveBeenCalled();
expect(exSpy).toHaveBeenCalled();
expect(logSpy).toHaveBeenCalledWith(
Expand Down
43 changes: 35 additions & 8 deletions dist/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71855,14 +71855,7 @@ function run() {
const checkLatest = (core.getInput('check-latest') || 'false').toUpperCase() === 'TRUE';
yield installer.getNode(version, stable, checkLatest, auth, arch);
}
// Output version of node is being used
try {
const { stdout: installedVersion } = yield exec.getExecOutput('node', ['--version'], { ignoreReturnCode: true, silent: true });
core.setOutput('node-version', installedVersion.trim());
}
catch (err) {
core.setOutput('node-version', '');
}
yield printEnvDetailsAndSetOutput();
const registryUrl = core.getInput('registry-url');
const alwaysAuth = core.getInput('always-auth');
if (registryUrl) {
Expand Down Expand Up @@ -71902,6 +71895,40 @@ function resolveVersionInput() {
}
return version;
}
function printEnvDetailsAndSetOutput() {
return __awaiter(this, void 0, void 0, function* () {
core.startGroup('Environment details');
// Output version of node is being used
try {
const { stdout: installedNodeVersion } = yield exec.getExecOutput('node', ['--version'], { ignoreReturnCode: true, silent: true });
core.setOutput('node-version', installedNodeVersion.trim());
}
catch (err) {
core.setOutput('node-version', '');
}
try {
const { stdout: installedNpmVersion } = yield exec.getExecOutput('npm', ['--version'], {
ignoreReturnCode: true,
silent: true
});
core.setOutput('npm-version', installedNpmVersion.trim());
}
catch (_a) {
core.setOutput('npm-version', '');
}
try {
const { stdout: installedYarnVersion } = yield exec.getExecOutput('yarn', ['--version'], {
ignoreReturnCode: true,
silent: true
});
core.setOutput('yarn-version', installedYarnVersion.trim());
}
catch (_b) {
core.setOutput('yarn-version', '');
}
core.endGroup();
});
}


/***/ }),
Expand Down
56 changes: 45 additions & 11 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,7 @@ export async function run() {
await installer.getNode(version, stable, checkLatest, auth, arch);
}

// Output version of node is being used
try {
const {stdout: installedVersion} = await exec.getExecOutput(
'node',
['--version'],
{ignoreReturnCode: true, silent: true}
);
core.setOutput('node-version', installedVersion.trim());
} catch (err) {
core.setOutput('node-version', '');
}
await printEnvDetailsAndSetOutput();

const registryUrl: string = core.getInput('registry-url');
const alwaysAuth: string = core.getInput('always-auth');
Expand Down Expand Up @@ -108,3 +98,47 @@ function resolveVersionInput(): string {

return version;
}

async function printEnvDetailsAndSetOutput() {
core.startGroup('Environment details');
// Output version of node is being used
try {
const {stdout: installedNodeVersion} = await exec.getExecOutput(
'node',
['--version'],
{ignoreReturnCode: true, silent: true}
);
core.setOutput('node-version', installedNodeVersion.trim());
} catch (err) {
core.setOutput('node-version', '');
}
try {
const {stdout: installedNpmVersion} = await exec.getExecOutput(
'npm',
['--version'],
{
ignoreReturnCode: true,
silent: true
}
);
core.setOutput('npm-version', installedNpmVersion.trim());
} catch {
core.setOutput('npm-version', '');
}

try {
const {stdout: installedYarnVersion} = await exec.getExecOutput(
'yarn',
['--version'],
{
ignoreReturnCode: true,
silent: true
}
);
core.setOutput('yarn-version', installedYarnVersion.trim());
} catch {
core.setOutput('yarn-version', '');
}

core.endGroup();
}