mirror of
				https://github.com/actions/setup-go.git
				synced 2025-10-30 23:06:22 +00:00 
			
		
		
		
	Implement "check-latest" flag to check if pre-cached version is latest one (#186)
This commit is contained in:
		| @@ -31,11 +31,27 @@ export interface IGoVersionInfo { | ||||
| export async function getGo( | ||||
|   versionSpec: string, | ||||
|   stable: boolean, | ||||
|   checkLatest: boolean, | ||||
|   auth: string | undefined | ||||
| ) { | ||||
|   let osPlat: string = os.platform(); | ||||
|   let osArch: string = os.arch(); | ||||
|  | ||||
|   if (checkLatest) { | ||||
|     core.info('Attempting to resolve the latest version from the manifest...'); | ||||
|     const resolvedVersion = await resolveVersionFromManifest( | ||||
|       versionSpec, | ||||
|       stable, | ||||
|       auth | ||||
|     ); | ||||
|     if (resolvedVersion) { | ||||
|       versionSpec = resolvedVersion; | ||||
|       core.info(`Resolved as '${versionSpec}'`); | ||||
|     } else { | ||||
|       core.info(`Failed to resolve version ${versionSpec} from manifest`); | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   // check cache | ||||
|   let toolPath: string; | ||||
|   toolPath = tc.find('go', versionSpec); | ||||
| @@ -97,6 +113,20 @@ export async function getGo( | ||||
|   return downloadPath; | ||||
| } | ||||
|  | ||||
| async function resolveVersionFromManifest( | ||||
|   versionSpec: string, | ||||
|   stable: boolean, | ||||
|   auth: string | undefined | ||||
| ): Promise<string | undefined> { | ||||
|   try { | ||||
|     const info = await getInfoFromManifest(versionSpec, stable, auth); | ||||
|     return info?.resolvedVersion; | ||||
|   } catch (err) { | ||||
|     core.info('Unable to resolve a version from the manifest...'); | ||||
|     core.debug(err.message); | ||||
|   } | ||||
| } | ||||
|  | ||||
| async function installGoVersion( | ||||
|   info: IGoVersionInfo, | ||||
|   auth: string | undefined | ||||
|   | ||||
| @@ -24,7 +24,13 @@ export async function run() { | ||||
|       let token = core.getInput('token'); | ||||
|       let auth = !token || isGhes() ? undefined : `token ${token}`; | ||||
|  | ||||
|       const installDir = await installer.getGo(versionSpec, stable, auth); | ||||
|       const checkLatest = core.getBooleanInput('check-latest'); | ||||
|       const installDir = await installer.getGo( | ||||
|         versionSpec, | ||||
|         stable, | ||||
|         checkLatest, | ||||
|         auth | ||||
|       ); | ||||
|  | ||||
|       core.exportVariable('GOROOT', installDir); | ||||
|       core.addPath(path.join(installDir, 'bin')); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user