mirror of
https://github.com/actions/setup-node.git
synced 2025-04-22 09:21:00 +00:00
separate function for resolving version file added
This commit is contained in:
parent
96fa061ec2
commit
f927de6ff2
1 changed files with 23 additions and 19 deletions
42
src/main.ts
42
src/main.ts
|
@ -13,25 +13,7 @@ export async function run() {
|
|||
// Version is optional. If supplied, install / use from the tool cache
|
||||
// If not supplied then task is still used to setup proxy, auth, etc...
|
||||
//
|
||||
let version = core.getInput('node-version');
|
||||
if (!version) {
|
||||
version = core.getInput('version');
|
||||
|
||||
if (!version) {
|
||||
const versionFile = core.getInput('node-version-file');
|
||||
|
||||
if (!!versionFile) {
|
||||
const versionFilePath = path.join(
|
||||
process.env.GITHUB_WORKSPACE!,
|
||||
versionFile
|
||||
);
|
||||
version = installer.parseNodeVersionFile(
|
||||
fs.readFileSync(versionFilePath, 'utf8')
|
||||
);
|
||||
core.info(`Resolved ${versionFile} as ${version}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
let version = resolveVersionInput();
|
||||
|
||||
let arch = core.getInput('architecture');
|
||||
const cache = core.getInput('cache');
|
||||
|
@ -90,3 +72,25 @@ function isGhes(): boolean {
|
|||
);
|
||||
return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM';
|
||||
}
|
||||
|
||||
function resolveVersionInput(): string {
|
||||
let version = core.getInput('node-version') || core.getInput('version');
|
||||
if (version) {
|
||||
return version;
|
||||
}
|
||||
|
||||
const versionFileInput = core.getInput('node-version-file');
|
||||
if (versionFileInput) {
|
||||
const versionFilePath = path.join(
|
||||
process.env.GITHUB_WORKSPACE!,
|
||||
versionFileInput
|
||||
);
|
||||
version = installer.parseNodeVersionFile(
|
||||
fs.readFileSync(versionFilePath, 'utf8')
|
||||
);
|
||||
core.info(`Resolved ${versionFileInput} as ${version}`);
|
||||
return version;
|
||||
}
|
||||
|
||||
return null as any;
|
||||
}
|
Loading…
Add table
Reference in a new issue