mirror of https://github.com/actions/setup-go.git
polish code
This commit is contained in:
parent
5a5cdc8151
commit
7e3178723a
|
@ -63236,17 +63236,7 @@ function getGo(versionSpec, checkLatest, auth, arch = os_1.default.arch()) {
|
||||||
manifest = yield getManifest(auth);
|
manifest = yield getManifest(auth);
|
||||||
let stableVersion = yield resolveStableVersionInput(versionSpec, arch, osPlat, manifest);
|
let stableVersion = yield resolveStableVersionInput(versionSpec, arch, osPlat, manifest);
|
||||||
if (!stableVersion) {
|
if (!stableVersion) {
|
||||||
let archFilter = sys.getArch(arch);
|
stableVersion = yield resolveStableVersionDist(versionSpec, arch);
|
||||||
let platFilter = sys.getPlatform();
|
|
||||||
const dlUrl = 'https://golang.org/dl/?mode=json&include=all';
|
|
||||||
let candidates = yield module.exports.getVersionsDist(dlUrl);
|
|
||||||
if (!candidates) {
|
|
||||||
throw new Error(`golang download url did not return results`);
|
|
||||||
}
|
|
||||||
const fixedCandidates = candidates.map(item => {
|
|
||||||
return Object.assign(Object.assign({}, item), { version: makeSemver(item.version) });
|
|
||||||
});
|
|
||||||
stableVersion = yield resolveStableVersionInput(versionSpec, archFilter, platFilter, fixedCandidates);
|
|
||||||
if (!stableVersion) {
|
if (!stableVersion) {
|
||||||
throw new Error(`Unable to find Go version '${versionSpec}' for platform ${osPlat} and architecture ${arch}.`);
|
throw new Error(`Unable to find Go version '${versionSpec}' for platform ${osPlat} and architecture ${arch}.`);
|
||||||
}
|
}
|
||||||
|
@ -63489,6 +63479,22 @@ function parseGoVersionFile(versionFilePath) {
|
||||||
return contents.trim();
|
return contents.trim();
|
||||||
}
|
}
|
||||||
exports.parseGoVersionFile = parseGoVersionFile;
|
exports.parseGoVersionFile = parseGoVersionFile;
|
||||||
|
function resolveStableVersionDist(versionSpec, arch) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
let archFilter = sys.getArch(arch);
|
||||||
|
let platFilter = sys.getPlatform();
|
||||||
|
const dlUrl = 'https://golang.org/dl/?mode=json&include=all';
|
||||||
|
let candidates = yield module.exports.getVersionsDist(dlUrl);
|
||||||
|
if (!candidates) {
|
||||||
|
throw new Error(`golang download url did not return results`);
|
||||||
|
}
|
||||||
|
const fixedCandidates = candidates.map(item => {
|
||||||
|
return Object.assign(Object.assign({}, item), { version: makeSemver(item.version) });
|
||||||
|
});
|
||||||
|
const stableVersion = yield resolveStableVersionInput(versionSpec, archFilter, platFilter, fixedCandidates);
|
||||||
|
return stableVersion;
|
||||||
|
});
|
||||||
|
}
|
||||||
function resolveStableVersionInput(versionSpec, arch, platform, manifest) {
|
function resolveStableVersionInput(versionSpec, arch, platform, manifest) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const releases = manifest
|
const releases = manifest
|
||||||
|
|
|
@ -52,30 +52,7 @@ export async function getGo(
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!stableVersion) {
|
if (!stableVersion) {
|
||||||
let archFilter = sys.getArch(arch);
|
stableVersion = await resolveStableVersionDist(versionSpec, arch);
|
||||||
let platFilter = sys.getPlatform();
|
|
||||||
const dlUrl: string = 'https://golang.org/dl/?mode=json&include=all';
|
|
||||||
let candidates:
|
|
||||||
| IGoVersion[]
|
|
||||||
| null = await module.exports.getVersionsDist(dlUrl);
|
|
||||||
if (!candidates) {
|
|
||||||
throw new Error(`golang download url did not return results`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const fixedCandidates = candidates.map(item => {
|
|
||||||
return {
|
|
||||||
...item,
|
|
||||||
version: makeSemver(item.version)
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
stableVersion = await resolveStableVersionInput(
|
|
||||||
versionSpec,
|
|
||||||
archFilter,
|
|
||||||
platFilter,
|
|
||||||
fixedCandidates
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!stableVersion) {
|
if (!stableVersion) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Unable to find Go version '${versionSpec}' for platform ${osPlat} and architecture ${arch}.`
|
`Unable to find Go version '${versionSpec}' for platform ${osPlat} and architecture ${arch}.`
|
||||||
|
@ -389,6 +366,34 @@ export function parseGoVersionFile(versionFilePath: string): string {
|
||||||
return contents.trim();
|
return contents.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function resolveStableVersionDist(versionSpec: string, arch: string) {
|
||||||
|
let archFilter = sys.getArch(arch);
|
||||||
|
let platFilter = sys.getPlatform();
|
||||||
|
const dlUrl: string = 'https://golang.org/dl/?mode=json&include=all';
|
||||||
|
let candidates: IGoVersion[] | null = await module.exports.getVersionsDist(
|
||||||
|
dlUrl
|
||||||
|
);
|
||||||
|
if (!candidates) {
|
||||||
|
throw new Error(`golang download url did not return results`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const fixedCandidates = candidates.map(item => {
|
||||||
|
return {
|
||||||
|
...item,
|
||||||
|
version: makeSemver(item.version)
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
const stableVersion = await resolveStableVersionInput(
|
||||||
|
versionSpec,
|
||||||
|
archFilter,
|
||||||
|
platFilter,
|
||||||
|
fixedCandidates
|
||||||
|
);
|
||||||
|
|
||||||
|
return stableVersion;
|
||||||
|
}
|
||||||
|
|
||||||
export async function resolveStableVersionInput(
|
export async function resolveStableVersionInput(
|
||||||
versionSpec: string,
|
versionSpec: string,
|
||||||
arch: string,
|
arch: string,
|
||||||
|
|
Loading…
Reference in New Issue