mirror of
https://github.com/actions/setup-node.git
synced 2025-04-22 09:21:00 +00:00
Read version from .nvmrc or .tool-versions
This commit is contained in:
parent
c46424eee2
commit
7fea721543
2 changed files with 53 additions and 9 deletions
29
dist/index.js
vendored
29
dist/index.js
vendored
|
@ -4695,6 +4695,7 @@ const auth = __importStar(__webpack_require__(202));
|
|||
const path = __importStar(__webpack_require__(622));
|
||||
const url_1 = __webpack_require__(835);
|
||||
const os = __webpack_require__(87);
|
||||
const fs = __webpack_require__(747);
|
||||
function run() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
try {
|
||||
|
@ -4702,10 +4703,7 @@ 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 = parseNodeVersion();
|
||||
let arch = core.getInput('architecture');
|
||||
// if architecture supplied but node-version is not
|
||||
// if we don't throw a warning, the already installed x64 node will be used which is not probably what user meant.
|
||||
|
@ -4742,6 +4740,29 @@ function isGhes() {
|
|||
const ghUrl = new url_1.URL(process.env['GITHUB_SERVER_URL'] || 'https://github.com');
|
||||
return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM';
|
||||
}
|
||||
function parseNodeVersion() {
|
||||
let nodeVersion = core.getInput('node-version') || core.getInput('version');
|
||||
if (!nodeVersion) {
|
||||
if (fs.existsSync('.nvmrc')) {
|
||||
// Read from .nvmrc
|
||||
nodeVersion = fs.readFileSync('.nvmrc', 'utf8').trim();
|
||||
console.log(`Using ${nodeVersion} as input from file .nvmrc`);
|
||||
}
|
||||
else if (fs.existsSync('.tool-versions')) {
|
||||
// Read from .tool-versions
|
||||
const toolVersions = fs.readFileSync('.tool-versions', 'utf8').trim();
|
||||
const nodeLine = toolVersions
|
||||
.split(/\r?\n/)
|
||||
.filter(e => e.match(/^nodejs\s/))[0];
|
||||
nodeVersion = nodeLine.match(/^nodejs\s+(.+)$/)[1];
|
||||
console.log(`Using ${nodeVersion} as input from file .tool-versions`);
|
||||
}
|
||||
else {
|
||||
console.log(`Version not specified and not found in .nvmrc or .tool-versions`);
|
||||
}
|
||||
}
|
||||
return nodeVersion;
|
||||
}
|
||||
//# sourceMappingURL=main.js.map
|
||||
|
||||
/***/ }),
|
||||
|
|
33
src/main.ts
33
src/main.ts
|
@ -4,6 +4,7 @@ import * as auth from './authutil';
|
|||
import * as path from 'path';
|
||||
import {URL} from 'url';
|
||||
import os = require('os');
|
||||
import fs = require('fs');
|
||||
|
||||
export async function run() {
|
||||
try {
|
||||
|
@ -11,11 +12,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 = parseNodeVersion();
|
||||
let arch = core.getInput('architecture');
|
||||
|
||||
// if architecture supplied but node-version is not
|
||||
|
@ -64,3 +61,29 @@ function isGhes(): boolean {
|
|||
);
|
||||
return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM';
|
||||
}
|
||||
|
||||
function parseNodeVersion(): string {
|
||||
let nodeVersion = core.getInput('node-version') || core.getInput('version');
|
||||
|
||||
if (!nodeVersion) {
|
||||
if (fs.existsSync('.nvmrc')) {
|
||||
// Read from .nvmrc
|
||||
nodeVersion = fs.readFileSync('.nvmrc', 'utf8').trim();
|
||||
console.log(`Using ${nodeVersion} as input from file .nvmrc`);
|
||||
} else if (fs.existsSync('.tool-versions')) {
|
||||
// Read from .tool-versions
|
||||
const toolVersions = fs.readFileSync('.tool-versions', 'utf8').trim();
|
||||
const nodeLine = toolVersions
|
||||
.split(/\r?\n/)
|
||||
.filter(e => e.match(/^nodejs\s/))[0];
|
||||
nodeVersion = nodeLine.match(/^nodejs\s+(.+)$/)![1];
|
||||
console.log(`Using ${nodeVersion} as input from file .tool-versions`);
|
||||
} else {
|
||||
console.log(
|
||||
`Version not specified and not found in .nvmrc or .tool-versions`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return nodeVersion;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue