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 8 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
15 changes: 15 additions & 0 deletions __tests__/installer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,21 @@ describe('setup-node', () => {

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

expect(getExecOutputSpy).toHaveBeenCalledWith(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dmitry-shibanov don't you think such check is better?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you

'node',
['--version'],
expect.anything()
);
expect(getExecOutputSpy).toHaveBeenCalledWith(
'npm',
['--version'],
expect.anything()
);
expect(getExecOutputSpy).toHaveBeenCalledWith(
'yarn',
['--version'],
expect.anything()
);
expect(dlSpy).toHaveBeenCalled();
expect(exSpy).toHaveBeenCalled();
expect(logSpy).toHaveBeenCalledWith(
Expand Down
42 changes: 34 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,39 @@ function resolveVersionInput() {
}
return version;
}
function printEnvDetailsAndSetOutput() {
return __awaiter(this, void 0, void 0, function* () {
core.startGroup('Environment details');
const promises = ['node', 'npm', 'yarn'].map((tool) => __awaiter(this, void 0, void 0, function* () {
const output = yield getToolVersion(tool, ['--version']);
if (tool === 'node') {
core.setOutput(`${tool}-version`, output);
}
core.info(`${tool}: ${output}`);
}));
yield Promise.all(promises);
core.endGroup();
});
}
exports.printEnvDetailsAndSetOutput = printEnvDetailsAndSetOutput;
function getToolVersion(tool, options) {
return __awaiter(this, void 0, void 0, function* () {
try {
const { stdout, stderr, exitCode } = yield exec.getExecOutput(tool, options, {
ignoreReturnCode: true,
silent: true
});
if (exitCode > 0) {
core.warning(`[warning]${stderr}`);
return '';
}
return stdout;
}
catch (err) {
return '';
}
});
}


/***/ }),
Expand Down
48 changes: 37 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,39 @@ function resolveVersionInput(): string {

return version;
}

export async function printEnvDetailsAndSetOutput() {
core.startGroup('Environment details');

const promises = ['node', 'npm', 'yarn'].map(async tool => {
const output = await getToolVersion(tool, ['--version']);

if (tool === 'node') {
core.setOutput(`${tool}-version`, output);
}

core.info(`${tool}: ${output}`);
});

await Promise.all(promises);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't check it 😄

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank yo


core.endGroup();
}

async function getToolVersion(tool: string, options: string[]) {
try {
const {stdout, stderr, exitCode} = await exec.getExecOutput(tool, options, {
ignoreReturnCode: true,
silent: true
});

if (exitCode > 0) {
core.warning(`[warning]${stderr}`);
return '';
}

return stdout;
} catch (err) {
return '';
}
}