Skip to content

Commit facc04d

Browse files
committed
Extend go-version to accept go.mod files
1 parent 0a12ed9 commit facc04d

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

__tests__/setup-go.test.ts

+23
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,29 @@ use .
904904
);
905905
});
906906

907+
it('go-version accepts a go.mod file', async () => {
908+
inputs['go-version'] = 'go.mod';
909+
existsSpy.mockImplementation(() => true);
910+
readFileSpy.mockImplementation(() => Buffer.from(goModContents));
911+
912+
await main.run();
913+
914+
expect(logSpy).toHaveBeenCalledWith('Setup go version spec 1.14');
915+
expect(logSpy).toHaveBeenCalledWith('Attempting to download 1.14...');
916+
expect(logSpy).toHaveBeenCalledWith('matching 1.14...');
917+
});
918+
919+
it('go-version reports a read failure', async () => {
920+
inputs['go-version'] = 'path/to/go.mod';
921+
existsSpy.mockImplementation(() => false);
922+
923+
await main.run();
924+
925+
expect(cnSpy).toHaveBeenCalledWith(
926+
`::error::The specified go version file at: path/to/go.mod does not exist${osm.EOL}`
927+
);
928+
});
929+
907930
it('acquires specified architecture of go', async () => {
908931
for (const {arch, version, osSpec} of [
909932
{arch: 'amd64', version: '1.13.7', osSpec: 'linux'},

dist/setup/index.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -88749,12 +88749,15 @@ function parseGoVersion(versionString) {
8874988749
exports.parseGoVersion = parseGoVersion;
8875088750
function resolveVersionInput() {
8875188751
let version = core.getInput('go-version');
88752-
const versionFilePath = core.getInput('go-version-file');
88752+
let versionFilePath = core.getInput('go-version-file');
8875388753
if (version && versionFilePath) {
8875488754
core.warning('Both go-version and go-version-file inputs are specified, only go-version will be used');
8875588755
}
8875688756
if (version) {
88757-
return version;
88757+
if (!version.endsWith('go.mod')) {
88758+
return version;
88759+
}
88760+
versionFilePath = version;
8875888761
}
8875988762
if (versionFilePath) {
8876088763
if (!fs_1.default.existsSync(versionFilePath)) {

src/main.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ export function parseGoVersion(versionString: string): string {
137137

138138
function resolveVersionInput(): string {
139139
let version = core.getInput('go-version');
140-
const versionFilePath = core.getInput('go-version-file');
140+
let versionFilePath = core.getInput('go-version-file');
141141

142142
if (version && versionFilePath) {
143143
core.warning(
@@ -146,7 +146,10 @@ function resolveVersionInput(): string {
146146
}
147147

148148
if (version) {
149-
return version;
149+
if (!version.endsWith('go.mod')) {
150+
return version;
151+
}
152+
versionFilePath = version;
150153
}
151154

152155
if (versionFilePath) {

0 commit comments

Comments
 (0)