feat: add node-lts-codename output

This commit is contained in:
Filip Skokan 2022-10-26 11:06:01 +02:00
parent 16352bb09b
commit c81dbb113a
3 changed files with 51 additions and 0 deletions

View file

@ -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'

21
dist/setup/index.js vendored
View file

@ -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 '';
}
});
}
/***/ }),

View file

@ -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 '';
}
}