Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Test output
  • Loading branch information
havenchyk committed Jul 31, 2022
commit 8ba370a949a3fb909752fe11e2d286bd359c8f69
6 changes: 6 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;
Comment thread
havenchyk marked this conversation as resolved.
Outdated

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,10 @@ describe('setup-node', () => {

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

expect(execExecSpy).toHaveBeenCalledWith('node', ['--version']);
Comment thread
havenchyk marked this conversation as resolved.
Outdated
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
40 changes: 29 additions & 11 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as auth from './authutil';
import * as path from 'path';
import {restoreCache} from './cache-restore';
import {isGhes, isCacheFeatureAvailable} from './cache-utils';
import { URL } from 'url';
import os = require('os');

export async function run() {
Expand Down Expand Up @@ -40,17 +41,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 +99,30 @@ function resolveVersionInput(): string {

return version;
}

async function printEnvDetailsAndSetOutput() {
const groupName = "Environment details";

core.startGroup(groupName);
// Output version of node is being used
try {
Comment thread
havenchyk marked this conversation as resolved.
Outdated
const {stdout: installedNodeVersion} = await exec.getExecOutput(
'node',
['--version'],
{ignoreReturnCode: true}
);
core.setOutput('node-version', installedNodeVersion.trim());
} catch (err) {
core.setOutput('node-version', '');
}

await exec.getExecOutput('npm', ['--version'], {
ignoreReturnCode: true
});

await exec.getExecOutput('yarn', ['--version'], {
ignoreReturnCode: true
});

core.endGroup(groupName);
}