fix: parse go-version-file by content

The `parseGoVersionFile` function used to only
check for exact filenames like "go.{mod,work}".
When `go-version-file` pointed to something like a
tools modfile ("go.tool.mod"), it would just dump
the whole file contents back, which then got
mistaken for a version spec and broke the
manifest/dist resolution.

Now it looks at the file content to spot Go module
or workspace files and pulls out the `toolchain`
or `go` directives. Left ".tool-versions" handling
alone.

Fixes #746

Signed-off-by: Dwi Siswanto <git@dw1.io>
This commit is contained in:
Dwi Siswanto 2026-04-10 15:03:39 +07:00
parent 4a3601121d
commit 493769a1ce
No known key found for this signature in database
GPG key ID: 3BB198907EF44CED
4 changed files with 61 additions and 21 deletions

View file

@ -901,6 +901,18 @@ use .
expect(logSpy).toHaveBeenCalledWith('matching 1.19...');
});
it('reads version from go.mod-like file name', async () => {
inputs['go-version-file'] = 'go.tool.mod';
existsSpy.mockImplementation(() => true);
readFileSpy.mockImplementation(() => Buffer.from(goModContents));
await main.run();
expect(logSpy).toHaveBeenCalledWith('Setup go version spec 1.14');
expect(logSpy).toHaveBeenCalledWith('Attempting to download 1.14...');
expect(logSpy).toHaveBeenCalledWith('matching 1.14...');
});
it('reads version from .tool-versions', async () => {
inputs['go-version-file'] = '.tool-versions';
existsSpy.mockImplementation(() => true);
@ -1066,6 +1078,19 @@ use .
expected_version: placeholderVersion,
desc: 'from go directive when GOTOOLCHAIN is local'
},
{
goVersionfile: 'go.tool.mod',
fileContents: Buffer.from(buildGoMod(placeholderVersion, version)),
expected_version: version,
desc: 'from toolchain directive'
},
{
goVersionfile: 'go.tool.mod',
fileContents: Buffer.from(buildGoMod(placeholderVersion, version)),
gotoolchain_env: 'local',
expected_version: placeholderVersion,
desc: 'from go directive when GOTOOLCHAIN is local'
},
{
goVersionfile: 'go.work',
fileContents: Buffer.from(buildGoMod(placeholderVersion, version)),