Skip to content

Commit

Permalink
Merge pull request Azure#900 from rondonjon/fix/899
Browse files Browse the repository at this point in the history
Fix 'Error fetching Function Core Tools releases: Cannot find downloa…
  • Loading branch information
Timothyw0 authored Jan 7, 2025
2 parents c24e67d + 7f0990c commit 08ac5a1
Showing 1 changed file with 29 additions and 25 deletions.
54 changes: 29 additions & 25 deletions src/core/func-core-tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,31 +121,35 @@ function getPlatform() {

export async function getLatestCoreToolsRelease(targetVersion: number): Promise<CoreToolsRelease> {
try {
const response = await fetch(RELEASES_FEED_URL);
const feed = (await response.json()) as { releases: any; tags: any };
const tag = feed.tags[`v${targetVersion}`];
if (!tag || tag.hidden) {
throw new Error(`Cannot find the latest version for v${targetVersion}`);
}

const release = feed.releases[tag.release];
if (!release) {
throw new Error(`Cannot find release for ${tag.release}`);
}

const coreTools = release.coreTools.filter((t: CoreToolsZipInfo) => t.size === "full");
const platform = getPlatform();
const info = coreTools.find((t: CoreToolsZipInfo) => t.OS === platform);
if (!info) {
throw new Error(`Cannot find download package for ${platform}`);
}

return {
version: tag.release,
url: info.downloadLink,
sha2: info.sha2,
};
} catch (error: unknown) {
const response = await fetch(RELEASES_FEED_URL);
const feed = (await response.json()) as { releases: Record<string, Record<string, CoreToolsZipInfo[]>>; };
const platform = getPlatform();

const matchingVersions = Object.keys(feed.releases)
.reverse() // JSON has newest versions first; we want the latest first; potential improvement: sort by semver
.filter(
(version) =>
version.match(/^\d+\.\d+\.\d+$/) && // only stable versions
version.startsWith(`${targetVersion}.`), // only matching major versions
);

for (const version of matchingVersions) {
const matchingDistribution = feed.releases[version].coreTools?.find(
(dist) =>
dist.OS === platform && // Distribution for matching platform
dist.size === "full", // exclude minified releases
);
if (matchingDistribution) {
return {
version,
url: matchingDistribution.downloadLink,
sha2: matchingDistribution.sha2,
};
}
}

throw new Error(`Cannot find download package for ${platform}`);
} catch (error: unknown) {
throw new Error(`Error fetching Function Core Tools releases: ${(error as Error).message}`);
}
}
Expand Down

0 comments on commit 08ac5a1

Please sign in to comment.