From 7fb5bea2dd6044c13578b39d351de3694b3ba764 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Tue, 11 Feb 2020 16:33:09 +0100 Subject: [PATCH] Solve conflicts --- dist/index.js | 474 +++++++++++++++++++++++++++----------------------- src/main.ts | 12 ++ src/system.ts | 17 +- 3 files changed, 281 insertions(+), 222 deletions(-) diff --git a/dist/index.js b/dist/index.js index 21783e6..4238e83 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1246,10 +1246,10 @@ exports.debug = debug; // for test /***/ (function(__unusedmodule, exports, __webpack_require__) { "use strict"; - -Object.defineProperty(exports, "__esModule", { value: true }); -const main_1 = __webpack_require__(198); -main_1.run(); + +Object.defineProperty(exports, "__esModule", { value: true }); +const main_1 = __webpack_require__(198); +main_1.run(); /***/ }), @@ -1258,65 +1258,76 @@ main_1.run(); /***/ (function(__unusedmodule, exports, __webpack_require__) { "use strict"; - -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; - result["default"] = mod; - return result; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const core = __importStar(__webpack_require__(470)); -const tc = __importStar(__webpack_require__(533)); -const installer = __importStar(__webpack_require__(749)); -const path = __importStar(__webpack_require__(622)); -function run() { - return __awaiter(this, void 0, void 0, function* () { - try { - // - // 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'); - // 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'; - console.log(`Setup go ${stable ? 'stable' : ''} version spec ${versionSpec}`); - if (versionSpec) { - let installDir = tc.find('go', versionSpec); - if (!installDir) { - console.log(`A version satisfying ${versionSpec} not found locally, attempting to download ...`); - installDir = yield installer.downloadGo(versionSpec, stable); - console.log('Installed'); - } - if (installDir) { - core.exportVariable('GOROOT', installDir); - core.addPath(path.join(installDir, 'bin')); - console.log('Added go to the path'); - } - else { - throw new Error(`Could not find a version that satisfied version spec: ${versionSpec}`); - } - } - // add problem matchers - const matchersPath = path.join(__dirname, '..', 'matchers.json'); - console.log(`##[add-matcher]${matchersPath}`); - } - catch (error) { - core.setFailed(error.message); - } - }); -} -exports.run = run; + +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; + result["default"] = mod; + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const core = __importStar(__webpack_require__(470)); +const tc = __importStar(__webpack_require__(533)); +const installer = __importStar(__webpack_require__(749)); +const path = __importStar(__webpack_require__(622)); +const system = __importStar(__webpack_require__(737)); +function run() { + return __awaiter(this, void 0, void 0, function* () { + try { + // + // 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'); + // 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'; + console.log(`Setup go ${stable ? 'stable' : ''} version spec ${versionSpec}`); + if (versionSpec) { + let installDir = tc.find('go', versionSpec); + if (!installDir) { + console.log(`A version satisfying ${versionSpec} not found locally, attempting to download ...`); + installDir = yield installer.downloadGo(versionSpec, stable); + console.log('Installed'); + } + if (installDir) { + core.exportVariable('GOROOT', installDir); + core.addPath(path.join(installDir, 'bin')); + console.log('Added go to the path'); + // set GOPATH and GOBIN as user value + const goPath = system.getGoPath(); + if (goPath) { + core.exportVariable('GOPATH', goPath); + core.addPath(path.join(goPath, 'bin')); + } + const goBin = process.env['GOBIN'] || ''; + if (goBin) { + core.exportVariable('GOBIN', goBin); + } + } + else { + throw new Error(`Could not find a version that satisfied version spec: ${versionSpec}`); + } + } + // add problem matchers + const matchersPath = path.join(__dirname, '..', 'matchers.json'); + console.log(`##[add-matcher]${matchersPath}`); + } + catch (error) { + core.setFailed(error.message); + } + }); +} +exports.run = run; /***/ }), @@ -4509,40 +4520,61 @@ module.exports = bytesToUuid; /***/ (function(__unusedmodule, exports, __webpack_require__) { "use strict"; - -Object.defineProperty(exports, "__esModule", { value: true }); -let os = __webpack_require__(87); -function getPlatform() { - // darwin and linux match already - // freebsd not supported yet but future proofed. - // 'aix', 'darwin', 'freebsd', 'linux', 'openbsd', 'sunos', and 'win32' - let plat = os.platform(); - // wants 'darwin', 'freebsd', 'linux', 'windows' - if (plat === 'win32') { - plat = 'windows'; - } - return plat; -} -exports.getPlatform = getPlatform; -function getArch() { - // 'arm', 'arm64', 'ia32', 'mips', 'mipsel', 'ppc', 'ppc64', 's390', 's390x', 'x32', and 'x64'. - let arch = os.arch(); - // wants amd64, 386, arm64, armv61, ppc641e, s390x - // currently not supported by runner but future proofed mapping - switch (arch) { - case 'x64': - arch = 'amd64'; - break; - // case 'ppc': - // arch = 'ppc64'; - // break; - case 'x32': - arch = '386'; - break; - } - return arch; -} -exports.getArch = getArch; + +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; + result["default"] = mod; + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const os = __importStar(__webpack_require__(87)); +const path = __importStar(__webpack_require__(622)); +function getPlatform() { + // darwin and linux match already + // freebsd not supported yet but future proofed. + // 'aix', 'darwin', 'freebsd', 'linux', 'openbsd', 'sunos', and 'win32' + let plat = os.platform(); + // wants 'darwin', 'freebsd', 'linux', 'windows' + if (plat === 'win32') { + plat = 'windows'; + } + return plat; +} +exports.getPlatform = getPlatform; +function getArch() { + // 'arm', 'arm64', 'ia32', 'mips', 'mipsel', 'ppc', 'ppc64', 's390', 's390x', 'x32', and 'x64'. + let arch = os.arch(); + // wants amd64, 386, arm64, armv61, ppc641e, s390x + // currently not supported by runner but future proofed mapping + switch (arch) { + case 'x64': + arch = 'amd64'; + break; + // case 'ppc': + // arch = 'ppc64'; + // break; + case 'x32': + arch = '386'; + break; + } + return arch; +} +exports.getArch = getArch; +// Get GOPATH as user value or as defined by https://golang.org/doc/code.html#GOPATH +function getGoPath() { + const home = process.env['HOME'] || ''; + const goPath = process.env['GOPATH'] || ''; + if (goPath) { + return goPath; + } + else if (home) { + return path.join(home, 'go'); + } + return ''; +} +exports.getGoPath = getGoPath; /***/ }), @@ -4558,130 +4590,130 @@ module.exports = require("fs"); /***/ (function(module, exports, __webpack_require__) { "use strict"; - -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; - result["default"] = mod; - return result; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const tc = __importStar(__webpack_require__(533)); -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 core_1 = __webpack_require__(470); -function downloadGo(versionSpec, stable) { - return __awaiter(this, void 0, void 0, function* () { - let toolPath; - try { - let match = yield findMatch(versionSpec, stable); - if (match) { - // download - core_1.debug(`match ${match.version}`); - let downloadUrl = `https://storage.googleapis.com/golang/${match.files[0].filename}`; - console.log(`Downloading from ${downloadUrl}`); - let downloadPath = yield tc.downloadTool(downloadUrl); - core_1.debug(`downloaded to ${downloadPath}`); - // extract - console.log('Extracting ...'); - let extPath = sys.getPlatform() == 'windows' - ? yield tc.extractZip(downloadPath) - : yield tc.extractTar(downloadPath); - core_1.debug(`extracted to ${extPath}`); - // extracts with a root folder that matches the fileName downloaded - const toolRoot = path.join(extPath, 'go'); - toolPath = yield tc.cacheDir(toolRoot, 'go', versionSpec); - } - } - catch (error) { - throw new Error(`Failed to download version ${versionSpec}: ${error}`); - } - return toolPath; - }); -} -exports.downloadGo = downloadGo; -function findMatch(versionSpec, stable) { - return __awaiter(this, void 0, void 0, function* () { - let archFilter = sys.getArch(); - let platFilter = sys.getPlatform(); - let result; - let match; - const dlUrl = 'https://golang.org/dl/?mode=json&include=all'; - let candidates = yield module.exports.getVersions(dlUrl); - if (!candidates) { - throw new Error(`golang download url did not return results`); - } - let goFile; - for (let i = 0; i < candidates.length; i++) { - let candidate = candidates[i]; - let version = makeSemver(candidate.version); - // 1.13.0 is advertised as 1.13 preventing being able to match exactly 1.13.0 - // since a semver of 1.13 would match latest 1.13 - let parts = version.split('.'); - if (parts.length == 2) { - version = version + '.0'; - } - core_1.debug(`check ${version} satisfies ${versionSpec}`); - if (semver.satisfies(version, versionSpec) && - (!stable || candidate.stable === stable)) { - goFile = candidate.files.find(file => { - core_1.debug(`${file.arch}===${archFilter} && ${file.os}===${platFilter}`); - return file.arch === archFilter && file.os === platFilter; - }); - if (goFile) { - core_1.debug(`matched ${candidate.version}`); - match = candidate; - break; - } - } - } - if (match && goFile) { - // clone since we're mutating the file list to be only the file that matches - result = Object.assign({}, match); - result.files = [goFile]; - } - return result; - }); -} -exports.findMatch = findMatch; -function getVersions(dlUrl) { - return __awaiter(this, void 0, void 0, function* () { - // this returns versions descending so latest is first - let http = new httpm.HttpClient('setup-go'); - return (yield http.getJson(dlUrl)).result; - }); -} -exports.getVersions = getVersions; -// -// Convert the go version syntax into semver for semver matching -// 1.13.1 => 1.13.1 -// 1.13 => 1.13.0 -// 1.10beta1 => 1.10.0-beta1, 1.10rc1 => 1.10.0-rc1 -// 1.8.5beta1 => 1.8.5-beta1, 1.8.5rc1 => 1.8.5-rc1 -function makeSemver(version) { - version = version.replace('go', ''); - version = version.replace('beta', '-beta').replace('rc', '-rc'); - let parts = version.split('-'); - let verPart = parts[0]; - let prereleasePart = parts.length > 1 ? `-${parts[1]}` : ''; - let verParts = verPart.split('.'); - if (verParts.length == 2) { - verPart += '.0'; - } - return `${verPart}${prereleasePart}`; -} -exports.makeSemver = makeSemver; + +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; + result["default"] = mod; + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const tc = __importStar(__webpack_require__(533)); +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 core_1 = __webpack_require__(470); +function downloadGo(versionSpec, stable) { + return __awaiter(this, void 0, void 0, function* () { + let toolPath; + try { + let match = yield findMatch(versionSpec, stable); + if (match) { + // download + core_1.debug(`match ${match.version}`); + let downloadUrl = `https://storage.googleapis.com/golang/${match.files[0].filename}`; + console.log(`Downloading from ${downloadUrl}`); + let downloadPath = yield tc.downloadTool(downloadUrl); + core_1.debug(`downloaded to ${downloadPath}`); + // extract + console.log('Extracting ...'); + let extPath = sys.getPlatform() == 'windows' + ? yield tc.extractZip(downloadPath) + : yield tc.extractTar(downloadPath); + core_1.debug(`extracted to ${extPath}`); + // extracts with a root folder that matches the fileName downloaded + const toolRoot = path.join(extPath, 'go'); + toolPath = yield tc.cacheDir(toolRoot, 'go', versionSpec); + } + } + catch (error) { + throw new Error(`Failed to download version ${versionSpec}: ${error}`); + } + return toolPath; + }); +} +exports.downloadGo = downloadGo; +function findMatch(versionSpec, stable) { + return __awaiter(this, void 0, void 0, function* () { + let archFilter = sys.getArch(); + let platFilter = sys.getPlatform(); + let result; + let match; + const dlUrl = 'https://golang.org/dl/?mode=json&include=all'; + let candidates = yield module.exports.getVersions(dlUrl); + if (!candidates) { + throw new Error(`golang download url did not return results`); + } + let goFile; + for (let i = 0; i < candidates.length; i++) { + let candidate = candidates[i]; + let version = makeSemver(candidate.version); + // 1.13.0 is advertised as 1.13 preventing being able to match exactly 1.13.0 + // since a semver of 1.13 would match latest 1.13 + let parts = version.split('.'); + if (parts.length == 2) { + version = version + '.0'; + } + core_1.debug(`check ${version} satisfies ${versionSpec}`); + if (semver.satisfies(version, versionSpec) && + (!stable || candidate.stable === stable)) { + goFile = candidate.files.find(file => { + core_1.debug(`${file.arch}===${archFilter} && ${file.os}===${platFilter}`); + return file.arch === archFilter && file.os === platFilter; + }); + if (goFile) { + core_1.debug(`matched ${candidate.version}`); + match = candidate; + break; + } + } + } + if (match && goFile) { + // clone since we're mutating the file list to be only the file that matches + result = Object.assign({}, match); + result.files = [goFile]; + } + return result; + }); +} +exports.findMatch = findMatch; +function getVersions(dlUrl) { + return __awaiter(this, void 0, void 0, function* () { + // this returns versions descending so latest is first + let http = new httpm.HttpClient('setup-go'); + return (yield http.getJson(dlUrl)).result; + }); +} +exports.getVersions = getVersions; +// +// Convert the go version syntax into semver for semver matching +// 1.13.1 => 1.13.1 +// 1.13 => 1.13.0 +// 1.10beta1 => 1.10.0-beta1, 1.10rc1 => 1.10.0-rc1 +// 1.8.5beta1 => 1.8.5-beta1, 1.8.5rc1 => 1.8.5-rc1 +function makeSemver(version) { + version = version.replace('go', ''); + version = version.replace('beta', '-beta').replace('rc', '-rc'); + let parts = version.split('-'); + let verPart = parts[0]; + let prereleasePart = parts.length > 1 ? `-${parts[1]}` : ''; + let verParts = verPart.split('.'); + if (verParts.length == 2) { + verPart += '.0'; + } + return `${verPart}${prereleasePart}`; +} +exports.makeSemver = makeSemver; /***/ }), diff --git a/src/main.ts b/src/main.ts index 132be9b..30856e3 100644 --- a/src/main.ts +++ b/src/main.ts @@ -2,6 +2,7 @@ import * as core from '@actions/core'; import * as tc from '@actions/tool-cache'; import * as installer from './installer'; import * as path from 'path'; +import * as system from './system'; export async function run() { try { @@ -34,6 +35,17 @@ export async function run() { core.exportVariable('GOROOT', installDir); core.addPath(path.join(installDir, 'bin')); console.log('Added go to the path'); + + // set GOPATH and GOBIN as user value + const goPath: string = system.getGoPath(); + if (goPath) { + core.exportVariable('GOPATH', goPath); + core.addPath(path.join(goPath, 'bin')); + } + const goBin: string = process.env['GOBIN'] || ''; + if (goBin) { + core.exportVariable('GOBIN', goBin); + } } else { throw new Error( `Could not find a version that satisfied version spec: ${versionSpec}` diff --git a/src/system.ts b/src/system.ts index 8dfad42..992760c 100644 --- a/src/system.ts +++ b/src/system.ts @@ -1,4 +1,5 @@ -let os = require('os'); +import * as os from 'os'; +import * as path from 'path'; export function getPlatform(): string { // darwin and linux match already @@ -35,3 +36,17 @@ export function getArch(): string { return arch; } + +// Get GOPATH as user value or as defined by https://golang.org/doc/code.html#GOPATH +export function getGoPath(): string { + const home: string = process.env['HOME'] || ''; + const goPath: string = process.env['GOPATH'] || ''; + + if (goPath) { + return goPath; + } else if (home) { + return path.join(home, 'go'); + } + + return ''; +}