Skip to content

Commit bd015c2

Browse files
committed
Ensure consistent apiDetails in getReleaseByVersion and getProxyBinaryPath
1 parent 8c32ebe commit bd015c2

3 files changed

Lines changed: 42 additions & 15 deletions

File tree

‎lib/entry-points.js‎

Lines changed: 9 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/start-proxy.test.ts‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,10 @@ test.serial(
752752
logger,
753753
features,
754754
});
755-
const info = await startProxyExports.getDownloadUrl(state);
755+
const info = await startProxyExports.getDownloadUrl(
756+
state,
757+
SAMPLE_DOTCOM_API_DETAILS,
758+
);
756759

757760
t.is(info.version, startProxyExports.UPDATEJOB_PROXY_VERSION);
758761
t.is(
@@ -778,7 +781,10 @@ test.serial(
778781
await withTmpDir(async (tempDir) => {
779782
const features = mockOfflineFeatures(tempDir, logger);
780783
const state = initAllState({ logger, features });
781-
const info = await startProxyExports.getDownloadUrl(state);
784+
const info = await startProxyExports.getDownloadUrl(
785+
state,
786+
SAMPLE_DOTCOM_API_DETAILS,
787+
);
782788

783789
t.is(info.version, startProxyExports.UPDATEJOB_PROXY_VERSION);
784790
t.is(
@@ -803,7 +809,10 @@ test.serial(
803809

804810
for (const assets of testAssets) {
805811
const stub = mockGetReleaseByTag(assets);
806-
const info = await startProxyExports.getDownloadUrl(state);
812+
const info = await startProxyExports.getDownloadUrl(
813+
state,
814+
SAMPLE_DOTCOM_API_DETAILS,
815+
);
807816

808817
t.is(info.version, startProxyExports.UPDATEJOB_PROXY_VERSION);
809818
t.is(
@@ -833,7 +842,10 @@ test.serial("getDownloadUrl returns matching release asset", async (t) => {
833842

834843
await withTmpDir(async (tempDir) => {
835844
const features = mockOfflineFeatures(tempDir, logger);
836-
const info = await startProxyExports.getDownloadUrl({ ...state, features });
845+
const info = await startProxyExports.getDownloadUrl(
846+
{ ...state, features },
847+
SAMPLE_DOTCOM_API_DETAILS,
848+
);
837849

838850
t.is(info.version, defaults.cliVersion);
839851
t.is(info.url, "url-we-want");

‎src/start-proxy.ts‎

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ import {
99
getApiDetails,
1010
getGitHubVersion,
1111
InstanceApiClient,
12+
type GitHubApiDetails,
1213
} from "./api-client";
1314
import * as artifactScanner from "./artifact-scanner";
1415
import { Config } from "./config-utils";
1516
import * as defaults from "./defaults.json";
17+
import type { ReadOnlyEnv } from "./environment";
1618
import {
1719
CodeQLDefaultVersionInfo,
1820
Feature,
@@ -395,8 +397,12 @@ export function getFallbackUrl(proxyPackage: string): string {
395397
*
396398
* @returns The response from the GitHub API.
397399
*/
398-
async function getReleaseByVersion(version: string) {
399-
return getApiClient().rest.repos.getReleaseByTag({
400+
async function getReleaseByVersion(
401+
env: ReadOnlyEnv,
402+
apiDetails: GitHubApiDetails,
403+
version: string,
404+
) {
405+
return getApiClient(env, apiDetails).rest.repos.getReleaseByTag({
400406
owner: "github",
401407
repo: "codeql-action",
402408
tag: version,
@@ -419,7 +425,8 @@ async function getCliVersionFromFeatures(
419425
* @returns Returns the download URL and version of the proxy package we plan to use.
420426
*/
421427
export async function getDownloadUrl(
422-
action: ActionState<["Base", "Logger", "FeatureFlags"]>,
428+
action: ActionState<["Base", "ReadOnlyEnv", "Logger", "FeatureFlags"]>,
429+
apiDetails: GitHubApiDetails,
423430
): Promise<{ url: string; version: string }> {
424431
// Default to linux64 if we don't recognise the platform+arch pair.
425432
// This maintains the behaviour we had before switching to `getBundlePlatform` here.
@@ -448,7 +455,11 @@ export async function getDownloadUrl(
448455
};
449456

450457
// Try to retrieve information about the CLI bundle release identified by `versionInfo`.
451-
const cliRelease = await getReleaseByVersion(versionInfo.tagName);
458+
const cliRelease = await getReleaseByVersion(
459+
action.env,
460+
apiDetails,
461+
versionInfo.tagName,
462+
);
452463

453464
// Search the release's assets to find the one we are looking for.
454465
for (const asset of cliRelease.data.assets) {
@@ -569,13 +580,13 @@ export function getProxyFilename() {
569580
* @returns The path to the proxy binary.
570581
*/
571582
export async function getProxyBinaryPath(
572-
action: ActionState<["Base", "Logger", "FeatureFlags"]>,
583+
action: ActionState<["Base", "ReadOnlyEnv", "Logger", "FeatureFlags"]>,
573584
): Promise<string> {
574585
const logger = action.logger;
575586
const apiDetails = getApiDetails();
576587
const client = new InstanceApiClient(apiDetails);
577588
const proxyFileName = getProxyFilename();
578-
const proxyInfo = await getDownloadUrl(action);
589+
const proxyInfo = await getDownloadUrl(action, apiDetails);
579590

580591
let proxyBin = toolcache.find(proxyFileName, proxyInfo.version);
581592
if (!proxyBin) {

0 commit comments

Comments
 (0)