diff --git a/action.yml b/action.yml index ae2e8243..6eedc546 100644 --- a/action.yml +++ b/action.yml @@ -32,6 +32,8 @@ outputs: description: 'A boolean value to indicate if a cache was hit.' node-version: description: 'The installed node version.' + node-lts-codename: + description: "The installed node version's LTS Codename. Empty if the installed node release is not an LTS release." runs: using: 'node16' main: 'dist/setup/index.js' diff --git a/dist/setup/index.js b/dist/setup/index.js index 0daaa2f2..7217d1fc 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -73683,6 +73683,9 @@ function printEnvDetailsAndSetOutput() { } core.info(`${tool}: ${output}`); })); + promises.push(getLtsCodename().then(codename => { + core.setOutput('node-lts-codename', codename); + })); yield Promise.all(promises); core.endGroup(); }); @@ -73706,6 +73709,24 @@ function getToolVersion(tool, options) { } }); } +function getLtsCodename() { + return __awaiter(this, void 0, void 0, function* () { + try { + const { stdout, stderr, exitCode } = yield exec.getExecOutput('node', ["-p 'process.release.lts || process.exit(0)'"], { + ignoreReturnCode: true, + silent: true + }); + if (exitCode > 0) { + core.warning(`[warning]${stderr}`); + return ''; + } + return stdout; + } + catch (err) { + return ''; + } + }); +} /***/ }), diff --git a/src/main.ts b/src/main.ts index 6a980a0d..89b51ef6 100644 --- a/src/main.ts +++ b/src/main.ts @@ -115,6 +115,12 @@ export async function printEnvDetailsAndSetOutput() { core.info(`${tool}: ${output}`); }); + promises.push( + getLtsCodename().then(codename => { + core.setOutput('node-lts-codename', codename); + }) + ); + await Promise.all(promises); core.endGroup(); @@ -137,3 +143,25 @@ async function getToolVersion(tool: string, options: string[]) { return ''; } } + +async function getLtsCodename() { + try { + const {stdout, stderr, exitCode} = await exec.getExecOutput( + 'node', + ["-p 'process.release.lts || process.exit(0)'"], + { + ignoreReturnCode: true, + silent: true + } + ); + + if (exitCode > 0) { + core.warning(`[warning]${stderr}`); + return ''; + } + + return stdout; + } catch (err) { + return ''; + } +}