Ensure consistent apiDetails in getReleaseByVersion and getProxyBinaryPath

This commit is contained in:
Michael B. Gale
2026-10-14 12:07:12 +01:00
parent 8c32ebe976
commit bd015c2686
3 changed files with 42 additions and 15 deletions

14
lib/entry-points.js generated
View File

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

View File

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

View File

@@ -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<string> {
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) {