From bd015c26863164afb87622ad11f7c72fc80f8daa Mon Sep 17 00:00:00 2001 From: "Michael B. Gale" Date: Wed, 14 Oct 2026 12:07:12 +0100 Subject: [PATCH] Ensure consistent `apiDetails` in `getReleaseByVersion` and `getProxyBinaryPath` --- lib/entry-points.js | 14 +++++++++----- src/start-proxy.test.ts | 20 ++++++++++++++++---- src/start-proxy.ts | 23 +++++++++++++++++------ 3 files changed, 42 insertions(+), 15 deletions(-) diff --git a/lib/entry-points.js b/lib/entry-points.js index 3bef1190c..91079c3f9 100644 --- a/lib/entry-points.js +++ b/lib/entry-points.js @@ -187796,8 +187796,8 @@ function getProxyPackage(platform2) { function getFallbackUrl(proxyPackage) { return `${UPDATEJOB_PROXY_URL_PREFIX}${proxyPackage}`; } -async function getReleaseByVersion(version) { - return getApiClient().rest.repos.getReleaseByTag({ +async function getReleaseByVersion(env, apiDetails, version) { + return getApiClient(env, apiDetails).rest.repos.getReleaseByTag({ owner: "github", repo: "codeql-action", tag: version @@ -187807,7 +187807,7 @@ async function getCliVersionFromFeatures(features) { const gitHubVersion = await getGitHubVersion(); return await features.getEnabledDefaultCliVersions(gitHubVersion.type); } -async function getDownloadUrl(action) { +async function getDownloadUrl(action, apiDetails) { let platform2 = getBundlePlatform(action.platform, action.arch); if (platform2 === void 0) { action.logger.warning( @@ -187824,7 +187824,11 @@ async function getDownloadUrl(action) { cliVersion, tagName: bundleVersion }; - const cliRelease = await getReleaseByVersion(versionInfo.tagName); + const cliRelease = await getReleaseByVersion( + action.env, + apiDetails, + versionInfo.tagName + ); for (const asset of cliRelease.data.assets) { if (asset.name === proxyPackage) { action.logger.info( @@ -187898,7 +187902,7 @@ async function getProxyBinaryPath(action) { const apiDetails = getApiDetails(); const client = new InstanceApiClient(apiDetails); const proxyFileName = getProxyFilename(); - const proxyInfo = await getDownloadUrl(action); + const proxyInfo = await getDownloadUrl(action, apiDetails); let proxyBin = toolcache4.find(proxyFileName, proxyInfo.version); if (!proxyBin) { const authorization = client.getAuthorizationHeaderFor( diff --git a/src/start-proxy.test.ts b/src/start-proxy.test.ts index 96cbe83a0..07d4afe64 100644 --- a/src/start-proxy.test.ts +++ b/src/start-proxy.test.ts @@ -752,7 +752,10 @@ test.serial( logger, features, }); - const info = await startProxyExports.getDownloadUrl(state); + const info = await startProxyExports.getDownloadUrl( + state, + SAMPLE_DOTCOM_API_DETAILS, + ); t.is(info.version, startProxyExports.UPDATEJOB_PROXY_VERSION); t.is( @@ -778,7 +781,10 @@ test.serial( await withTmpDir(async (tempDir) => { const features = mockOfflineFeatures(tempDir, logger); const state = initAllState({ logger, features }); - const info = await startProxyExports.getDownloadUrl(state); + const info = await startProxyExports.getDownloadUrl( + state, + SAMPLE_DOTCOM_API_DETAILS, + ); t.is(info.version, startProxyExports.UPDATEJOB_PROXY_VERSION); t.is( @@ -803,7 +809,10 @@ test.serial( for (const assets of testAssets) { const stub = mockGetReleaseByTag(assets); - const info = await startProxyExports.getDownloadUrl(state); + const info = await startProxyExports.getDownloadUrl( + state, + SAMPLE_DOTCOM_API_DETAILS, + ); t.is(info.version, startProxyExports.UPDATEJOB_PROXY_VERSION); t.is( @@ -833,7 +842,10 @@ test.serial("getDownloadUrl returns matching release asset", async (t) => { await withTmpDir(async (tempDir) => { const features = mockOfflineFeatures(tempDir, logger); - const info = await startProxyExports.getDownloadUrl({ ...state, features }); + const info = await startProxyExports.getDownloadUrl( + { ...state, features }, + SAMPLE_DOTCOM_API_DETAILS, + ); t.is(info.version, defaults.cliVersion); t.is(info.url, "url-we-want"); diff --git a/src/start-proxy.ts b/src/start-proxy.ts index f4ea47fd9..41e55f8f0 100644 --- a/src/start-proxy.ts +++ b/src/start-proxy.ts @@ -9,10 +9,12 @@ import { getApiDetails, getGitHubVersion, InstanceApiClient, + type GitHubApiDetails, } from "./api-client"; import * as artifactScanner from "./artifact-scanner"; import { Config } from "./config-utils"; import * as defaults from "./defaults.json"; +import type { ReadOnlyEnv } from "./environment"; import { CodeQLDefaultVersionInfo, Feature, @@ -395,8 +397,12 @@ export function getFallbackUrl(proxyPackage: string): string { * * @returns The response from the GitHub API. */ -async function getReleaseByVersion(version: string) { - return getApiClient().rest.repos.getReleaseByTag({ +async function getReleaseByVersion( + env: ReadOnlyEnv, + apiDetails: GitHubApiDetails, + version: string, +) { + return getApiClient(env, apiDetails).rest.repos.getReleaseByTag({ owner: "github", repo: "codeql-action", tag: version, @@ -419,7 +425,8 @@ async function getCliVersionFromFeatures( * @returns Returns the download URL and version of the proxy package we plan to use. */ export async function getDownloadUrl( - action: ActionState<["Base", "Logger", "FeatureFlags"]>, + action: ActionState<["Base", "ReadOnlyEnv", "Logger", "FeatureFlags"]>, + apiDetails: GitHubApiDetails, ): Promise<{ url: string; version: string }> { // Default to linux64 if we don't recognise the platform+arch pair. // This maintains the behaviour we had before switching to `getBundlePlatform` here. @@ -448,7 +455,11 @@ export async function getDownloadUrl( }; // Try to retrieve information about the CLI bundle release identified by `versionInfo`. - const cliRelease = await getReleaseByVersion(versionInfo.tagName); + const cliRelease = await getReleaseByVersion( + action.env, + apiDetails, + versionInfo.tagName, + ); // Search the release's assets to find the one we are looking for. for (const asset of cliRelease.data.assets) { @@ -569,13 +580,13 @@ export function getProxyFilename() { * @returns The path to the proxy binary. */ export async function getProxyBinaryPath( - action: ActionState<["Base", "Logger", "FeatureFlags"]>, + action: ActionState<["Base", "ReadOnlyEnv", "Logger", "FeatureFlags"]>, ): Promise { const logger = action.logger; const apiDetails = getApiDetails(); const client = new InstanceApiClient(apiDetails); const proxyFileName = getProxyFilename(); - const proxyInfo = await getDownloadUrl(action); + const proxyInfo = await getDownloadUrl(action, apiDetails); let proxyBin = toolcache.find(proxyFileName, proxyInfo.version); if (!proxyBin) {