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

Print node, npm and yarn versions after installation #368

Merged
merged 10 commits into from Oct 3, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions __tests__/installer.test.ts
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;
havenchyk marked this conversation as resolved.
Show resolved Hide resolved

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']);
havenchyk marked this conversation as resolved.
Show resolved Hide resolved
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
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
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 {
havenchyk marked this conversation as resolved.
Show resolved Hide resolved
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();
}