mirror of
https://code.forgejo.org/actions/setup-node.git
synced 2025-05-19 12:54:45 +00:00
Adding Node.js version file support (#338)
This commit is contained in:
parent
360ab8b75b
commit
d08cf22211
9 changed files with 221 additions and 23 deletions
43
src/main.ts
43
src/main.ts
|
@ -1,5 +1,6 @@
|
|||
import * as core from '@actions/core';
|
||||
import * as installer from './installer';
|
||||
import fs from 'fs';
|
||||
import * as auth from './authutil';
|
||||
import * as path from 'path';
|
||||
import {restoreCache} from './cache-restore';
|
||||
|
@ -12,10 +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');
|
||||
}
|
||||
let version = resolveVersionInput();
|
||||
|
||||
let arch = core.getInput('architecture');
|
||||
const cache = core.getInput('cache');
|
||||
|
@ -63,8 +61,8 @@ export async function run() {
|
|||
core.info(
|
||||
`##[add-matcher]${path.join(matchersPath, 'eslint-compact.json')}`
|
||||
);
|
||||
} catch (error) {
|
||||
core.setFailed(error.message);
|
||||
} catch (err) {
|
||||
core.setFailed(err.message);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -74,3 +72,36 @@ function isGhes(): boolean {
|
|||
);
|
||||
return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM';
|
||||
}
|
||||
|
||||
function resolveVersionInput(): string {
|
||||
let version = core.getInput('node-version') || core.getInput('version');
|
||||
const versionFileInput = core.getInput('node-version-file');
|
||||
|
||||
if (version && versionFileInput) {
|
||||
core.warning(
|
||||
'Both node-version and node-version-file inputs are specified, only node-version will be used'
|
||||
);
|
||||
}
|
||||
|
||||
if (version) {
|
||||
return version;
|
||||
}
|
||||
|
||||
if (versionFileInput) {
|
||||
const versionFilePath = path.join(
|
||||
process.env.GITHUB_WORKSPACE!,
|
||||
versionFileInput
|
||||
);
|
||||
if (!fs.existsSync(versionFilePath)) {
|
||||
throw new Error(
|
||||
`The specified node version file at: ${versionFilePath} does not exist`
|
||||
);
|
||||
}
|
||||
version = installer.parseNodeVersionFile(
|
||||
fs.readFileSync(versionFilePath, 'utf8')
|
||||
);
|
||||
core.info(`Resolved ${versionFileInput} as ${version}`);
|
||||
}
|
||||
|
||||
return version;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue