1
0
Fork 0
mirror of https://github.com/actions/setup-node synced 2024-12-22 21:22:42 +00:00

Merge pull request #534 from panva/set-version-output

set node-version output (2022 edition)
This commit is contained in:
Marko Zivic 2022-07-04 14:45:20 +02:00 committed by GitHub
commit 78faa555e1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 939 additions and 918 deletions

View file

@ -1,6 +1,7 @@
import * as core from '@actions/core'; import * as core from '@actions/core';
import * as io from '@actions/io'; import * as io from '@actions/io';
import * as tc from '@actions/tool-cache'; import * as tc from '@actions/tool-cache';
import * as exec from '@actions/exec';
import * as im from '../src/installer'; import * as im from '../src/installer';
import * as cache from '@actions/cache'; import * as cache from '@actions/cache';
import fs from 'fs'; import fs from 'fs';
@ -38,6 +39,7 @@ describe('setup-node', () => {
let authSpy: jest.SpyInstance; let authSpy: jest.SpyInstance;
let parseNodeVersionSpy: jest.SpyInstance; let parseNodeVersionSpy: jest.SpyInstance;
let isCacheActionAvailable: jest.SpyInstance; let isCacheActionAvailable: jest.SpyInstance;
let getExecOutputSpy: jest.SpyInstance;
beforeEach(() => { beforeEach(() => {
// @actions/core // @actions/core
@ -103,6 +105,10 @@ describe('setup-node', () => {
// uncomment to debug // uncomment to debug
// process.stderr.write('log:' + line + '\n'); // process.stderr.write('log:' + line + '\n');
}); });
// @actions/exec
getExecOutputSpy = jest.spyOn(exec, 'getExecOutput');
getExecOutputSpy.mockImplementation(() => 'v16.15.0');
}); });
afterEach(() => { afterEach(() => {

View file

@ -30,6 +30,8 @@ inputs:
outputs: outputs:
cache-hit: cache-hit:
description: 'A boolean value to indicate if a cache was hit.' description: 'A boolean value to indicate if a cache was hit.'
node-version:
description: 'The installed node version.'
runs: runs:
using: 'node16' using: 'node16'
main: 'dist/setup/index.js' main: 'dist/setup/index.js'

4
dist/setup/index.js vendored
View file

@ -71808,6 +71808,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
}; };
Object.defineProperty(exports, "__esModule", ({ value: true })); Object.defineProperty(exports, "__esModule", ({ value: true }));
const core = __importStar(__nccwpck_require__(2186)); const core = __importStar(__nccwpck_require__(2186));
const exec = __importStar(__nccwpck_require__(1514));
const installer = __importStar(__nccwpck_require__(2574)); const installer = __importStar(__nccwpck_require__(2574));
const fs_1 = __importDefault(__nccwpck_require__(7147)); const fs_1 = __importDefault(__nccwpck_require__(7147));
const auth = __importStar(__nccwpck_require__(7573)); const auth = __importStar(__nccwpck_require__(7573));
@ -71840,6 +71841,9 @@ function run() {
const checkLatest = (core.getInput('check-latest') || 'false').toUpperCase() === 'TRUE'; const checkLatest = (core.getInput('check-latest') || 'false').toUpperCase() === 'TRUE';
yield installer.getNode(version, stable, checkLatest, auth, arch); yield installer.getNode(version, stable, checkLatest, auth, arch);
} }
// Output version of node is being used
const { stdout: installedVersion } = yield exec.getExecOutput('node', ['--version'], { ignoreReturnCode: true });
core.setOutput('node-version', installedVersion);
const registryUrl = core.getInput('registry-url'); const registryUrl = core.getInput('registry-url');
const alwaysAuth = core.getInput('always-auth'); const alwaysAuth = core.getInput('always-auth');
if (registryUrl) { if (registryUrl) {

View file

@ -1,4 +1,5 @@
import * as core from '@actions/core'; import * as core from '@actions/core';
import * as exec from '@actions/exec';
import * as installer from './installer'; import * as installer from './installer';
import fs from 'fs'; import fs from 'fs';
import * as auth from './authutil'; import * as auth from './authutil';
@ -39,6 +40,14 @@ export async function run() {
await installer.getNode(version, stable, checkLatest, auth, arch); await installer.getNode(version, stable, checkLatest, auth, arch);
} }
// Output version of node is being used
const {stdout: installedVersion} = await exec.getExecOutput(
'node',
['--version'],
{ignoreReturnCode: true}
);
core.setOutput('node-version', installedVersion);
const registryUrl: string = core.getInput('registry-url'); const registryUrl: string = core.getInput('registry-url');
const alwaysAuth: string = core.getInput('always-auth'); const alwaysAuth: string = core.getInput('always-auth');
if (registryUrl) { if (registryUrl) {