feat: support array-form Go versions in mise.toml

pull/787/head
Leif Arriens 2 weeks ago
parent 0979d1074a
commit 28672cdcc5

@ -1019,6 +1019,20 @@ go = "1.24"
expect(logSpy).toHaveBeenCalledWith('matching 1.25...');
});
it('reads the first version from an array in mise.toml', async () => {
inputs['go-version-file'] = 'mise.toml';
existsSpy.mockImplementation(() => true);
readFileSpy.mockImplementation(() =>
Buffer.from('[tools]\ngo = ["1.26", "1.27"]\n')
);
await main.run();
expect(logSpy).toHaveBeenCalledWith('Setup go version spec 1.26');
expect(logSpy).toHaveBeenCalledWith('Attempting to download 1.26...');
expect(logSpy).toHaveBeenCalledWith('matching 1.26...');
});
it('reads version from .go-version', async () => {
inputs['go-version-file'] = '.go-version';
existsSpy.mockImplementation(() => true);

@ -45024,16 +45024,15 @@ function parseGoVersionFile(versionFilePath) {
return match ? match[1].trim() : '';
}
else if (external_path_.basename(versionFilePath) === 'mise.toml') {
// mise stores tool versions under the [tools] table. The Go tool is
// named "go" in mise, even though this action uses "golang" elsewhere.
try {
const manifest = parse(contents);
const go = manifest?.tools?.go;
if (typeof go === 'object' && go?.version) {
return go.version;
const first = Array.isArray(go) ? go[0] : go;
if (typeof first === 'object' && typeof first?.version === 'string') {
return first.version;
}
if (typeof go === 'string') {
return go;
if (typeof first === 'string') {
return first;
}
return '';
}

@ -673,12 +673,14 @@ export function parseGoVersionFile(versionFilePath: string): string {
const manifest: Record<string, any> = parse(contents);
const go = manifest?.tools?.go;
if (typeof go === 'object' && go?.version) {
return go.version;
const first = Array.isArray(go) ? go[0] : go;
if (typeof first === 'object' && typeof first?.version === 'string') {
return first.version;
}
if (typeof go === 'string') {
return go;
if (typeof first === 'string') {
return first;
}
return '';

Loading…
Cancel
Save