Implement "check-latest" flag to check if pre-cached version is latest one (#186)

This commit is contained in:
Dmitry Shibanov
2022-02-09 14:59:04 +03:00
committed by GitHub
parent 44e221478f
commit bfdd3570ce
17 changed files with 4811 additions and 3599 deletions

View File

@ -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

View File

@ -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'));