Skip to content

Commit 748956a

Browse files
committed
feat: add support for mise.toml file
1 parent 53b8394 commit 748956a

File tree

5 files changed

+144
-7
lines changed

5 files changed

+144
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ See [action.yml](action.yml)
4141
# Examples: 12.x, 10.15.1, >=10.15.0, lts/Hydrogen, 16-nightly, latest, node
4242
node-version: ''
4343

44-
# File containing the version Spec of the version to use. Examples: package.json, .nvmrc, .node-version, .tool-versions.
44+
# File containing the version Spec of the version to use. Examples: package.json, mise.toml, .nvmrc, .node-version, .tool-versions.
4545
# If node-version and node-version-file are both provided the action will use version from node-version.
4646
node-version-file: ''
4747

__tests__/main.test.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1+
import * as cache from '@actions/cache';
12
import * as core from '@actions/core';
23
import * as exec from '@actions/exec';
3-
import * as tc from '@actions/tool-cache';
4-
import * as cache from '@actions/cache';
54
import * as io from '@actions/io';
5+
import * as tc from '@actions/tool-cache';
66

77
import fs from 'fs';
8-
import path from 'path';
98
import osm from 'os';
9+
import path from 'path';
1010

1111
import each from 'jest-each';
1212

13+
import OfficialBuilds from '../src/distributions/official_builds/official_builds';
1314
import * as main from '../src/main';
1415
import * as util from '../src/util';
15-
import OfficialBuilds from '../src/distributions/official_builds/official_builds';
1616

1717
describe('main tests', () => {
1818
let inputs = {} as any;
@@ -112,6 +112,8 @@ describe('main tests', () => {
112112
${'{"engines": {"node": "17.0.0"}}'} | ${'17.0.0'}
113113
${'{"devEngines": {"runtime": {"name": "node", "version": "22.0.0"}}}'} | ${'22.0.0'}
114114
${'{"devEngines": {"runtime": [{"name": "bun"}, {"name": "node", "version": "22.0.0"}]}}'} | ${'22.0.0'}
115+
${'[tools]\ngo="latest"\nnode = "24.10"'} | ${'24.10'}
116+
${'[tools]\nnode = "22.12"'} | ${'22.12'}
115117
`.it('parses "$contents"', ({contents, expected}) => {
116118
const existsSpy = jest.spyOn(fs, 'existsSync');
117119
existsSpy.mockImplementation(() => true);

package-lock.json

Lines changed: 117 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@
3636
"@actions/http-client": "^2.2.1",
3737
"@actions/io": "^1.0.2",
3838
"@actions/tool-cache": "^2.0.2",
39-
"semver": "^7.6.3"
39+
"js-toml": "1.0.2",
40+
"semver": "^7.6.3",
41+
"uuid": "^11.1.0"
4042
},
4143
"devDependencies": {
4244
"@types/jest": "^29.5.14",

src/util.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as core from '@actions/core';
22
import * as exec from '@actions/exec';
33
import * as io from '@actions/io';
4+
import {load} from 'js-toml';
45

56
import fs from 'fs';
67
import path from 'path';
@@ -68,6 +69,22 @@ export function getNodeVersionFromFile(versionFilePath: string): string | null {
6869
core.info('Node version file is not JSON file');
6970
}
7071

72+
// Try parsing the file as an MISE `mise.toml` file.
73+
try {
74+
const manifest: Record<string, any> = load(contents);
75+
if (manifest?.tools?.node) {
76+
const node = manifest.tools.node;
77+
78+
if (typeof node === 'object' && node?.version) {
79+
return node.version;
80+
}
81+
82+
return node;
83+
}
84+
} catch {
85+
core.info('Node version file is not TOML file');
86+
}
87+
7188
const found = contents.match(/^(?:node(js)?\s+)?v?(?<version>[^\s]+)$/m);
7289
return found?.groups?.version ?? contents.trim();
7390
}

0 commit comments

Comments
 (0)