Skip to content
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

feat: add volta as node-version-file #532

Merged
merged 21 commits into from
Sep 12, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge remote-tracking branch 'upstream/main'
  • Loading branch information
jef committed Jul 27, 2022
commit 5a01179c35f995befcf90f93e32924c655cc09b9
10 changes: 2 additions & 8 deletions __tests__/data/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
{
"name": "test",
"version": "1.0.0",
"private": true,
"scripts": {
"test": "echo test"
},
"volta": {
"node": "16.15.1"
"engines": {
"node": ">=14.0.0"
}
}
6 changes: 3 additions & 3 deletions dist/cache-save/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59926,12 +59926,12 @@ const exec = __importStar(__nccwpck_require__(1514));
const cache = __importStar(__nccwpck_require__(7799));
exports.supportedPackageManagers = {
npm: {
lockFilePatterns: ['package-lock.json', 'yarn.lock'],
lockFilePatterns: ['package-lock.json', 'npm-shrinkwrap.json', 'yarn.lock'],
getCacheFolderCommand: 'npm config get cache'
},
pnpm: {
lockFilePatterns: ['pnpm-lock.yaml'],
getCacheFolderCommand: 'pnpm store path'
getCacheFolderCommand: 'pnpm store path --silent'
},
yarn1: {
lockFilePatterns: ['yarn.lock'],
Expand Down Expand Up @@ -59986,7 +59986,7 @@ exports.getCacheDirectoryPath = (packageManagerInfo, packageManager) => __awaite
throw new Error(`Could not get cache folder path for ${packageManager}`);
}
core.debug(`${packageManager} path is ${stdOut}`);
return stdOut;
return stdOut.trim();
});
function isGhes() {
const ghUrl = new URL(process.env['GITHUB_SERVER_URL'] || 'https://github.com');
Expand Down
38 changes: 29 additions & 9 deletions dist/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71272,12 +71272,12 @@ const exec = __importStar(__nccwpck_require__(1514));
const cache = __importStar(__nccwpck_require__(7799));
exports.supportedPackageManagers = {
npm: {
lockFilePatterns: ['package-lock.json', 'yarn.lock'],
lockFilePatterns: ['package-lock.json', 'npm-shrinkwrap.json', 'yarn.lock'],
getCacheFolderCommand: 'npm config get cache'
},
pnpm: {
lockFilePatterns: ['pnpm-lock.yaml'],
getCacheFolderCommand: 'pnpm store path'
getCacheFolderCommand: 'pnpm store path --silent'
},
yarn1: {
lockFilePatterns: ['yarn.lock'],
Expand Down Expand Up @@ -71332,7 +71332,7 @@ exports.getCacheDirectoryPath = (packageManagerInfo, packageManager) => __awaite
throw new Error(`Could not get cache folder path for ${packageManager}`);
}
core.debug(`${packageManager} path is ${stdOut}`);
return stdOut;
return stdOut.trim();
});
function isGhes() {
const ghUrl = new URL(process.env['GITHUB_SERVER_URL'] || 'https://github.com');
Expand Down Expand Up @@ -71768,12 +71768,23 @@ function translateArchToDistUrl(arch) {
}
}
function parseNodeVersionFile(contents) {
let nodeVersion = contents.trim();
if (contents.includes('volta')) {
nodeVersion = JSON.parse(contents).volta.node;
}
if (/^v\d/.test(nodeVersion)) {
nodeVersion = nodeVersion.substring(1);
var _a, _b;
let nodeVersion;
const found = contents.match(/^(?:nodejs\s+)?v?(?<version>[^\s]+)$/m);
nodeVersion = (_a = found === null || found === void 0 ? void 0 : found.groups) === null || _a === void 0 ? void 0 : _a.version;
if (!nodeVersion) {
try {
// Try parsing the file as an NPM `package.json`
// file.
nodeVersion = (_b = JSON.parse(contents).engines) === null || _b === void 0 ? void 0 : _b.node;
if (!nodeVersion)
throw new Error();
}
catch (err) {
// In the case of an unknown format,
// return as is and evaluate the version separately.
nodeVersion = contents.trim();
}
}
return nodeVersion;
}
Expand Down Expand Up @@ -71811,6 +71822,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
const core = __importStar(__nccwpck_require__(2186));
const exec = __importStar(__nccwpck_require__(1514));
const installer = __importStar(__nccwpck_require__(2574));
const fs_1 = __importDefault(__nccwpck_require__(7147));
const auth = __importStar(__nccwpck_require__(7573));
Expand Down Expand Up @@ -71843,6 +71855,14 @@ function run() {
const checkLatest = (core.getInput('check-latest') || 'false').toUpperCase() === 'TRUE';
yield installer.getNode(version, stable, checkLatest, auth, arch);
}
// Output version of node is being used
try {
const { stdout: installedVersion } = yield exec.getExecOutput('node', ['--version'], { ignoreReturnCode: true, silent: true });
core.setOutput('node-version', installedVersion.trim());
}
catch (err) {
core.setOutput('node-version', '');
}
const registryUrl = core.getInput('registry-url');
const alwaysAuth = core.getInput('always-auth');
if (registryUrl) {
Expand Down
3 changes: 1 addition & 2 deletions docs/advanced-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ steps:

## Node version file

The `node-version-file` input accepts a path to a file containing the version of Node.js to be used by a project, for example `.nvmrc` or `.node-version`. If both the `node-version` and the `node-version-file` inputs are provided then the `node-version` input is used. In the special case of using `package.json`, the action will look for keys like `volta.node` key to receive the version.

The `node-version-file` input accepts a path to a file containing the version of Node.js to be used by a project, for example `.nvmrc`, `.node-version` or `.tool-versions`. If both the `node-version` and the `node-version-file` inputs are provided then the `node-version` input is used.
See [supported version syntax](https://github.com/actions/setup-node#supported-version-syntax)

> The action will search for the node version file relative to the repository root.
Expand Down
21 changes: 15 additions & 6 deletions src/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,15 +497,24 @@ function translateArchToDistUrl(arch: string): string {
export function parseNodeVersionFile(contents: string): string {
let nodeVersion: string | undefined;

if (contents.includes('volta')) {
nodeVersion = JSON.parse(contents).volta.node;
}
const found = contents.match(/^(?:nodejs\s+)?v?(?<version>[^\s]+)$/m);
nodeVersion = found?.groups?.version;

if (!nodeVersion) {
try {
// Try parsing the file as an NPM `package.json`
// file.
nodeVersion = JSON.parse(contents).engines?.node;

if (/^v\d/.test(nodeVersion)) {
nodeVersion = nodeVersion.substring(1);
if (!nodeVersion) throw new Error();
} catch (err) {
// In the case of an unknown format,
// return as is and evaluate the version separately.
nodeVersion = contents.trim();
}
}

return nodeVersion;
return nodeVersion as string;
}

function isLatestSyntax(versionSpec): boolean {
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.