diff --git a/__tests__/setup-go.test.ts b/__tests__/setup-go.test.ts index 70f2166eb..182e7bda7 100644 --- a/__tests__/setup-go.test.ts +++ b/__tests__/setup-go.test.ts @@ -904,6 +904,29 @@ use . ); }); + it('go-version accepts a go.mod file', async () => { + inputs['go-version'] = 'go.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('go-version reports a read failure', async () => { + inputs['go-version'] = 'path/to/go.mod'; + existsSpy.mockImplementation(() => false); + + await main.run(); + + expect(cnSpy).toHaveBeenCalledWith( + `::error::The specified go version file at: path/to/go.mod does not exist${osm.EOL}` + ); + }); + it('acquires specified architecture of go', async () => { for (const {arch, version, osSpec} of [ {arch: 'amd64', version: '1.13.7', osSpec: 'linux'}, diff --git a/dist/setup/index.js b/dist/setup/index.js index 9ad3784ea..e3b4d9152 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -88749,12 +88749,15 @@ function parseGoVersion(versionString) { exports.parseGoVersion = parseGoVersion; function resolveVersionInput() { let version = core.getInput('go-version'); - const versionFilePath = core.getInput('go-version-file'); + let versionFilePath = core.getInput('go-version-file'); if (version && versionFilePath) { core.warning('Both go-version and go-version-file inputs are specified, only go-version will be used'); } if (version) { - return version; + if (!version.endsWith('go.mod')) { + return version; + } + versionFilePath = version; } if (versionFilePath) { if (!fs_1.default.existsSync(versionFilePath)) { diff --git a/src/main.ts b/src/main.ts index 690d277f9..2fdeb8ae0 100644 --- a/src/main.ts +++ b/src/main.ts @@ -137,7 +137,7 @@ export function parseGoVersion(versionString: string): string { function resolveVersionInput(): string { let version = core.getInput('go-version'); - const versionFilePath = core.getInput('go-version-file'); + let versionFilePath = core.getInput('go-version-file'); if (version && versionFilePath) { core.warning( @@ -146,7 +146,10 @@ function resolveVersionInput(): string { } if (version) { - return version; + if (!version.endsWith('go.mod')) { + return version; + } + versionFilePath = version; } if (versionFilePath) {