From 748956ad629b565b8604ddb0464ddbe68ea0fa35 Mon Sep 17 00:00:00 2001 From: Gustavo Perdomo Date: Wed, 22 Oct 2025 00:13:35 -0300 Subject: [PATCH] feat: add support for mise.toml file --- README.md | 2 +- __tests__/main.test.ts | 10 ++-- package-lock.json | 118 ++++++++++++++++++++++++++++++++++++++++- package.json | 4 +- src/util.ts | 17 ++++++ 5 files changed, 144 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index aad5a82a..feea3eca 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ See [action.yml](action.yml) # Examples: 12.x, 10.15.1, >=10.15.0, lts/Hydrogen, 16-nightly, latest, node 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. node-version-file: '' diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index 4d7a79a0..0af507b8 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -1,18 +1,18 @@ +import * as cache from '@actions/cache'; import * as core from '@actions/core'; 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 tc from '@actions/tool-cache'; import fs from 'fs'; -import path from 'path'; import osm from 'os'; +import path from 'path'; import each from 'jest-each'; +import OfficialBuilds from '../src/distributions/official_builds/official_builds'; import * as main from '../src/main'; import * as util from '../src/util'; -import OfficialBuilds from '../src/distributions/official_builds/official_builds'; describe('main tests', () => { let inputs = {} as any; @@ -112,6 +112,8 @@ describe('main tests', () => { ${'{"engines": {"node": "17.0.0"}}'} | ${'17.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'} + ${'[tools]\ngo="latest"\nnode = "24.10"'} | ${'24.10'} + ${'[tools]\nnode = "22.12"'} | ${'22.12'} `.it('parses "$contents"', ({contents, expected}) => { const existsSpy = jest.spyOn(fs, 'existsSync'); existsSpy.mockImplementation(() => true); diff --git a/package-lock.json b/package-lock.json index 59a0ec8b..a48e7c59 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,7 +17,9 @@ "@actions/http-client": "^2.2.1", "@actions/io": "^1.0.2", "@actions/tool-cache": "^2.0.2", - "semver": "^7.6.3" + "js-toml": "1.0.2", + "semver": "^7.6.3", + "uuid": "^11.1.0" }, "devDependencies": { "@types/jest": "^29.5.14", @@ -951,6 +953,18 @@ "@babel/core": "^7.0.0-0" } }, + "node_modules/@babel/runtime-corejs3": { + "version": "7.29.2", + "resolved": "https://registry.npmjs.org/@babel/runtime-corejs3/-/runtime-corejs3-7.29.2.tgz", + "integrity": "sha512-Lc94FOD5+0aXhdb0Tdg3RUtqT6yWbI/BbFWvlaSJ3gAb9Ks+99nHRDKADVqC37er4eCB0fHyWT+y+K3QOvJKbw==", + "license": "MIT", + "dependencies": { + "core-js-pure": "^3.48.0" + }, + "engines": { + "node": ">=6.9.0" + } + }, "node_modules/@babel/template": { "version": "7.27.2", "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.27.2.tgz", @@ -1006,6 +1020,45 @@ "dev": true, "license": "MIT" }, + "node_modules/@chevrotain/cst-dts-gen": { + "version": "11.2.0", + "resolved": "https://registry.npmjs.org/@chevrotain/cst-dts-gen/-/cst-dts-gen-11.2.0.tgz", + "integrity": "sha512-ssJFvn/UXhQQeICw3SR/fZPmYVj+JM2mP+Lx7bZ51cOeHaMWOKp3AUMuyM3QR82aFFXTfcAp67P5GpPjGmbZWQ==", + "license": "Apache-2.0", + "dependencies": { + "@chevrotain/gast": "11.2.0", + "@chevrotain/types": "11.2.0", + "lodash-es": "4.17.23" + } + }, + "node_modules/@chevrotain/gast": { + "version": "11.2.0", + "resolved": "https://registry.npmjs.org/@chevrotain/gast/-/gast-11.2.0.tgz", + "integrity": "sha512-c+KoD6eSI1xjAZZoNUW+V0l13UEn+a4ShmUrjIKs1BeEWCji0Kwhmqn5FSx1K4BhWL7IQKlV7wLR4r8lLArORQ==", + "license": "Apache-2.0", + "dependencies": { + "@chevrotain/types": "11.2.0", + "lodash-es": "4.17.23" + } + }, + "node_modules/@chevrotain/regexp-to-ast": { + "version": "11.2.0", + "resolved": "https://registry.npmjs.org/@chevrotain/regexp-to-ast/-/regexp-to-ast-11.2.0.tgz", + "integrity": "sha512-lG73pBFqbXODTbXhdZwv0oyUaI+3Irm+uOv5/W79lI3g5hasYaJnVJOm3H2NkhA0Ef4XLBU4Scr7TJDJwgFkAw==", + "license": "Apache-2.0" + }, + "node_modules/@chevrotain/types": { + "version": "11.2.0", + "resolved": "https://registry.npmjs.org/@chevrotain/types/-/types-11.2.0.tgz", + "integrity": "sha512-vBMSj/lz/LqolbGQEHB0tlpW5BnljHVtp+kzjQfQU+5BtGMTuZCPVgaAjtKvQYXnHb/8i/02Kii00y0tsuwfsw==", + "license": "Apache-2.0" + }, + "node_modules/@chevrotain/utils": { + "version": "11.2.0", + "resolved": "https://registry.npmjs.org/@chevrotain/utils/-/utils-11.2.0.tgz", + "integrity": "sha512-+7whECg4yNWHottjvr2To2BRxL4XJVjIyyv5J4+bJ0iMOVU8j/8n1qPDLZS/90W/BObDR8VNL46lFbzY/Hosmw==", + "license": "Apache-2.0" + }, "node_modules/@eslint-community/eslint-utils": { "version": "4.9.0", "resolved": "https://registry.npmjs.org/@eslint-community/eslint-utils/-/eslint-utils-4.9.0.tgz", @@ -2619,6 +2672,20 @@ "node": ">=10" } }, + "node_modules/chevrotain": { + "version": "11.2.0", + "resolved": "https://registry.npmjs.org/chevrotain/-/chevrotain-11.2.0.tgz", + "integrity": "sha512-mHCHTxM51nCklUw9RzRVc0DLjAh/SAUPM4k/zMInlTIo25ldWXOZoPt7XEIk/LwoT4lFVmJcu9g5MHtx371x3A==", + "license": "Apache-2.0", + "dependencies": { + "@chevrotain/cst-dts-gen": "11.2.0", + "@chevrotain/gast": "11.2.0", + "@chevrotain/regexp-to-ast": "11.2.0", + "@chevrotain/types": "11.2.0", + "@chevrotain/utils": "11.2.0", + "lodash-es": "4.17.23" + } + }, "node_modules/ci-info": { "version": "3.9.0", "resolved": "https://registry.npmjs.org/ci-info/-/ci-info-3.9.0.tgz", @@ -2708,6 +2775,17 @@ "dev": true, "license": "MIT" }, + "node_modules/core-js-pure": { + "version": "3.49.0", + "resolved": "https://registry.npmjs.org/core-js-pure/-/core-js-pure-3.49.0.tgz", + "integrity": "sha512-XM4RFka59xATyJv/cS3O3Kml72hQXUeGRuuTmMYFxwzc9/7C8OYTaIR/Ji+Yt8DXzsFLNhat15cE/JP15HrCgw==", + "hasInstallScript": true, + "license": "MIT", + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/core-js" + } + }, "node_modules/create-jest": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/create-jest/-/create-jest-29.7.0.tgz", @@ -4549,6 +4627,16 @@ "dev": true, "license": "MIT" }, + "node_modules/js-toml": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/js-toml/-/js-toml-1.0.2.tgz", + "integrity": "sha512-/7IQ//bzn2a/5IDazPUNzlW7bsjxS51cxciYZDR+Z+3Le60yzT0YfI8KOWqTtBcZkXXVklhWd2OuGd8ZksB0wQ==", + "license": "MIT", + "dependencies": { + "chevrotain": "^11.0.3", + "xregexp": "^5.1.1" + } + }, "node_modules/js-yaml": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.1.tgz", @@ -4683,6 +4771,12 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/lodash-es": { + "version": "4.17.23", + "resolved": "https://registry.npmjs.org/lodash-es/-/lodash-es-4.17.23.tgz", + "integrity": "sha512-kVI48u3PZr38HdYz98UmfPnXl2DXrpdctLrFLCd3kOx1xUkOmpFPx7gCWWM5MPkL/fD8zb+Ph0QzjGFs4+hHWg==", + "license": "MIT" + }, "node_modules/lodash.memoize": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/lodash.memoize/-/lodash.memoize-4.1.2.tgz", @@ -5891,6 +5985,19 @@ "punycode": "^2.1.0" } }, + "node_modules/uuid": { + "version": "11.1.0", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-11.1.0.tgz", + "integrity": "sha512-0/A9rDy9P7cJ+8w1c9WD9V//9Wj15Ce2MPz8Ri6032usz+NfePxx5AcN3bN+r6ZL6jEo066/yNYB3tn4pQEx+A==", + "funding": [ + "https://github.com/sponsors/broofa", + "https://github.com/sponsors/ctavan" + ], + "license": "MIT", + "bin": { + "uuid": "dist/esm/bin/uuid" + } + }, "node_modules/v8-to-istanbul": { "version": "9.3.0", "resolved": "https://registry.npmjs.org/v8-to-istanbul/-/v8-to-istanbul-9.3.0.tgz", @@ -5987,6 +6094,15 @@ "node": "^12.13.0 || ^14.15.0 || >=16.0.0" } }, + "node_modules/xregexp": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/xregexp/-/xregexp-5.1.2.tgz", + "integrity": "sha512-6hGgEMCGhqCTFEJbqmWrNIPqfpdirdGWkqshu7fFZddmTSfgv5Sn9D2SaKloR79s5VUiUlpwzg3CM3G6D3VIlw==", + "license": "MIT", + "dependencies": { + "@babel/runtime-corejs3": "^7.26.9" + } + }, "node_modules/y18n": { "version": "5.0.8", "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz", diff --git a/package.json b/package.json index 726ec6fb..3ce68200 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,9 @@ "@actions/http-client": "^2.2.1", "@actions/io": "^1.0.2", "@actions/tool-cache": "^2.0.2", - "semver": "^7.6.3" + "js-toml": "1.0.2", + "semver": "^7.6.3", + "uuid": "^11.1.0" }, "devDependencies": { "@types/jest": "^29.5.14", diff --git a/src/util.ts b/src/util.ts index dd34f7e5..5eaf1b52 100644 --- a/src/util.ts +++ b/src/util.ts @@ -1,6 +1,7 @@ import * as core from '@actions/core'; import * as exec from '@actions/exec'; import * as io from '@actions/io'; +import {load} from 'js-toml'; import fs from 'fs'; import path from 'path'; @@ -68,6 +69,22 @@ export function getNodeVersionFromFile(versionFilePath: string): string | null { core.info('Node version file is not JSON file'); } + // Try parsing the file as an MISE `mise.toml` file. + try { + const manifest: Record = load(contents); + if (manifest?.tools?.node) { + const node = manifest.tools.node; + + if (typeof node === 'object' && node?.version) { + return node.version; + } + + return node; + } + } catch { + core.info('Node version file is not TOML file'); + } + const found = contents.match(/^(?:node(js)?\s+)?v?(?[^\s]+)$/m); return found?.groups?.version ?? contents.trim(); }