diff --git a/__tests__/setup-go.test.ts b/__tests__/setup-go.test.ts index bb85dee..8c5033b 100644 --- a/__tests__/setup-go.test.ts +++ b/__tests__/setup-go.test.ts @@ -105,6 +105,11 @@ describe('setup-go', () => { jest.restoreAllMocks(); }, 100000); + it('can extract the major.minor.patch version from a given Go version string', async () => { + const goVersionOutput = 'go version go1.16.6 darwin/amd64'; + expect(main.parseGoVersion(goVersionOutput)).toBe('1.16.6'); + }); + it('can find 1.9.7 from manifest on osx', async () => { os.platform = 'darwin'; os.arch = 'x64'; diff --git a/dist/index.js b/dist/index.js index d194ebf..74206fb 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2058,7 +2058,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.addBinToPath = exports.run = void 0; +exports.parseGoVersion = exports.addBinToPath = exports.run = void 0; const core = __importStar(__webpack_require__(470)); const io = __importStar(__webpack_require__(1)); const installer = __importStar(__webpack_require__(749)); @@ -2100,12 +2100,7 @@ function run() { let goPath = yield io.which('go'); let goVersion = (child_process_1.default.execSync(`${goPath} version`) || '').toString(); core.info(goVersion); - // get the installed version as an Action output - // based on go/src/cmd/go/internal/version/version.go: - // fmt.Printf("go version %s %s/%s\n", runtime.Version(), runtime.GOOS, runtime.GOARCH) - // expecting go for runtime.Version() - let goVersionOutput = [...goVersion.split(' ')[2]].slice(2).join(''); - core.setOutput('go-version', goVersionOutput); + core.setOutput('go-version', parseGoVersion(goVersion)); core.startGroup('go env'); let goEnv = (child_process_1.default.execSync(`${goPath} env`) || '').toString(); core.info(goEnv); @@ -2151,6 +2146,14 @@ function isGhes() { const ghUrl = new url_1.URL(process.env['GITHUB_SERVER_URL'] || 'https://github.com'); return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM'; } +function parseGoVersion(versionString) { + // get the installed version as an Action output + // based on go/src/cmd/go/internal/version/version.go: + // fmt.Printf("go version %s %s/%s\n", runtime.Version(), runtime.GOOS, runtime.GOARCH) + // expecting go for runtime.Version() + return versionString.split(' ')[2].slice('go'.length); +} +exports.parseGoVersion = parseGoVersion; //# sourceMappingURL=main.js.map /***/ }), diff --git a/src/main.ts b/src/main.ts index 75c9587..a5caf9b 100644 --- a/src/main.ts +++ b/src/main.ts @@ -48,12 +48,7 @@ export async function run() { let goVersion = (cp.execSync(`${goPath} version`) || '').toString(); core.info(goVersion); - // get the installed version as an Action output - // based on go/src/cmd/go/internal/version/version.go: - // fmt.Printf("go version %s %s/%s\n", runtime.Version(), runtime.GOOS, runtime.GOARCH) - // expecting go for runtime.Version() - let goVersionOutput = [...goVersion.split(' ')[2]].slice(2).join(''); - core.setOutput('go-version', goVersionOutput); + core.setOutput('go-version', parseGoVersion(goVersion)); core.startGroup('go env'); let goEnv = (cp.execSync(`${goPath} env`) || '').toString(); @@ -101,3 +96,11 @@ function isGhes(): boolean { ); return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM'; } + +export function parseGoVersion(versionString: string): string { + // get the installed version as an Action output + // based on go/src/cmd/go/internal/version/version.go: + // fmt.Printf("go version %s %s/%s\n", runtime.Version(), runtime.GOOS, runtime.GOARCH) + // expecting go for runtime.Version() + return versionString.split(' ')[2].slice('go'.length); +}