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...'); 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 () => { it('reads version from .go-version', async () => {
inputs['go-version-file'] = '.go-version'; inputs['go-version-file'] = '.go-version';
existsSpy.mockImplementation(() => true); existsSpy.mockImplementation(() => true);

@ -45024,16 +45024,15 @@ function parseGoVersionFile(versionFilePath) {
return match ? match[1].trim() : ''; return match ? match[1].trim() : '';
} }
else if (external_path_.basename(versionFilePath) === 'mise.toml') { 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 { try {
const manifest = parse(contents); const manifest = parse(contents);
const go = manifest?.tools?.go; const go = manifest?.tools?.go;
if (typeof go === 'object' && go?.version) { const first = Array.isArray(go) ? go[0] : go;
return go.version; if (typeof first === 'object' && typeof first?.version === 'string') {
return first.version;
} }
if (typeof go === 'string') { if (typeof first === 'string') {
return go; return first;
} }
return ''; return '';
} }

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

Loading…
Cancel
Save