Stop fetching version information from github APIs

This commit is contained in:
Zsolt Dollenstein
2026-01-22 11:22:17 +00:00
parent 450788bda3
commit 71191068af
4 changed files with 19 additions and 4417 deletions

4314
dist/setup/index.js generated vendored

File diff suppressed because it is too large Load Diff

View File

@@ -32529,7 +32529,7 @@ async function getManifestEntries(manifestUrl) {
data = await response.text(); data = await response.text();
} }
else { else {
core.debug("Reading manifest from local bundled file."); core.info("manifest-file not provided, reading from local file.");
const fileContent = await node_fs_1.promises.readFile(localManifestFile); const fileContent = await node_fs_1.promises.readFile(localManifestFile);
data = fileContent.toString(); data = fileContent.toString();
} }

View File

@@ -2,11 +2,9 @@ import { promises as fs } from "node:fs";
import * as path from "node:path"; import * as path from "node:path";
import * as core from "@actions/core"; import * as core from "@actions/core";
import * as tc from "@actions/tool-cache"; import * as tc from "@actions/tool-cache";
import type { Endpoints } from "@octokit/types";
import * as pep440 from "@renovatebot/pep440"; import * as pep440 from "@renovatebot/pep440";
import * as semver from "semver"; import * as semver from "semver";
import { OWNER, REPO, TOOL_CACHE_NAME } from "../utils/constants"; import { OWNER, REPO, TOOL_CACHE_NAME } from "../utils/constants";
import { Octokit } from "../utils/octokit";
import type { Architecture, Platform } from "../utils/platforms"; import type { Architecture, Platform } from "../utils/platforms";
import { validateChecksum } from "./checksum/checksum"; import { validateChecksum } from "./checksum/checksum";
import { import {
@@ -16,9 +14,6 @@ import {
REMOTE_MANIFEST_URL, REMOTE_MANIFEST_URL,
} from "./version-manifest"; } from "./version-manifest";
type Release =
Endpoints["GET /repos/{owner}/{repo}/releases"]["response"]["data"][number];
export function tryGetFromToolCache( export function tryGetFromToolCache(
arch: Architecture, arch: Architecture,
version: string, version: string,
@@ -154,7 +149,6 @@ function getExtension(platform: Platform): string {
export async function resolveVersion( export async function resolveVersion(
versionInput: string, versionInput: string,
manifestFile: string | undefined, manifestFile: string | undefined,
githubToken: string,
resolutionStrategy: "highest" | "lowest" = "highest", resolutionStrategy: "highest" | "lowest" = "highest",
): Promise<string> { ): Promise<string> {
core.debug(`Resolving version: ${versionInput}`); core.debug(`Resolving version: ${versionInput}`);
@@ -174,7 +168,7 @@ export async function resolveVersion(
} else { } else {
version = version =
versionInput === "latest" || resolveVersionSpecifierToLatest versionInput === "latest" || resolveVersionSpecifierToLatest
? await getLatestVersion(githubToken) ? await getLatestVersion()
: versionInput; : versionInput;
} }
if (tc.isExplicitVersion(version)) { if (tc.isExplicitVersion(version)) {
@@ -186,7 +180,7 @@ export async function resolveVersion(
} }
return version; return version;
} }
const availableVersions = await getAvailableVersions(githubToken); const availableVersions = await getAvailableVersions();
core.debug(`Available versions: ${availableVersions}`); core.debug(`Available versions: ${availableVersions}`);
const resolvedVersion = const resolvedVersion =
resolutionStrategy === "lowest" resolutionStrategy === "lowest"
@@ -198,7 +192,7 @@ export async function resolveVersion(
return resolvedVersion; return resolvedVersion;
} }
async function getAvailableVersions(githubToken: string): Promise<string[]> { async function getAvailableVersions(): Promise<string[]> {
// 1. Try remote manifest first (no rate limits, always current) // 1. Try remote manifest first (no rate limits, always current)
try { try {
core.info("Getting available versions from remote manifest..."); core.info("Getting available versions from remote manifest...");
@@ -210,57 +204,12 @@ async function getAvailableVersions(githubToken: string): Promise<string[]> {
core.debug(`Remote manifest lookup failed: ${err}`); core.debug(`Remote manifest lookup failed: ${err}`);
} }
// 2. Try GitHub API (rate limited but up-to-date) // 2. Fall back to bundled manifest (no network, may be stale)
try {
return await getAvailableVersionsFromGitHubApi(githubToken);
} catch (err) {
core.debug(`GitHub API lookup failed: ${err}`);
}
// 3. Fall back to bundled manifest (no network, may be stale)
core.info("Getting available versions from bundled manifest..."); core.info("Getting available versions from bundled manifest...");
return await getAvailableVersionsFromManifest(undefined); return await getAvailableVersionsFromManifest(undefined);
} }
async function getAvailableVersionsFromGitHubApi( async function getLatestVersion() {
githubToken: string,
): Promise<string[]> {
core.info("Getting available versions from GitHub API...");
try {
const octokit = new Octokit({
auth: githubToken,
});
return await getReleaseTagNames(octokit);
} catch (err) {
if ((err as Error).message.includes("Bad credentials")) {
core.info(
"No (valid) GitHub token provided. Falling back to anonymous. Requests might be rate limited.",
);
const octokit = new Octokit();
return await getReleaseTagNames(octokit);
}
throw err;
}
}
async function getReleaseTagNames(octokit: Octokit): Promise<string[]> {
const response: Release[] = await octokit.paginate(
octokit.rest.repos.listReleases,
{
owner: OWNER,
repo: REPO,
},
);
const releaseTagNames = response.map((release) => release.tag_name);
if (releaseTagNames.length === 0) {
throw Error(
"Github API request failed while getting releases. Check the GitHub status page for outages. Try again later.",
);
}
return releaseTagNames;
}
async function getLatestVersion(githubToken: string) {
// 1. Try remote manifest first (no rate limits, always current) // 1. Try remote manifest first (no rate limits, always current)
try { try {
core.info("Getting latest version from remote manifest..."); core.info("Getting latest version from remote manifest...");
@@ -271,59 +220,11 @@ async function getLatestVersion(githubToken: string) {
core.debug(`Remote manifest lookup failed: ${err}`); core.debug(`Remote manifest lookup failed: ${err}`);
} }
// 2. Try GitHub API (rate limited but up-to-date) // 2. Fall back to bundled manifest (no network, may be stale)
try {
core.info("Getting latest version from GitHub API...");
return await getLatestVersionFromGitHubApi(githubToken);
} catch (err) {
core.debug(`GitHub API lookup failed: ${err}`);
}
// 3. Fall back to bundled manifest (no network, may be stale)
core.info("Getting latest version from bundled manifest..."); core.info("Getting latest version from bundled manifest...");
return await getLatestVersionInManifest(undefined); return await getLatestVersionInManifest(undefined);
} }
async function getLatestVersionFromGitHubApi(
githubToken: string,
): Promise<string> {
const octokit = new Octokit({
auth: githubToken,
});
let latestRelease: { tag_name: string } | undefined;
try {
latestRelease = await getLatestRelease(octokit);
} catch (err) {
if ((err as Error).message.includes("Bad credentials")) {
core.info(
"No (valid) GitHub token provided. Falling back to anonymous. Requests might be rate limited.",
);
const octokit = new Octokit();
latestRelease = await getLatestRelease(octokit);
} else {
core.error(
"Github API request failed while getting latest release. Check the GitHub status page for outages. Try again later.",
);
throw err;
}
}
if (!latestRelease) {
throw new Error("Could not determine latest release.");
}
core.debug(`Latest version: ${latestRelease.tag_name}`);
return latestRelease.tag_name;
}
async function getLatestRelease(octokit: Octokit) {
const { data: latestRelease } = await octokit.rest.repos.getLatestRelease({
owner: OWNER,
repo: REPO,
});
return latestRelease;
}
function maxSatisfying( function maxSatisfying(
versions: string[], versions: string[],
version: string, version: string,

View File

@@ -157,12 +157,7 @@ async function determineVersion(
manifestFile: string | undefined, manifestFile: string | undefined,
): Promise<string> { ): Promise<string> {
if (versionInput !== "") { if (versionInput !== "") {
return await resolveVersion( return await resolveVersion(versionInput, manifestFile, resolutionStrategy);
versionInput,
manifestFile,
githubToken,
resolutionStrategy,
);
} }
if (versionFileInput !== "") { if (versionFileInput !== "") {
const versionFromFile = getUvVersionFromFile(versionFileInput); const versionFromFile = getUvVersionFromFile(versionFileInput);
@@ -174,7 +169,6 @@ async function determineVersion(
return await resolveVersion( return await resolveVersion(
versionFromFile, versionFromFile,
manifestFile, manifestFile,
githubToken,
resolutionStrategy, resolutionStrategy,
); );
} }
@@ -192,7 +186,6 @@ async function determineVersion(
return await resolveVersion( return await resolveVersion(
versionFromUvToml || versionFromPyproject || "latest", versionFromUvToml || versionFromPyproject || "latest",
manifestFile, manifestFile,
githubToken,
resolutionStrategy, resolutionStrategy,
); );
} }