From a707d84385be85607f1d50c46b9cbd3dc3300b82 Mon Sep 17 00:00:00 2001 From: jojo43 Date: Sun, 5 Jul 2020 10:25:03 +0900 Subject: [PATCH 01/13] Add go-version-from-file option --- __tests__/setup-go.test.ts | 41 ++++++++++++++++++++++++++++++++++++++ src/main.ts | 9 ++++++++- 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/__tests__/setup-go.test.ts b/__tests__/setup-go.test.ts index 9007c81ee..3a2841d9e 100644 --- a/__tests__/setup-go.test.ts +++ b/__tests__/setup-go.test.ts @@ -31,6 +31,7 @@ describe('setup-go', () => { let dbgSpy: jest.SpyInstance; let whichSpy: jest.SpyInstance; let existsSpy: jest.SpyInstance; + let readFileSpy: jest.SpyInstance; let mkdirpSpy: jest.SpyInstance; let execSpy: jest.SpyInstance; let getManifestSpy: jest.SpyInstance; @@ -60,6 +61,7 @@ describe('setup-go', () => { // io whichSpy = jest.spyOn(io, 'which'); existsSpy = jest.spyOn(fs, 'existsSync'); + readFileSpy = jest.spyOn(fs, 'readFileSync'); mkdirpSpy = jest.spyOn(io, 'mkdirP'); // gets @@ -556,4 +558,43 @@ describe('setup-go', () => { it('does not convert exact versions', async () => { expect(im.makeSemver('1.13.1')).toBe('1.13.1'); }); + + describe('go-version-from-file', () => { + it('reads version from file', async () => { + inputs['go-version-from-file'] = '.go-version'; + readFileSpy.mockImplementation(() => Buffer.from('1.13.0\n')); + + await main.run(); + + expect(logSpy).toHaveBeenCalledWith( + 'Setup go stable version spec 1.13.0' + ); + }); + + it('is overwritten by go-version', async () => { + inputs['go-version'] = '1.13.1'; + + inputs['go-version-from-file'] = '.go-version'; + readFileSpy.mockImplementation(() => Buffer.from('1.13.0\n')); + + await main.run(); + + expect(logSpy).toHaveBeenCalledWith( + 'Setup go stable version spec 1.13.1' + ); + }); + + it('reports a read failure', async () => { + const versionFilePath = '.go-version'; + inputs['go-version-from-file'] = versionFilePath; + const errMsg = `ENOENT: no such file or directory, open '${versionFilePath}'`; + readFileSpy.mockImplementation(() => { + throw new Error(errMsg); + }); + + await main.run(); + + expect(cnSpy).toHaveBeenCalledWith(`::error::${errMsg}${osm.EOL}`); + }); + }); }); diff --git a/src/main.ts b/src/main.ts index 2d90b2fe7..7593e7ab5 100644 --- a/src/main.ts +++ b/src/main.ts @@ -12,7 +12,14 @@ export async function run() { // versionSpec is optional. If supplied, install / use from the tool cache // If not supplied then problem matchers will still be setup. Useful for self-hosted. // - let versionSpec = core.getInput('go-version'); + const versionFilePath = core.getInput('go-version-from-file'); + const versionSpecFromFile = + versionFilePath && + fs + .readFileSync(versionFilePath) + .toString() + .trim(); + let versionSpec = core.getInput('go-version') || versionSpecFromFile; // stable will be true unless false is the exact input // since getting unstable versions should be explicit From d706c92bdb4ef0f3557826f3d45751b603a0182c Mon Sep 17 00:00:00 2001 From: jojo43 Date: Sun, 5 Jul 2020 10:39:13 +0900 Subject: [PATCH 02/13] Fix EOL --- __tests__/setup-go.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/__tests__/setup-go.test.ts b/__tests__/setup-go.test.ts index 3a2841d9e..c241364b0 100644 --- a/__tests__/setup-go.test.ts +++ b/__tests__/setup-go.test.ts @@ -562,7 +562,7 @@ describe('setup-go', () => { describe('go-version-from-file', () => { it('reads version from file', async () => { inputs['go-version-from-file'] = '.go-version'; - readFileSpy.mockImplementation(() => Buffer.from('1.13.0\n')); + readFileSpy.mockImplementation(() => Buffer.from(`1.13.0${osm.EOL}`)); await main.run(); @@ -575,7 +575,7 @@ describe('setup-go', () => { inputs['go-version'] = '1.13.1'; inputs['go-version-from-file'] = '.go-version'; - readFileSpy.mockImplementation(() => Buffer.from('1.13.0\n')); + readFileSpy.mockImplementation(() => Buffer.from(`1.13.0${osm.EOL}`)); await main.run(); From 95c6e43dbe5693e6299839e07c002a1f7105ba1e Mon Sep 17 00:00:00 2001 From: jojo43 Date: Sun, 5 Jul 2020 10:52:54 +0900 Subject: [PATCH 03/13] npm run build --- dist/index.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/dist/index.js b/dist/index.js index 2689cf38a..aacd1ca1f 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1432,7 +1432,13 @@ function run() { // versionSpec is optional. If supplied, install / use from the tool cache // If not supplied then problem matchers will still be setup. Useful for self-hosted. // - let versionSpec = core.getInput('go-version'); + const versionFilePath = core.getInput('go-version-from-file'); + const versionSpecFromFile = versionFilePath && + fs_1.default + .readFileSync(versionFilePath) + .toString() + .trim(); + let versionSpec = core.getInput('go-version') || versionSpecFromFile; // stable will be true unless false is the exact input // since getting unstable versions should be explicit let stable = (core.getInput('stable') || 'true').toUpperCase() === 'TRUE'; From f5fe54e5a4d9da96fcd5fb3684972aee5fc9ee79 Mon Sep 17 00:00:00 2001 From: jojo43 Date: Sun, 5 Jul 2020 11:09:35 +0900 Subject: [PATCH 04/13] Add description of go-version-from-file --- action.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/action.yml b/action.yml index 4a32e12ba..abc026549 100644 --- a/action.yml +++ b/action.yml @@ -4,6 +4,8 @@ author: 'GitHub' inputs: go-version: description: 'The Go version to download (if necessary) and use. Supports semver spec and ranges.' + go-version-from-file: + description: Path to the file with the Go version. go-version overwrites this. stable: description: 'Whether to download only stable versions' default: 'true' From 55b9afc327002fa064c28b79835120a81b1aba06 Mon Sep 17 00:00:00 2001 From: So Jomura Date: Fri, 29 Apr 2022 11:11:36 +0000 Subject: [PATCH 05/13] Read go version from go.mod --- __tests__/setup-go.test.ts | 33 +++++++++++++++++++++++++++------ dist/index.js | 29 +++++++++++++++++++++-------- src/installer.ts | 9 +++++++++ src/main.ts | 27 +++++++++++++++++++-------- 4 files changed, 76 insertions(+), 22 deletions(-) diff --git a/__tests__/setup-go.test.ts b/__tests__/setup-go.test.ts index c241364b0..6cb16fff7 100644 --- a/__tests__/setup-go.test.ts +++ b/__tests__/setup-go.test.ts @@ -559,9 +559,31 @@ describe('setup-go', () => { expect(im.makeSemver('1.13.1')).toBe('1.13.1'); }); - describe('go-version-from-file', () => { - it('reads version from file', async () => { - inputs['go-version-from-file'] = '.go-version'; + describe('go-version-file', () => { + it('reads version from go.mod', async () => { + inputs['go-version-file'] = 'go.mod'; + const content = `module example.com/mymodule + +go 1.14 + +require ( + example.com/othermodule v1.2.3 + example.com/thismodule v1.2.3 + example.com/thatmodule v1.2.3 +) + +replace example.com/thatmodule => ../thatmodule +exclude example.com/thismodule v1.3.0 +`; + readFileSpy.mockImplementation(() => Buffer.from(content)); + + await main.run(); + + expect(logSpy).toHaveBeenCalledWith('Setup go stable version spec 1.14'); + }); + + it('reads version from .go-version', async () => { + inputs['go-version-file'] = '.go-version'; readFileSpy.mockImplementation(() => Buffer.from(`1.13.0${osm.EOL}`)); await main.run(); @@ -573,8 +595,7 @@ describe('setup-go', () => { it('is overwritten by go-version', async () => { inputs['go-version'] = '1.13.1'; - - inputs['go-version-from-file'] = '.go-version'; + inputs['go-version-file'] = '.go-version'; readFileSpy.mockImplementation(() => Buffer.from(`1.13.0${osm.EOL}`)); await main.run(); @@ -586,7 +607,7 @@ describe('setup-go', () => { it('reports a read failure', async () => { const versionFilePath = '.go-version'; - inputs['go-version-from-file'] = versionFilePath; + inputs['go-version-file'] = versionFilePath; const errMsg = `ENOENT: no such file or directory, open '${versionFilePath}'`; readFileSpy.mockImplementation(() => { throw new Error(errMsg); diff --git a/dist/index.js b/dist/index.js index aacd1ca1f..cb4de9475 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1432,13 +1432,7 @@ function run() { // versionSpec is optional. If supplied, install / use from the tool cache // If not supplied then problem matchers will still be setup. Useful for self-hosted. // - const versionFilePath = core.getInput('go-version-from-file'); - const versionSpecFromFile = versionFilePath && - fs_1.default - .readFileSync(versionFilePath) - .toString() - .trim(); - let versionSpec = core.getInput('go-version') || versionSpecFromFile; + const versionSpec = resolveVersionInput(); // stable will be true unless false is the exact input // since getting unstable versions should be explicit let stable = (core.getInput('stable') || 'true').toUpperCase() === 'TRUE'; @@ -1506,6 +1500,17 @@ function isGhes() { const ghUrl = new url_1.URL(process.env['GITHUB_SERVER_URL'] || 'https://github.com'); return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM'; } +function resolveVersionInput() { + let version = core.getInput('go-version'); + const versionFilePath = core.getInput('go-version-file'); + if (version) { + return version; + } + if (versionFilePath) { + version = installer.parseGoVersionFile(fs_1.default.readFileSync(versionFilePath).toString(), path_1.default.basename(versionFilePath) === 'go.mod'); + } + return version; +} /***/ }), @@ -4941,7 +4946,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.makeSemver = exports.getVersionsDist = exports.findMatch = exports.getInfoFromManifest = exports.extractGoArchive = exports.getGo = void 0; +exports.parseGoVersionFile = exports.makeSemver = exports.getVersionsDist = exports.findMatch = exports.getInfoFromManifest = exports.extractGoArchive = exports.getGo = void 0; const tc = __importStar(__webpack_require__(533)); const core = __importStar(__webpack_require__(470)); const path = __importStar(__webpack_require__(622)); @@ -5144,6 +5149,14 @@ function makeSemver(version) { return `${verPart}${prereleasePart}`; } exports.makeSemver = makeSemver; +function parseGoVersionFile(contents, isMod) { + if (!isMod) { + return contents.trim(); + } + const match = contents.match(/^go (\d+(\.\d+)*)/m); + return match ? match[1] : ''; +} +exports.parseGoVersionFile = parseGoVersionFile; /***/ }), diff --git a/src/installer.ts b/src/installer.ts index 08758a48c..bb0a084b7 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -266,3 +266,12 @@ export function makeSemver(version: string): string { return `${verPart}${prereleasePart}`; } + +export function parseGoVersionFile(contents: string, isMod: boolean): string { + if (!isMod) { + return contents.trim(); + } + + const match = contents.match(/^go (\d+(\.\d+)*)/m); + return match ? match[1] : ''; +} diff --git a/src/main.ts b/src/main.ts index 7593e7ab5..d91c19a8a 100644 --- a/src/main.ts +++ b/src/main.ts @@ -12,14 +12,7 @@ export async function run() { // versionSpec is optional. If supplied, install / use from the tool cache // If not supplied then problem matchers will still be setup. Useful for self-hosted. // - const versionFilePath = core.getInput('go-version-from-file'); - const versionSpecFromFile = - versionFilePath && - fs - .readFileSync(versionFilePath) - .toString() - .trim(); - let versionSpec = core.getInput('go-version') || versionSpecFromFile; + const versionSpec = resolveVersionInput(); // stable will be true unless false is the exact input // since getting unstable versions should be explicit @@ -97,3 +90,21 @@ function isGhes(): boolean { ); return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM'; } + +function resolveVersionInput(): string { + let version = core.getInput('go-version'); + const versionFilePath = core.getInput('go-version-file'); + + if (version) { + return version; + } + + if (versionFilePath) { + version = installer.parseGoVersionFile( + fs.readFileSync(versionFilePath).toString(), + path.basename(versionFilePath) === 'go.mod' + ); + } + + return version; +} From df84f4b7c8807f948b0a7e62673bae46fc1419da Mon Sep 17 00:00:00 2001 From: jojo43 Date: Sun, 1 May 2022 11:40:07 +0900 Subject: [PATCH 06/13] Fix go-version-file description --- action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index 294bb34ed..40d662145 100644 --- a/action.yml +++ b/action.yml @@ -4,8 +4,8 @@ author: 'GitHub' inputs: go-version: description: 'The Go version to download (if necessary) and use. Supports semver spec and ranges.' - go-version-from-file: - description: Path to the file with the Go version. go-version overwrites this. + go-version-file: + description: 'Path to the go.mod file.' check-latest: description: 'Set this option to true if you want the action to always check for the latest available version that satisfies the version spec' default: false From fabe2129ee8a8ffea135550bb4b9e71657ef7170 Mon Sep 17 00:00:00 2001 From: jojo43 Date: Sun, 1 May 2022 11:42:54 +0900 Subject: [PATCH 07/13] Add waring when the both inputs are specified --- src/main.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main.ts b/src/main.ts index 546fded3c..1152a295d 100644 --- a/src/main.ts +++ b/src/main.ts @@ -109,6 +109,12 @@ function resolveVersionInput(): string { let version = core.getInput('go-version'); const 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; } From dbe1872ad43ff1347e640f30fcfd4d4eea521016 Mon Sep 17 00:00:00 2001 From: jojo43 Date: Sun, 1 May 2022 11:56:41 +0900 Subject: [PATCH 08/13] Fix parseGoVersionFile --- __tests__/setup-go.test.ts | 16 +++++++++------- src/installer.ts | 13 ++++++++----- src/main.ts | 5 +---- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/__tests__/setup-go.test.ts b/__tests__/setup-go.test.ts index 27531d6f3..895f1d478 100644 --- a/__tests__/setup-go.test.ts +++ b/__tests__/setup-go.test.ts @@ -797,7 +797,9 @@ exclude example.com/thismodule v1.3.0 await main.run(); - expect(logSpy).toHaveBeenCalledWith('Setup go stable version spec 1.14'); + 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 .go-version', async () => { @@ -806,9 +808,9 @@ exclude example.com/thismodule v1.3.0 await main.run(); - expect(logSpy).toHaveBeenCalledWith( - 'Setup go stable version spec 1.13.0' - ); + expect(logSpy).toHaveBeenCalledWith('Setup go version spec 1.13.0'); + expect(logSpy).toHaveBeenCalledWith('Attempting to download 1.13.0...'); + expect(logSpy).toHaveBeenCalledWith('matching 1.13.0...'); }); it('is overwritten by go-version', async () => { @@ -818,9 +820,9 @@ exclude example.com/thismodule v1.3.0 await main.run(); - expect(logSpy).toHaveBeenCalledWith( - 'Setup go stable version spec 1.13.1' - ); + expect(logSpy).toHaveBeenCalledWith('Setup go version spec 1.13.1'); + expect(logSpy).toHaveBeenCalledWith('Attempting to download 1.13.1...'); + expect(logSpy).toHaveBeenCalledWith('matching 1.13.1...'); }); it('reports a read failure', async () => { diff --git a/src/installer.ts b/src/installer.ts index 6a147b51c..c1a1e3959 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -4,6 +4,7 @@ import * as path from 'path'; import * as semver from 'semver'; import * as httpm from '@actions/http-client'; import * as sys from './system'; +import fs from 'fs'; import os from 'os'; type InstallationType = 'dist' | 'manifest'; @@ -299,11 +300,13 @@ export function makeSemver(version: string): string { return fullVersion; } -export function parseGoVersionFile(contents: string, isMod: boolean): string { - if (!isMod) { - return contents.trim(); +export function parseGoVersionFile(versionFilePath: string): string { + const contents = fs.readFileSync(versionFilePath).toString(); + + if (path.basename(versionFilePath) === 'go.mod') { + const match = contents.match(/^go (\d+(\.\d+)*)/m); + return match ? match[1] : ''; } - const match = contents.match(/^go (\d+(\.\d+)*)/m); - return match ? match[1] : ''; + return contents.trim(); } diff --git a/src/main.ts b/src/main.ts index 1152a295d..ca31f39bd 100644 --- a/src/main.ts +++ b/src/main.ts @@ -120,10 +120,7 @@ function resolveVersionInput(): string { } if (versionFilePath) { - version = installer.parseGoVersionFile( - fs.readFileSync(versionFilePath).toString(), - path.basename(versionFilePath) === 'go.mod' - ); + version = installer.parseGoVersionFile(versionFilePath); } return version; From 1fefa4e32448a302a8330935afc33e15b3234f6d Mon Sep 17 00:00:00 2001 From: jojo43 Date: Sun, 1 May 2022 12:09:36 +0900 Subject: [PATCH 09/13] Add checking if the specified file exist --- __tests__/setup-go.test.ts | 28 +++++++++++++++------------- src/main.ts | 5 +++++ 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/__tests__/setup-go.test.ts b/__tests__/setup-go.test.ts index 895f1d478..1f1f29db7 100644 --- a/__tests__/setup-go.test.ts +++ b/__tests__/setup-go.test.ts @@ -778,9 +778,7 @@ describe('setup-go', () => { }); describe('go-version-file', () => { - it('reads version from go.mod', async () => { - inputs['go-version-file'] = 'go.mod'; - const content = `module example.com/mymodule + const goModContents = `module example.com/mymodule go 1.14 @@ -793,7 +791,11 @@ require ( replace example.com/thatmodule => ../thatmodule exclude example.com/thismodule v1.3.0 `; - readFileSpy.mockImplementation(() => Buffer.from(content)); + + it('reads version from go.mod', async () => { + inputs['go-version-file'] = 'go.mod'; + existsSpy.mockImplementation(path => true); + readFileSpy.mockImplementation(() => Buffer.from(goModContents)); await main.run(); @@ -804,6 +806,7 @@ exclude example.com/thismodule v1.3.0 it('reads version from .go-version', async () => { inputs['go-version-file'] = '.go-version'; + existsSpy.mockImplementation(path => true); readFileSpy.mockImplementation(() => Buffer.from(`1.13.0${osm.EOL}`)); await main.run(); @@ -815,8 +818,9 @@ exclude example.com/thismodule v1.3.0 it('is overwritten by go-version', async () => { inputs['go-version'] = '1.13.1'; - inputs['go-version-file'] = '.go-version'; - readFileSpy.mockImplementation(() => Buffer.from(`1.13.0${osm.EOL}`)); + inputs['go-version-file'] = 'go.mod'; + existsSpy.mockImplementation(path => true); + readFileSpy.mockImplementation(() => Buffer.from(goModContents)); await main.run(); @@ -826,16 +830,14 @@ exclude example.com/thismodule v1.3.0 }); it('reports a read failure', async () => { - const versionFilePath = '.go-version'; - inputs['go-version-file'] = versionFilePath; - const errMsg = `ENOENT: no such file or directory, open '${versionFilePath}'`; - readFileSpy.mockImplementation(() => { - throw new Error(errMsg); - }); + inputs['go-version-file'] = 'go.mod'; + existsSpy.mockImplementation(path => false); await main.run(); - expect(cnSpy).toHaveBeenCalledWith(`::error::${errMsg}${osm.EOL}`); + expect(cnSpy).toHaveBeenCalledWith( + `::error::The specified go version file at: go.mod does not exist${osm.EOL}` + ); }); }); }); diff --git a/src/main.ts b/src/main.ts index ca31f39bd..991a0002f 100644 --- a/src/main.ts +++ b/src/main.ts @@ -120,6 +120,11 @@ function resolveVersionInput(): string { } if (versionFilePath) { + if (!fs.existsSync(versionFilePath)) { + throw new Error( + `The specified go version file at: ${versionFilePath} does not exist` + ); + } version = installer.parseGoVersionFile(versionFilePath); } From 676a55b643f29f14efc29a4a8a55e99f2a6ec0f1 Mon Sep 17 00:00:00 2001 From: jojo43 Date: Sun, 1 May 2022 12:46:11 +0900 Subject: [PATCH 10/13] npm run build --- dist/index.js | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/dist/index.js b/dist/index.js index 0bb9dea99..e40505e6c 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2157,11 +2157,17 @@ exports.parseGoVersion = parseGoVersion; function resolveVersionInput() { let version = core.getInput('go-version'); const 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 (versionFilePath) { - version = installer.parseGoVersionFile(fs_1.default.readFileSync(versionFilePath).toString(), path_1.default.basename(versionFilePath) === 'go.mod'); + if (!fs_1.default.existsSync(versionFilePath)) { + throw new Error(`The specified go version file at: ${versionFilePath} does not exist`); + } + version = installer.parseGoVersionFile(versionFilePath); } return version; } @@ -5825,8 +5831,8 @@ class OidcClient { const res = yield httpclient .getJson(id_token_url) .catch(error => { - throw new Error(`Failed to get ID Token. \n - Error Code : ${error.statusCode}\n + throw new Error(`Failed to get ID Token. \n + Error Code : ${error.statusCode}\n Error Message: ${error.result.message}`); }); const id_token = (_a = res.result) === null || _a === void 0 ? void 0 : _a.value; @@ -5912,6 +5918,7 @@ const path = __importStar(__webpack_require__(622)); const semver = __importStar(__webpack_require__(280)); const httpm = __importStar(__webpack_require__(539)); const sys = __importStar(__webpack_require__(737)); +const fs_1 = __importDefault(__webpack_require__(747)); const os_1 = __importDefault(__webpack_require__(87)); function getGo(versionSpec, checkLatest, auth) { return __awaiter(this, void 0, void 0, function* () { @@ -6130,12 +6137,13 @@ function makeSemver(version) { return fullVersion; } exports.makeSemver = makeSemver; -function parseGoVersionFile(contents, isMod) { - if (!isMod) { - return contents.trim(); +function parseGoVersionFile(versionFilePath) { + const contents = fs_1.default.readFileSync(versionFilePath).toString(); + if (path.basename(versionFilePath) === 'go.mod') { + const match = contents.match(/^go (\d+(\.\d+)*)/m); + return match ? match[1] : ''; } - const match = contents.match(/^go (\d+(\.\d+)*)/m); - return match ? match[1] : ''; + return contents.trim(); } exports.parseGoVersionFile = parseGoVersionFile; //# sourceMappingURL=installer.js.map @@ -6386,4 +6394,4 @@ exports.exec = exec; /***/ }) -/******/ }); +/******/ }); \ No newline at end of file From 0cd474d058c80a4670e30ba7859254955b9264e8 Mon Sep 17 00:00:00 2001 From: jojo43 Date: Tue, 3 May 2022 14:07:34 +0900 Subject: [PATCH 11/13] Add a job with go-version-file --- .github/workflows/versions.yml | 16 ++++++++++++++++ __tests__/data/go.mod | 12 ++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 __tests__/data/go.mod diff --git a/.github/workflows/versions.yml b/.github/workflows/versions.yml index 79683ecaf..12c711e3f 100644 --- a/.github/workflows/versions.yml +++ b/.github/workflows/versions.yml @@ -50,6 +50,22 @@ jobs: - name: Verify Go run: go version + go-version-file: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + steps: + - uses: actions/checkout@v3 + - name: Setup Go and check latest + uses: ./ + with: + go-version-file: __tests__/data/go.mod + - name: verify go + run: __tests__/verify-go.sh 1.14 + shell: bash + setup-versions-from-manifest: name: Setup ${{ matrix.go }} ${{ matrix.os }} runs-on: ${{ matrix.os }} diff --git a/__tests__/data/go.mod b/__tests__/data/go.mod new file mode 100644 index 000000000..dea3480ee --- /dev/null +++ b/__tests__/data/go.mod @@ -0,0 +1,12 @@ +module example.com/mymodule + +go 1.14 + +require ( + example.com/othermodule v1.2.3 + example.com/thismodule v1.2.3 + example.com/thatmodule v1.2.3 +) + +replace example.com/thatmodule => ../thatmodule +exclude example.com/thismodule v1.3.0 From aa32cee4cf13b63892acb2d488b648b57d147407 Mon Sep 17 00:00:00 2001 From: jojo43 Date: Sat, 7 May 2022 08:58:45 +0900 Subject: [PATCH 12/13] Add go-version-file description --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index 20440a442..fa92571cf 100644 --- a/README.md +++ b/README.md @@ -123,6 +123,22 @@ The `go-version` input supports the following syntax: For more information about semantic versioning, please refer to [semver](https://github.com/npm/node-semver) documentation. +## Getting go version from the go.mod file + +The `go-version-file` input accepts a path to a `go.mod` file containing the version of Go to be used by a project. As the `go.mod` file contains only major and minor (e.g. 1.18) tags, the action will search for the latest available patch version sequentially in the runner's directory with the cached tools, in the [version-manifest.json](https://github.com/actions/go-versions/blob/main/versions-manifest.json) file or at the go servers. + +If both the `go-version` and the `go-version-file` inputs are provided then the `go-version` input is used. +> The action will search for the `go.mod` file relative to the repository root + +```yaml +steps: +- uses: actions/checkout@v3 +- uses: actions/setup-go@v3 + with: + go-version-file: '**/go.mod' +- run: go version +``` + # License The scripts and documentation in this project are released under the [MIT License](LICENSE) From a6b717db01f3c612177a0623b846aed66e0c769e Mon Sep 17 00:00:00 2001 From: IvanZosimov Date: Mon, 9 May 2022 11:03:31 +0200 Subject: [PATCH 13/13] Change README.md file Shifted chapter related to retrieving go version from go.mod file and updated yml example --- README.md | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index fa92571cf..64ecf7abc 100644 --- a/README.md +++ b/README.md @@ -94,6 +94,21 @@ steps: check-latest: true - run: go run hello.go ``` +## Getting go version from the go.mod file + +The `go-version-file` input accepts a path to a `go.mod` file containing the version of Go to be used by a project. As the `go.mod` file contains only major and minor (e.g. 1.18) tags, the action will search for the latest available patch version sequentially in the runner's directory with the cached tools, in the [version-manifest.json](https://github.com/actions/go-versions/blob/main/versions-manifest.json) file or at the go servers. + +If both the `go-version` and the `go-version-file` inputs are provided then the `go-version` input is used. +> The action will search for the `go.mod` file relative to the repository root + +```yaml +steps: +- uses: actions/checkout@v3 +- uses: actions/setup-go@v3 + with: + go-version-file: 'path/to/go.mod' +- run: go version +``` ## Matrix testing @@ -123,22 +138,6 @@ The `go-version` input supports the following syntax: For more information about semantic versioning, please refer to [semver](https://github.com/npm/node-semver) documentation. -## Getting go version from the go.mod file - -The `go-version-file` input accepts a path to a `go.mod` file containing the version of Go to be used by a project. As the `go.mod` file contains only major and minor (e.g. 1.18) tags, the action will search for the latest available patch version sequentially in the runner's directory with the cached tools, in the [version-manifest.json](https://github.com/actions/go-versions/blob/main/versions-manifest.json) file or at the go servers. - -If both the `go-version` and the `go-version-file` inputs are provided then the `go-version` input is used. -> The action will search for the `go.mod` file relative to the repository root - -```yaml -steps: -- uses: actions/checkout@v3 -- uses: actions/setup-go@v3 - with: - go-version-file: '**/go.mod' -- run: go version -``` - # License The scripts and documentation in this project are released under the [MIT License](LICENSE)