This commit is contained in:
Gustavo Perdomo 2026-04-22 23:03:51 -04:00 committed by GitHub
commit 6577251aa1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 1883 additions and 7 deletions

BIN
.licenses/npm/smol-toml.dep.yml generated Normal file

Binary file not shown.

View File

@ -41,7 +41,7 @@ See [action.yml](action.yml)
# Examples: 12.x, 10.15.1, >=10.15.0, lts/Hydrogen, 16-nightly, latest, node # Examples: 12.x, 10.15.1, >=10.15.0, lts/Hydrogen, 16-nightly, latest, node
node-version: '' node-version: ''
# File containing the version Spec of the version to use. Examples: package.json, .nvmrc, .node-version, .tool-versions. # File containing the version Spec of the version to use. Examples: package.json, mise.toml, .nvmrc, .node-version, .tool-versions.
# If node-version and node-version-file are both provided the action will use version from node-version. # If node-version and node-version-file are both provided the action will use version from node-version.
node-version-file: '' node-version-file: ''

View File

@ -1,18 +1,18 @@
import * as cache from '@actions/cache';
import * as core from '@actions/core'; import * as core from '@actions/core';
import * as exec from '@actions/exec'; import * as exec from '@actions/exec';
import * as tc from '@actions/tool-cache';
import * as cache from '@actions/cache';
import * as io from '@actions/io'; import * as io from '@actions/io';
import * as tc from '@actions/tool-cache';
import fs from 'fs'; import fs from 'fs';
import path from 'path';
import osm from 'os'; import osm from 'os';
import path from 'path';
import each from 'jest-each'; import each from 'jest-each';
import OfficialBuilds from '../src/distributions/official_builds/official_builds';
import * as main from '../src/main'; import * as main from '../src/main';
import * as util from '../src/util'; import * as util from '../src/util';
import OfficialBuilds from '../src/distributions/official_builds/official_builds';
describe('main tests', () => { describe('main tests', () => {
let inputs = {} as any; let inputs = {} as any;
@ -112,6 +112,11 @@ describe('main tests', () => {
${'{"engines": {"node": "17.0.0"}}'} | ${'17.0.0'} ${'{"engines": {"node": "17.0.0"}}'} | ${'17.0.0'}
${'{"devEngines": {"runtime": {"name": "node", "version": "22.0.0"}}}'} | ${'22.0.0'} ${'{"devEngines": {"runtime": {"name": "node", "version": "22.0.0"}}}'} | ${'22.0.0'}
${'{"devEngines": {"runtime": [{"name": "bun"}, {"name": "node", "version": "22.0.0"}]}}'} | ${'22.0.0'} ${'{"devEngines": {"runtime": [{"name": "bun"}, {"name": "node", "version": "22.0.0"}]}}'} | ${'22.0.0'}
${'[tools]\ngo="latest"\nnode = "24.10"'} | ${'24.10'}
${'[tools]\nnode = "22.12"'} | ${'22.12'}
${'[tools]\ngo="latest"\nnode = "24.10"'} | ${'24.10'}
${'[tools]\nnode = { version = "22.20" }'} | ${'22.20'}
${'[tools]\nnode = { postinstall = "corepack enable" }'} | ${null}
`.it('parses "$contents"', ({contents, expected}) => { `.it('parses "$contents"', ({contents, expected}) => {
const existsSpy = jest.spyOn(fs, 'existsSync'); const existsSpy = jest.spyOn(fs, 'existsSync');
existsSpy.mockImplementation(() => true); existsSpy.mockImplementation(() => true);

File diff suppressed because one or more lines are too long

918
dist/setup/index.js vendored

File diff suppressed because one or more lines are too long

15
package-lock.json generated
View File

@ -17,7 +17,8 @@
"@actions/http-client": "^3.0.2", "@actions/http-client": "^3.0.2",
"@actions/io": "^2.0.0", "@actions/io": "^2.0.0",
"@actions/tool-cache": "^3.0.1", "@actions/tool-cache": "^3.0.1",
"semver": "^7.6.3" "semver": "^7.6.3",
"smol-toml": "^1.6.1"
}, },
"devDependencies": { "devDependencies": {
"@types/jest": "^29.5.14", "@types/jest": "^29.5.14",
@ -5448,6 +5449,18 @@
"node": ">=8" "node": ">=8"
} }
}, },
"node_modules/smol-toml": {
"version": "1.6.1",
"resolved": "https://registry.npmjs.org/smol-toml/-/smol-toml-1.6.1.tgz",
"integrity": "sha512-dWUG8F5sIIARXih1DTaQAX4SsiTXhInKf1buxdY9DIg4ZYPZK5nGM1VRIYmEbDbsHt7USo99xSLFu5Q1IqTmsg==",
"license": "BSD-3-Clause",
"engines": {
"node": ">= 18"
},
"funding": {
"url": "https://github.com/sponsors/cyyynthia"
}
},
"node_modules/source-map": { "node_modules/source-map": {
"version": "0.6.1", "version": "0.6.1",
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",

View File

@ -36,7 +36,8 @@
"@actions/http-client": "^3.0.2", "@actions/http-client": "^3.0.2",
"@actions/io": "^2.0.0", "@actions/io": "^2.0.0",
"@actions/tool-cache": "^3.0.1", "@actions/tool-cache": "^3.0.1",
"semver": "^7.6.3" "semver": "^7.6.3",
"smol-toml": "^1.6.1"
}, },
"devDependencies": { "devDependencies": {
"@types/jest": "^29.5.14", "@types/jest": "^29.5.14",

View File

@ -1,6 +1,7 @@
import * as core from '@actions/core'; import * as core from '@actions/core';
import * as exec from '@actions/exec'; import * as exec from '@actions/exec';
import * as io from '@actions/io'; import * as io from '@actions/io';
import {parse} from 'smol-toml';
import fs from 'fs'; import fs from 'fs';
import path from 'path'; import path from 'path';
@ -68,6 +69,26 @@ export function getNodeVersionFromFile(versionFilePath: string): string | null {
core.info('Node version file is not JSON file'); core.info('Node version file is not JSON file');
} }
// Try parsing the file as a mise `mise.toml` file.
try {
const manifest: Record<string, any> = parse(contents);
if (manifest?.tools?.node) {
const node = manifest.tools.node;
if (typeof node === 'object' && node?.version) {
return node.version;
}
if (typeof node === 'string') {
return node;
}
return null;
}
} catch {
core.info('Node version file is not TOML file');
}
const found = contents.match(/^(?:node(js)?\s+)?v?(?<version>[^\s]+)$/m); const found = contents.match(/^(?:node(js)?\s+)?v?(?<version>[^\s]+)$/m);
return found?.groups?.version ?? contents.trim(); return found?.groups?.version ?? contents.trim();
} }