mirror of
https://codeberg.org/actions/setup-node.git
synced 2023-07-31 13:16:24 +00:00
Merge pull request #532 from jef/main
feat: add volta as node-version-file
This commit is contained in:
commit
9f3a02bbd1
18
.github/workflows/versions.yml
vendored
18
.github/workflows/versions.yml
vendored
|
@ -102,6 +102,24 @@ jobs:
|
||||||
- name: Verify node
|
- name: Verify node
|
||||||
run: __tests__/verify-node.sh 14
|
run: __tests__/verify-node.sh 14
|
||||||
|
|
||||||
|
version-file-volta:
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
os: [ ubuntu-latest, windows-latest, macos-latest ]
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- name: Remove engines from package.json
|
||||||
|
shell: bash
|
||||||
|
run: cat <<< "$(jq 'del(.engines)' ./__tests__/data/package.json)" > ./__tests__/data/package.json
|
||||||
|
- name: Setup node from node version file
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
node-version-file: '__tests__/data/package.json'
|
||||||
|
- name: Verify node
|
||||||
|
run: __tests__/verify-node.sh 14
|
||||||
|
|
||||||
node-dist:
|
node-dist:
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
strategy:
|
strategy:
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
{
|
{
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": "^14.0.0"
|
"node": "^14.0.0"
|
||||||
|
},
|
||||||
|
"volta": {
|
||||||
|
"node": "14.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -579,6 +579,7 @@ describe('setup-node', () => {
|
||||||
existsSpy.mockImplementationOnce(
|
existsSpy.mockImplementationOnce(
|
||||||
input => input === path.join(__dirname, 'data', versionFile)
|
input => input === path.join(__dirname, 'data', versionFile)
|
||||||
);
|
);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
await main.run();
|
await main.run();
|
||||||
|
|
||||||
|
|
20
dist/setup/index.js
vendored
20
dist/setup/index.js
vendored
|
@ -73530,29 +73530,25 @@ function translateArchToDistUrl(arch) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function parseNodeVersionFile(contents) {
|
function parseNodeVersionFile(contents) {
|
||||||
var _a, _b;
|
var _a, _b, _c;
|
||||||
let nodeVersion;
|
let nodeVersion;
|
||||||
// Try parsing the file as an NPM `package.json`
|
// Try parsing the file as an NPM `package.json` file.
|
||||||
// file.
|
|
||||||
try {
|
try {
|
||||||
nodeVersion = (_a = JSON.parse(contents).engines) === null || _a === void 0 ? void 0 : _a.node;
|
nodeVersion = (_a = JSON.parse(contents).volta) === null || _a === void 0 ? void 0 : _a.node;
|
||||||
|
if (!nodeVersion)
|
||||||
|
nodeVersion = (_b = JSON.parse(contents).engines) === null || _b === void 0 ? void 0 : _b.node;
|
||||||
}
|
}
|
||||||
catch (_c) {
|
catch (_d) {
|
||||||
core.warning('Node version file is not JSON file');
|
core.warning('Node version file is not JSON file');
|
||||||
}
|
}
|
||||||
if (!nodeVersion) {
|
if (!nodeVersion) {
|
||||||
try {
|
|
||||||
const found = contents.match(/^(?:nodejs\s+)?v?(?<version>[^\s]+)$/m);
|
const found = contents.match(/^(?:nodejs\s+)?v?(?<version>[^\s]+)$/m);
|
||||||
nodeVersion = (_b = found === null || found === void 0 ? void 0 : found.groups) === null || _b === void 0 ? void 0 : _b.version;
|
nodeVersion = (_c = found === null || found === void 0 ? void 0 : found.groups) === null || _c === void 0 ? void 0 : _c.version;
|
||||||
if (!nodeVersion)
|
|
||||||
throw new Error();
|
|
||||||
}
|
}
|
||||||
catch (err) {
|
|
||||||
// In the case of an unknown format,
|
// In the case of an unknown format,
|
||||||
// return as is and evaluate the version separately.
|
// return as is and evaluate the version separately.
|
||||||
|
if (!nodeVersion)
|
||||||
nodeVersion = contents.trim();
|
nodeVersion = contents.trim();
|
||||||
}
|
|
||||||
}
|
|
||||||
return nodeVersion;
|
return nodeVersion;
|
||||||
}
|
}
|
||||||
exports.parseNodeVersionFile = parseNodeVersionFile;
|
exports.parseNodeVersionFile = parseNodeVersionFile;
|
||||||
|
|
|
@ -48,7 +48,7 @@ steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- uses: actions/setup-node@v3
|
- uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
node-version: '14'
|
node-version: '16'
|
||||||
check-latest: true
|
check-latest: true
|
||||||
- run: npm ci
|
- run: npm ci
|
||||||
- run: npm test
|
- run: npm test
|
||||||
|
@ -56,8 +56,9 @@ steps:
|
||||||
|
|
||||||
## Node version file
|
## 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`, `.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.
|
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`, `.tool-versions`, or `package.json`. 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)
|
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.
|
> The action will search for the node version file relative to the repository root.
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
|
@ -70,6 +71,19 @@ steps:
|
||||||
- run: npm test
|
- run: npm test
|
||||||
```
|
```
|
||||||
|
|
||||||
|
When using the `package.json` input, the action will look for `volta.node` first. If `volta.node` isn't defined, then it will look for `engines.node`.
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"engines": {
|
||||||
|
"node": ">=16.0.0"
|
||||||
|
},
|
||||||
|
"volta": {
|
||||||
|
"node": "16.0.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
## Architecture
|
## Architecture
|
||||||
|
|
||||||
You can use any of the [supported operating systems](https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners), and the compatible `architecture` can be selected using `architecture`. Values are `x86`, `x64`, `arm64`, `armv6l`, `armv7l`, `ppc64le`, `s390x` (not all of the architectures are available on all platforms).
|
You can use any of the [supported operating systems](https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners), and the compatible `architecture` can be selected using `architecture`. Values are `x86`, `x64`, `arm64`, `armv6l`, `armv7l`, `ppc64le`, `s390x` (not all of the architectures are available on all platforms).
|
||||||
|
|
|
@ -497,26 +497,22 @@ function translateArchToDistUrl(arch: string): string {
|
||||||
export function parseNodeVersionFile(contents: string): string {
|
export function parseNodeVersionFile(contents: string): string {
|
||||||
let nodeVersion: string | undefined;
|
let nodeVersion: string | undefined;
|
||||||
|
|
||||||
// Try parsing the file as an NPM `package.json`
|
// Try parsing the file as an NPM `package.json` file.
|
||||||
// file.
|
|
||||||
try {
|
try {
|
||||||
nodeVersion = JSON.parse(contents).engines?.node;
|
nodeVersion = JSON.parse(contents).volta?.node;
|
||||||
|
if (!nodeVersion) nodeVersion = JSON.parse(contents).engines?.node;
|
||||||
} catch {
|
} catch {
|
||||||
core.warning('Node version file is not JSON file');
|
core.warning('Node version file is not JSON file');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!nodeVersion) {
|
if (!nodeVersion) {
|
||||||
try {
|
|
||||||
const found = contents.match(/^(?:nodejs\s+)?v?(?<version>[^\s]+)$/m);
|
const found = contents.match(/^(?:nodejs\s+)?v?(?<version>[^\s]+)$/m);
|
||||||
nodeVersion = found?.groups?.version;
|
nodeVersion = found?.groups?.version;
|
||||||
|
}
|
||||||
|
|
||||||
if (!nodeVersion) throw new Error();
|
|
||||||
} catch (err) {
|
|
||||||
// In the case of an unknown format,
|
// In the case of an unknown format,
|
||||||
// return as is and evaluate the version separately.
|
// return as is and evaluate the version separately.
|
||||||
nodeVersion = contents.trim();
|
if (!nodeVersion) nodeVersion = contents.trim();
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nodeVersion as string;
|
return nodeVersion as string;
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,14 +95,17 @@ function resolveVersionInput(): string {
|
||||||
process.env.GITHUB_WORKSPACE!,
|
process.env.GITHUB_WORKSPACE!,
|
||||||
versionFileInput
|
versionFileInput
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!fs.existsSync(versionFilePath)) {
|
if (!fs.existsSync(versionFilePath)) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`The specified node version file at: ${versionFilePath} does not exist`
|
`The specified node version file at: ${versionFilePath} does not exist`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
version = installer.parseNodeVersionFile(
|
version = installer.parseNodeVersionFile(
|
||||||
fs.readFileSync(versionFilePath, 'utf8')
|
fs.readFileSync(versionFilePath, 'utf8')
|
||||||
);
|
);
|
||||||
|
|
||||||
core.info(`Resolved ${versionFileInput} as ${version}`);
|
core.info(`Resolved ${versionFileInput} as ${version}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue