diff --git a/__tests__/setup-go.test.ts b/__tests__/setup-go.test.ts index 0141736..18d68a2 100644 --- a/__tests__/setup-go.test.ts +++ b/__tests__/setup-go.test.ts @@ -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); diff --git a/dist/setup/index.js b/dist/setup/index.js index eec98bf..270dfc8 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -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 ''; } diff --git a/src/installer.ts b/src/installer.ts index 82654c5..71e1ebe 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -673,12 +673,14 @@ export function parseGoVersionFile(versionFilePath: string): string { const manifest: Record = 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 '';