-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Read version from .nvmrc or .tool-versions config #222
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -4,18 +4,15 @@ 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 { | ||||||
// | ||||||
// 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]; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This does then throw into question the flow of these statements, because if I have a I would revisit this by allowing TS to guide you with the types & then making sure that a string is definitely being returned.
Suggested change
|
||||||
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; | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just wanted to ask here whether you want to check for a
falsy
value or justnull
orundefined
? If the latter: