mirror of
				https://gitea.com/actions/setup-go.git
				synced 2025-10-31 09:08:13 +07:00 
			
		
		
		
	Remove stable input and fix SemVer notation (#195)
This commit is contained in:
		
							parent
							
								
									2bb2aab2fd
								
							
						
					
					
						commit
						f6164bd8c8
					
				| @ -147,7 +147,7 @@ describe('setup-go', () => { | |||||||
|     os.arch = 'x64'; |     os.arch = 'x64'; | ||||||
| 
 | 
 | ||||||
|     // spec: 1.13.0 => 1.13
 |     // spec: 1.13.0 => 1.13
 | ||||||
|     let match: im.IGoVersion | undefined = await im.findMatch('1.13.0', true); |     let match: im.IGoVersion | undefined = await im.findMatch('1.13.0'); | ||||||
|     expect(match).toBeDefined(); |     expect(match).toBeDefined(); | ||||||
|     let version: string = match ? match.version : ''; |     let version: string = match ? match.version : ''; | ||||||
|     expect(version).toBe('go1.13'); |     expect(version).toBe('go1.13'); | ||||||
| @ -160,7 +160,7 @@ describe('setup-go', () => { | |||||||
|     os.arch = 'x64'; |     os.arch = 'x64'; | ||||||
| 
 | 
 | ||||||
|     // spec: 1.13 => 1.13.7 (latest)
 |     // spec: 1.13 => 1.13.7 (latest)
 | ||||||
|     let match: im.IGoVersion | undefined = await im.findMatch('1.13', true); |     let match: im.IGoVersion | undefined = await im.findMatch('1.13'); | ||||||
|     expect(match).toBeDefined(); |     expect(match).toBeDefined(); | ||||||
|     let version: string = match ? match.version : ''; |     let version: string = match ? match.version : ''; | ||||||
|     expect(version).toBe('go1.13.7'); |     expect(version).toBe('go1.13.7'); | ||||||
| @ -173,7 +173,7 @@ describe('setup-go', () => { | |||||||
|     os.arch = 'x64'; |     os.arch = 'x64'; | ||||||
| 
 | 
 | ||||||
|     // spec: ^1.13.6 => 1.13.7
 |     // spec: ^1.13.6 => 1.13.7
 | ||||||
|     let match: im.IGoVersion | undefined = await im.findMatch('^1.13.6', true); |     let match: im.IGoVersion | undefined = await im.findMatch('^1.13.6'); | ||||||
|     expect(match).toBeDefined(); |     expect(match).toBeDefined(); | ||||||
|     let version: string = match ? match.version : ''; |     let version: string = match ? match.version : ''; | ||||||
|     expect(version).toBe('go1.13.7'); |     expect(version).toBe('go1.13.7'); | ||||||
| @ -186,7 +186,7 @@ describe('setup-go', () => { | |||||||
|     os.arch = 'x32'; |     os.arch = 'x32'; | ||||||
| 
 | 
 | ||||||
|     // spec: 1 => 1.13.7 (latest)
 |     // spec: 1 => 1.13.7 (latest)
 | ||||||
|     let match: im.IGoVersion | undefined = await im.findMatch('1', true); |     let match: im.IGoVersion | undefined = await im.findMatch('1'); | ||||||
|     expect(match).toBeDefined(); |     expect(match).toBeDefined(); | ||||||
|     let version: string = match ? match.version : ''; |     let version: string = match ? match.version : ''; | ||||||
|     expect(version).toBe('go1.13.7'); |     expect(version).toBe('go1.13.7'); | ||||||
| @ -199,10 +199,7 @@ describe('setup-go', () => { | |||||||
|     os.arch = 'x64'; |     os.arch = 'x64'; | ||||||
| 
 | 
 | ||||||
|     // spec: 1.14, stable=false => go1.14rc1
 |     // spec: 1.14, stable=false => go1.14rc1
 | ||||||
|     let match: im.IGoVersion | undefined = await im.findMatch( |     let match: im.IGoVersion | undefined = await im.findMatch('1.14.0-rc.1'); | ||||||
|       '1.14.0-rc1', |  | ||||||
|       false |  | ||||||
|     ); |  | ||||||
|     expect(match).toBeDefined(); |     expect(match).toBeDefined(); | ||||||
|     let version: string = match ? match.version : ''; |     let version: string = match ? match.version : ''; | ||||||
|     expect(version).toBe('go1.14rc1'); |     expect(version).toBe('go1.14rc1'); | ||||||
| @ -218,7 +215,7 @@ describe('setup-go', () => { | |||||||
|     findSpy.mockImplementation(() => toolPath); |     findSpy.mockImplementation(() => toolPath); | ||||||
|     await main.run(); |     await main.run(); | ||||||
| 
 | 
 | ||||||
|     expect(logSpy).toHaveBeenCalledWith(`Setup go stable version spec 1.13.0`); |     expect(logSpy).toHaveBeenCalledWith(`Setup go version spec 1.13.0`); | ||||||
|   }); |   }); | ||||||
| 
 | 
 | ||||||
|   it('evaluates to stable with no input', async () => { |   it('evaluates to stable with no input', async () => { | ||||||
| @ -230,7 +227,7 @@ describe('setup-go', () => { | |||||||
|     findSpy.mockImplementation(() => toolPath); |     findSpy.mockImplementation(() => toolPath); | ||||||
|     await main.run(); |     await main.run(); | ||||||
| 
 | 
 | ||||||
|     expect(logSpy).toHaveBeenCalledWith(`Setup go stable version spec 1.13.0`); |     expect(logSpy).toHaveBeenCalledWith(`Setup go version spec 1.13.0`); | ||||||
|   }); |   }); | ||||||
| 
 | 
 | ||||||
|   it('finds a version of go already in the cache', async () => { |   it('finds a version of go already in the cache', async () => { | ||||||
| @ -396,7 +393,7 @@ describe('setup-go', () => { | |||||||
|     await main.run(); |     await main.run(); | ||||||
| 
 | 
 | ||||||
|     let expPath = path.join(toolPath, 'bin'); |     let expPath = path.join(toolPath, 'bin'); | ||||||
|     expect(logSpy).toHaveBeenCalledWith('Setup go stable version spec 1.12.14'); |     expect(logSpy).toHaveBeenCalledWith('Setup go version spec 1.12.14'); | ||||||
|     expect(findSpy).toHaveBeenCalled(); |     expect(findSpy).toHaveBeenCalled(); | ||||||
|     expect(logSpy).toHaveBeenCalledWith('Attempting to download 1.12.14...'); |     expect(logSpy).toHaveBeenCalledWith('Attempting to download 1.12.14...'); | ||||||
|     expect(dlSpy).toHaveBeenCalled(); |     expect(dlSpy).toHaveBeenCalled(); | ||||||
| @ -560,11 +557,11 @@ describe('setup-go', () => { | |||||||
| 
 | 
 | ||||||
|   // 1.13.1 => 1.13.1
 |   // 1.13.1 => 1.13.1
 | ||||||
|   // 1.13 => 1.13.0
 |   // 1.13 => 1.13.0
 | ||||||
|   // 1.10beta1 => 1.10.0-beta1, 1.10rc1 => 1.10.0-rc1
 |   // 1.10beta1 => 1.10.0-beta.1, 1.10rc1 => 1.10.0-rc.1
 | ||||||
|   // 1.8.5beta1 => 1.8.5-beta1, 1.8.5rc1 => 1.8.5-rc1
 |   // 1.8.5beta1 => 1.8.5-beta.1, 1.8.5rc1 => 1.8.5-rc.1
 | ||||||
|   it('converts prerelease versions', async () => { |   it('converts prerelease versions', async () => { | ||||||
|     expect(im.makeSemver('1.10beta1')).toBe('1.10.0-beta1'); |     expect(im.makeSemver('1.10beta1')).toBe('1.10.0-beta.1'); | ||||||
|     expect(im.makeSemver('1.10rc1')).toBe('1.10.0-rc1'); |     expect(im.makeSemver('1.10rc1')).toBe('1.10.0-rc.1'); | ||||||
|   }); |   }); | ||||||
| 
 | 
 | ||||||
|   it('converts dot zero versions', async () => { |   it('converts dot zero versions', async () => { | ||||||
| @ -608,7 +605,7 @@ describe('setup-go', () => { | |||||||
| 
 | 
 | ||||||
|       await main.run(); |       await main.run(); | ||||||
| 
 | 
 | ||||||
|       expect(logSpy).toHaveBeenCalledWith('Setup go stable version spec 1.16'); |       expect(logSpy).toHaveBeenCalledWith('Setup go version spec 1.16'); | ||||||
|       expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`); |       expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`); | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
| @ -633,7 +630,7 @@ describe('setup-go', () => { | |||||||
|       await main.run(); |       await main.run(); | ||||||
| 
 | 
 | ||||||
|       expect(logSpy).toHaveBeenCalledWith( |       expect(logSpy).toHaveBeenCalledWith( | ||||||
|         `Setup go stable version spec ${versionSpec}` |         `Setup go version spec ${versionSpec}` | ||||||
|       ); |       ); | ||||||
|       expect(logSpy).toHaveBeenCalledWith( |       expect(logSpy).toHaveBeenCalledWith( | ||||||
|         'Attempting to resolve the latest version from the manifest...' |         'Attempting to resolve the latest version from the manifest...' | ||||||
|  | |||||||
| @ -7,9 +7,6 @@ inputs: | |||||||
|   check-latest: |   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' |     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 |     default: false | ||||||
|   stable: |  | ||||||
|     description: 'Whether to download only stable versions' |  | ||||||
|     default: 'true' |  | ||||||
|   token: |   token: | ||||||
|     description: Used to pull node distributions from go-versions.  Since there's a default, this is typically not supplied by the user. |     description: Used to pull node distributions from go-versions.  Since there's a default, this is typically not supplied by the user. | ||||||
|     default: ${{ github.token }} |     default: ${{ github.token }} | ||||||
|  | |||||||
							
								
								
									
										56
									
								
								dist/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										56
									
								
								dist/index.js
									
									
									
									
										vendored
									
									
								
							| @ -2074,15 +2074,12 @@ function run() { | |||||||
|             // If not supplied then problem matchers will still be setup.  Useful for self-hosted.
 |             // If not supplied then problem matchers will still be setup.  Useful for self-hosted.
 | ||||||
|             //
 |             //
 | ||||||
|             let versionSpec = core.getInput('go-version'); |             let versionSpec = core.getInput('go-version'); | ||||||
|             // stable will be true unless false is the exact input
 |             core.info(`Setup go version spec ${versionSpec}`); | ||||||
|             // since getting unstable versions should be explicit
 |  | ||||||
|             let stable = (core.getInput('stable') || 'true').toUpperCase() === 'TRUE'; |  | ||||||
|             core.info(`Setup go ${stable ? 'stable' : ''} version spec ${versionSpec}`); |  | ||||||
|             if (versionSpec) { |             if (versionSpec) { | ||||||
|                 let token = core.getInput('token'); |                 let token = core.getInput('token'); | ||||||
|                 let auth = !token || isGhes() ? undefined : `token ${token}`; |                 let auth = !token || isGhes() ? undefined : `token ${token}`; | ||||||
|                 const checkLatest = core.getBooleanInput('check-latest'); |                 const checkLatest = core.getBooleanInput('check-latest'); | ||||||
|                 const installDir = yield installer.getGo(versionSpec, stable, checkLatest, auth); |                 const installDir = yield installer.getGo(versionSpec, checkLatest, auth); | ||||||
|                 core.exportVariable('GOROOT', installDir); |                 core.exportVariable('GOROOT', installDir); | ||||||
|                 core.addPath(path_1.default.join(installDir, 'bin')); |                 core.addPath(path_1.default.join(installDir, 'bin')); | ||||||
|                 core.info('Added go to the path'); |                 core.info('Added go to the path'); | ||||||
| @ -5718,7 +5715,7 @@ module.exports = bytesToUuid; | |||||||
| 
 | 
 | ||||||
| Object.defineProperty(exports, "__esModule", { value: true }); | Object.defineProperty(exports, "__esModule", { value: true }); | ||||||
| exports.getArch = exports.getPlatform = void 0; | exports.getArch = exports.getPlatform = void 0; | ||||||
| let os = __webpack_require__(87); | const os = __webpack_require__(87); | ||||||
| function getPlatform() { | function getPlatform() { | ||||||
|     // darwin and linux match already
 |     // darwin and linux match already
 | ||||||
|     // freebsd not supported yet but future proofed.
 |     // freebsd not supported yet but future proofed.
 | ||||||
| @ -5890,13 +5887,13 @@ const semver = __importStar(__webpack_require__(280)); | |||||||
| const httpm = __importStar(__webpack_require__(539)); | const httpm = __importStar(__webpack_require__(539)); | ||||||
| const sys = __importStar(__webpack_require__(737)); | const sys = __importStar(__webpack_require__(737)); | ||||||
| const os_1 = __importDefault(__webpack_require__(87)); | const os_1 = __importDefault(__webpack_require__(87)); | ||||||
| function getGo(versionSpec, stable, checkLatest, auth) { | function getGo(versionSpec, checkLatest, auth) { | ||||||
|     return __awaiter(this, void 0, void 0, function* () { |     return __awaiter(this, void 0, void 0, function* () { | ||||||
|         let osPlat = os_1.default.platform(); |         let osPlat = os_1.default.platform(); | ||||||
|         let osArch = os_1.default.arch(); |         let osArch = os_1.default.arch(); | ||||||
|         if (checkLatest) { |         if (checkLatest) { | ||||||
|             core.info('Attempting to resolve the latest version from the manifest...'); |             core.info('Attempting to resolve the latest version from the manifest...'); | ||||||
|             const resolvedVersion = yield resolveVersionFromManifest(versionSpec, stable, auth); |             const resolvedVersion = yield resolveVersionFromManifest(versionSpec, true, auth); | ||||||
|             if (resolvedVersion) { |             if (resolvedVersion) { | ||||||
|                 versionSpec = resolvedVersion; |                 versionSpec = resolvedVersion; | ||||||
|                 core.info(`Resolved as '${versionSpec}'`); |                 core.info(`Resolved as '${versionSpec}'`); | ||||||
| @ -5920,7 +5917,7 @@ function getGo(versionSpec, stable, checkLatest, auth) { | |||||||
|         // Try download from internal distribution (popular versions only)
 |         // Try download from internal distribution (popular versions only)
 | ||||||
|         //
 |         //
 | ||||||
|         try { |         try { | ||||||
|             info = yield getInfoFromManifest(versionSpec, stable, auth); |             info = yield getInfoFromManifest(versionSpec, true, auth); | ||||||
|             if (info) { |             if (info) { | ||||||
|                 downloadPath = yield installGoVersion(info, auth); |                 downloadPath = yield installGoVersion(info, auth); | ||||||
|             } |             } | ||||||
| @ -5943,7 +5940,7 @@ function getGo(versionSpec, stable, checkLatest, auth) { | |||||||
|         // Download from storage.googleapis.com
 |         // Download from storage.googleapis.com
 | ||||||
|         //
 |         //
 | ||||||
|         if (!downloadPath) { |         if (!downloadPath) { | ||||||
|             info = yield getInfoFromDist(versionSpec, stable); |             info = yield getInfoFromDist(versionSpec); | ||||||
|             if (!info) { |             if (!info) { | ||||||
|                 throw new Error(`Unable to find Go version '${versionSpec}' for platform ${osPlat} and architecture ${osArch}.`); |                 throw new Error(`Unable to find Go version '${versionSpec}' for platform ${osPlat} and architecture ${osArch}.`); | ||||||
|             } |             } | ||||||
| @ -6018,10 +6015,10 @@ function getInfoFromManifest(versionSpec, stable, auth) { | |||||||
|     }); |     }); | ||||||
| } | } | ||||||
| exports.getInfoFromManifest = getInfoFromManifest; | exports.getInfoFromManifest = getInfoFromManifest; | ||||||
| function getInfoFromDist(versionSpec, stable) { | function getInfoFromDist(versionSpec) { | ||||||
|     return __awaiter(this, void 0, void 0, function* () { |     return __awaiter(this, void 0, void 0, function* () { | ||||||
|         let version; |         let version; | ||||||
|         version = yield findMatch(versionSpec, stable); |         version = yield findMatch(versionSpec); | ||||||
|         if (!version) { |         if (!version) { | ||||||
|             return null; |             return null; | ||||||
|         } |         } | ||||||
| @ -6034,7 +6031,7 @@ function getInfoFromDist(versionSpec, stable) { | |||||||
|         }; |         }; | ||||||
|     }); |     }); | ||||||
| } | } | ||||||
| function findMatch(versionSpec, stable) { | function findMatch(versionSpec) { | ||||||
|     return __awaiter(this, void 0, void 0, function* () { |     return __awaiter(this, void 0, void 0, function* () { | ||||||
|         let archFilter = sys.getArch(); |         let archFilter = sys.getArch(); | ||||||
|         let platFilter = sys.getPlatform(); |         let platFilter = sys.getPlatform(); | ||||||
| @ -6049,15 +6046,8 @@ function findMatch(versionSpec, stable) { | |||||||
|         for (let i = 0; i < candidates.length; i++) { |         for (let i = 0; i < candidates.length; i++) { | ||||||
|             let candidate = candidates[i]; |             let candidate = candidates[i]; | ||||||
|             let version = makeSemver(candidate.version); |             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.debug(`check ${version} satisfies ${versionSpec}`); |             core.debug(`check ${version} satisfies ${versionSpec}`); | ||||||
|             if (semver.satisfies(version, versionSpec) && |             if (semver.satisfies(version, versionSpec)) { | ||||||
|                 (!stable || candidate.stable === stable)) { |  | ||||||
|                 goFile = candidate.files.find(file => { |                 goFile = candidate.files.find(file => { | ||||||
|                     core.debug(`${file.arch}===${archFilter} && ${file.os}===${platFilter}`); |                     core.debug(`${file.arch}===${archFilter} && ${file.os}===${platFilter}`); | ||||||
|                     return file.arch === archFilter && file.os === platFilter; |                     return file.arch === archFilter && file.os === platFilter; | ||||||
| @ -6093,19 +6083,25 @@ exports.getVersionsDist = getVersionsDist; | |||||||
| // Convert the go version syntax into semver for semver matching
 | // Convert the go version syntax into semver for semver matching
 | ||||||
| // 1.13.1 => 1.13.1
 | // 1.13.1 => 1.13.1
 | ||||||
| // 1.13 => 1.13.0
 | // 1.13 => 1.13.0
 | ||||||
| // 1.10beta1 => 1.10.0-beta1, 1.10rc1 => 1.10.0-rc1
 | // 1.10beta1 => 1.10.0-beta.1, 1.10rc1 => 1.10.0-rc.1
 | ||||||
| // 1.8.5beta1 => 1.8.5-beta1, 1.8.5rc1 => 1.8.5-rc1
 | // 1.8.5beta1 => 1.8.5-beta.1, 1.8.5rc1 => 1.8.5-rc.1
 | ||||||
| function makeSemver(version) { | function makeSemver(version) { | ||||||
|  |     var _a; | ||||||
|     version = version.replace('go', ''); |     version = version.replace('go', ''); | ||||||
|     version = version.replace('beta', '-beta').replace('rc', '-rc'); |     version = version.replace('beta', '-beta.').replace('rc', '-rc.'); | ||||||
|     let parts = version.split('-'); |     let parts = version.split('-'); | ||||||
|     let verPart = parts[0]; |     let semVersion = (_a = semver.coerce(parts[0])) === null || _a === void 0 ? void 0 : _a.version; | ||||||
|     let prereleasePart = parts.length > 1 ? `-${parts[1]}` : ''; |     if (!semVersion) { | ||||||
|     let verParts = verPart.split('.'); |         throw new Error(`The version: ${version} can't be changed to SemVer notation`); | ||||||
|     if (verParts.length == 2) { |  | ||||||
|         verPart += '.0'; |  | ||||||
|     } |     } | ||||||
|     return `${verPart}${prereleasePart}`; |     if (!parts[1]) { | ||||||
|  |         return semVersion; | ||||||
|  |     } | ||||||
|  |     const fullVersion = semver.valid(`${semVersion}-${parts[1]}`); | ||||||
|  |     if (!fullVersion) { | ||||||
|  |         throw new Error(`The version: ${version} can't be changed to SemVer notation`); | ||||||
|  |     } | ||||||
|  |     return fullVersion; | ||||||
| } | } | ||||||
| exports.makeSemver = makeSemver; | exports.makeSemver = makeSemver; | ||||||
| //# sourceMappingURL=installer.js.map
 | //# sourceMappingURL=installer.js.map
 | ||||||
|  | |||||||
| @ -30,7 +30,6 @@ export interface IGoVersionInfo { | |||||||
| 
 | 
 | ||||||
| export async function getGo( | export async function getGo( | ||||||
|   versionSpec: string, |   versionSpec: string, | ||||||
|   stable: boolean, |  | ||||||
|   checkLatest: boolean, |   checkLatest: boolean, | ||||||
|   auth: string | undefined |   auth: string | undefined | ||||||
| ) { | ) { | ||||||
| @ -41,7 +40,7 @@ export async function getGo( | |||||||
|     core.info('Attempting to resolve the latest version from the manifest...'); |     core.info('Attempting to resolve the latest version from the manifest...'); | ||||||
|     const resolvedVersion = await resolveVersionFromManifest( |     const resolvedVersion = await resolveVersionFromManifest( | ||||||
|       versionSpec, |       versionSpec, | ||||||
|       stable, |       true, | ||||||
|       auth |       auth | ||||||
|     ); |     ); | ||||||
|     if (resolvedVersion) { |     if (resolvedVersion) { | ||||||
| @ -68,7 +67,7 @@ export async function getGo( | |||||||
|   // Try download from internal distribution (popular versions only)
 |   // Try download from internal distribution (popular versions only)
 | ||||||
|   //
 |   //
 | ||||||
|   try { |   try { | ||||||
|     info = await getInfoFromManifest(versionSpec, stable, auth); |     info = await getInfoFromManifest(versionSpec, true, auth); | ||||||
|     if (info) { |     if (info) { | ||||||
|       downloadPath = await installGoVersion(info, auth); |       downloadPath = await installGoVersion(info, auth); | ||||||
|     } else { |     } else { | ||||||
| @ -95,7 +94,7 @@ export async function getGo( | |||||||
|   // Download from storage.googleapis.com
 |   // Download from storage.googleapis.com
 | ||||||
|   //
 |   //
 | ||||||
|   if (!downloadPath) { |   if (!downloadPath) { | ||||||
|     info = await getInfoFromDist(versionSpec, stable); |     info = await getInfoFromDist(versionSpec); | ||||||
|     if (!info) { |     if (!info) { | ||||||
|       throw new Error( |       throw new Error( | ||||||
|         `Unable to find Go version '${versionSpec}' for platform ${osPlat} and architecture ${osArch}.` |         `Unable to find Go version '${versionSpec}' for platform ${osPlat} and architecture ${osArch}.` | ||||||
| @ -191,11 +190,10 @@ export async function getInfoFromManifest( | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| async function getInfoFromDist( | async function getInfoFromDist( | ||||||
|   versionSpec: string, |   versionSpec: string | ||||||
|   stable: boolean |  | ||||||
| ): Promise<IGoVersionInfo | null> { | ): Promise<IGoVersionInfo | null> { | ||||||
|   let version: IGoVersion | undefined; |   let version: IGoVersion | undefined; | ||||||
|   version = await findMatch(versionSpec, stable); |   version = await findMatch(versionSpec); | ||||||
|   if (!version) { |   if (!version) { | ||||||
|     return null; |     return null; | ||||||
|   } |   } | ||||||
| @ -211,8 +209,7 @@ async function getInfoFromDist( | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export async function findMatch( | export async function findMatch( | ||||||
|   versionSpec: string, |   versionSpec: string | ||||||
|   stable: boolean |  | ||||||
| ): Promise<IGoVersion | undefined> { | ): Promise<IGoVersion | undefined> { | ||||||
|   let archFilter = sys.getArch(); |   let archFilter = sys.getArch(); | ||||||
|   let platFilter = sys.getPlatform(); |   let platFilter = sys.getPlatform(); | ||||||
| @ -233,18 +230,8 @@ export async function findMatch( | |||||||
|     let candidate: IGoVersion = candidates[i]; |     let candidate: IGoVersion = candidates[i]; | ||||||
|     let version = makeSemver(candidate.version); |     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: string[] = version.split('.'); |  | ||||||
|     if (parts.length == 2) { |  | ||||||
|       version = version + '.0'; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     core.debug(`check ${version} satisfies ${versionSpec}`); |     core.debug(`check ${version} satisfies ${versionSpec}`); | ||||||
|     if ( |     if (semver.satisfies(version, versionSpec)) { | ||||||
|       semver.satisfies(version, versionSpec) && |  | ||||||
|       (!stable || candidate.stable === stable) |  | ||||||
|     ) { |  | ||||||
|       goFile = candidate.files.find(file => { |       goFile = candidate.files.find(file => { | ||||||
|         core.debug( |         core.debug( | ||||||
|           `${file.arch}===${archFilter} && ${file.os}===${platFilter}` |           `${file.arch}===${archFilter} && ${file.os}===${platFilter}` | ||||||
| @ -284,20 +271,30 @@ export async function getVersionsDist( | |||||||
| // Convert the go version syntax into semver for semver matching
 | // Convert the go version syntax into semver for semver matching
 | ||||||
| // 1.13.1 => 1.13.1
 | // 1.13.1 => 1.13.1
 | ||||||
| // 1.13 => 1.13.0
 | // 1.13 => 1.13.0
 | ||||||
| // 1.10beta1 => 1.10.0-beta1, 1.10rc1 => 1.10.0-rc1
 | // 1.10beta1 => 1.10.0-beta.1, 1.10rc1 => 1.10.0-rc.1
 | ||||||
| // 1.8.5beta1 => 1.8.5-beta1, 1.8.5rc1 => 1.8.5-rc1
 | // 1.8.5beta1 => 1.8.5-beta.1, 1.8.5rc1 => 1.8.5-rc.1
 | ||||||
| export function makeSemver(version: string): string { | export function makeSemver(version: string): string { | ||||||
|   version = version.replace('go', ''); |   version = version.replace('go', ''); | ||||||
|   version = version.replace('beta', '-beta').replace('rc', '-rc'); |   version = version.replace('beta', '-beta.').replace('rc', '-rc.'); | ||||||
|   let parts = version.split('-'); |   let parts = version.split('-'); | ||||||
| 
 | 
 | ||||||
|   let verPart: string = parts[0]; |   let semVersion = semver.coerce(parts[0])?.version; | ||||||
|   let prereleasePart = parts.length > 1 ? `-${parts[1]}` : ''; |   if (!semVersion) { | ||||||
| 
 |     throw new Error( | ||||||
|   let verParts: string[] = verPart.split('.'); |       `The version: ${version} can't be changed to SemVer notation` | ||||||
|   if (verParts.length == 2) { |     ); | ||||||
|     verPart += '.0'; |  | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   return `${verPart}${prereleasePart}`; |   if (!parts[1]) { | ||||||
|  |     return semVersion; | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   const fullVersion = semver.valid(`${semVersion}-${parts[1]}`); | ||||||
|  | 
 | ||||||
|  |   if (!fullVersion) { | ||||||
|  |     throw new Error( | ||||||
|  |       `The version: ${version} can't be changed to SemVer notation` | ||||||
|  |     ); | ||||||
|  |   } | ||||||
|  |   return fullVersion; | ||||||
| } | } | ||||||
|  | |||||||
							
								
								
									
										13
									
								
								src/main.ts
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								src/main.ts
									
									
									
									
									
								
							| @ -14,23 +14,14 @@ export async function run() { | |||||||
|     //
 |     //
 | ||||||
|     let versionSpec = core.getInput('go-version'); |     let versionSpec = core.getInput('go-version'); | ||||||
| 
 | 
 | ||||||
|     // stable will be true unless false is the exact input
 |     core.info(`Setup go version spec ${versionSpec}`); | ||||||
|     // since getting unstable versions should be explicit
 |  | ||||||
|     let stable = (core.getInput('stable') || 'true').toUpperCase() === 'TRUE'; |  | ||||||
| 
 |  | ||||||
|     core.info(`Setup go ${stable ? 'stable' : ''} version spec ${versionSpec}`); |  | ||||||
| 
 | 
 | ||||||
|     if (versionSpec) { |     if (versionSpec) { | ||||||
|       let token = core.getInput('token'); |       let token = core.getInput('token'); | ||||||
|       let auth = !token || isGhes() ? undefined : `token ${token}`; |       let auth = !token || isGhes() ? undefined : `token ${token}`; | ||||||
| 
 | 
 | ||||||
|       const checkLatest = core.getBooleanInput('check-latest'); |       const checkLatest = core.getBooleanInput('check-latest'); | ||||||
|       const installDir = await installer.getGo( |       const installDir = await installer.getGo(versionSpec, checkLatest, auth); | ||||||
|         versionSpec, |  | ||||||
|         stable, |  | ||||||
|         checkLatest, |  | ||||||
|         auth |  | ||||||
|       ); |  | ||||||
| 
 | 
 | ||||||
|       core.exportVariable('GOROOT', installDir); |       core.exportVariable('GOROOT', installDir); | ||||||
|       core.addPath(path.join(installDir, 'bin')); |       core.addPath(path.join(installDir, 'bin')); | ||||||
|  | |||||||
| @ -1,4 +1,4 @@ | |||||||
| let os = require('os'); | const os = require('os'); | ||||||
| 
 | 
 | ||||||
| export function getPlatform(): string { | export function getPlatform(): string { | ||||||
|   // darwin and linux match already
 |   // darwin and linux match already
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user