Skip to content

Commit

Permalink
Extend go-version to accept go.mod files
Browse files Browse the repository at this point in the history
  • Loading branch information
myaaaaaaaaa committed Jul 7, 2024
1 parent 0a12ed9 commit facc04d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
23 changes: 23 additions & 0 deletions __tests__/setup-go.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'},
Expand Down
7 changes: 5 additions & 2 deletions dist/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
7 changes: 5 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -146,7 +146,10 @@ function resolveVersionInput(): string {
}

if (version) {
return version;
if (!version.endsWith('go.mod')) {
return version;
}
versionFilePath = version;
}

if (versionFilePath) {
Expand Down

0 comments on commit facc04d

Please sign in to comment.