Use getBundlePlatform in getDownloadUrl

This commit is contained in:
Michael B. Gale
2026-09-28 16:55:43 +01:00
parent 97a91d9861
commit 62a2268b34
3 changed files with 47 additions and 18 deletions

View File

@@ -12,6 +12,7 @@ import { UnvalidatedObject, validateSchema } from "./json";
import { makeFromSchema } from "./json/testing-util";
import { BuiltInLanguage } from "./languages";
import { getRunnerLogger, Logger } from "./logging";
import { BundlePlatform, getBundlePlatform } from "./platform";
import * as startProxyExports from "./start-proxy";
import * as statusReport from "./status-report";
import {
@@ -721,6 +722,10 @@ function mockOfflineFeatures(tempDir: string, logger: Logger) {
return setUpFeatureFlagTests(tempDir, logger, gitHubVersion);
}
/** The result of `getBundlePlatform` or `Linux64` if `undefined`. */
const testPlatform: BundlePlatform =
getBundlePlatform() ?? BundlePlatform.Linux64;
test.serial(
"getDownloadUrl returns fallback when `getReleaseByVersion` rejects",
async (t) => {
@@ -737,7 +742,9 @@ test.serial(
t.is(info.version, startProxyExports.UPDATEJOB_PROXY_VERSION);
t.is(
info.url,
startProxyExports.getFallbackUrl(startProxyExports.getProxyPackage()),
startProxyExports.getFallbackUrl(
startProxyExports.getProxyPackage(testPlatform),
),
);
});
},
@@ -762,7 +769,9 @@ test.serial(
t.is(info.version, startProxyExports.UPDATEJOB_PROXY_VERSION);
t.is(
info.url,
startProxyExports.getFallbackUrl(startProxyExports.getProxyPackage()),
startProxyExports.getFallbackUrl(
startProxyExports.getProxyPackage(testPlatform),
),
);
stub.restore();
@@ -775,7 +784,10 @@ test.serial("getDownloadUrl returns matching release asset", async (t) => {
const logger = new RecordingLogger();
const assets = [
{ name: "foo", url: "other-url" },
{ name: startProxyExports.getProxyPackage(), url: "url-we-want" },
{
name: startProxyExports.getProxyPackage(testPlatform),
url: "url-we-want",
},
];
mockGetReleaseByTag(assets);
@@ -935,7 +947,10 @@ test.serial(
const logger = new RecordingLogger();
const downloadUrl = "url-we-want";
mockGetReleaseByTag([
{ name: startProxyExports.getProxyPackage(), url: downloadUrl },
{
name: startProxyExports.getProxyPackage(testPlatform),
url: downloadUrl,
},
]);
const toolcachePath = "/path/to/proxy/dir";
@@ -976,7 +991,7 @@ test.serial(
);
checkExpectedLogMessages(t, logger.messages, [
`Found '${startProxyExports.getProxyPackage()}' in release '${defaults.bundleVersion}' at '${downloadUrl}'`,
`Found '${startProxyExports.getProxyPackage(testPlatform)}' in release '${defaults.bundleVersion}' at '${downloadUrl}'`,
]);
},
);
@@ -994,7 +1009,7 @@ test.serial(
const downloadUrl = "url-we-want";
const assets = [
{
name: startProxyExports.getProxyPackage(),
name: startProxyExports.getProxyPackage(testPlatform),
url: downloadUrl,
},
];
@@ -1067,7 +1082,7 @@ test.serial(
});
checkExpectedLogMessages(t, logger.messages, [
`Found '${startProxyExports.getProxyPackage()}' in release '${expectedTag}' at '${downloadUrl}'`,
`Found '${startProxyExports.getProxyPackage(testPlatform)}' in release '${expectedTag}' at '${downloadUrl}'`,
]);
},
);

View File

@@ -3,6 +3,7 @@ import * as path from "path";
import * as core from "@actions/core";
import * as toolcache from "@actions/tool-cache";
import { ActionState } from "./action-common";
import {
getApiClient,
getApiDetails,
@@ -20,6 +21,7 @@ import {
import * as json from "./json";
import { BuiltInLanguage } from "./languages";
import { Logger } from "./logging";
import { BundlePlatform, getBundlePlatform } from "./platform";
import {
Address,
Registry,
@@ -370,14 +372,10 @@ export function getCredentials(
/**
* Gets the name of the proxy release asset for the current platform.
*
* @param platform The platform to get the asset name for.
*/
export function getProxyPackage(): string {
const platform =
process.platform === "win32"
? "win64"
: process.platform === "darwin"
? "osx64"
: "linux64";
export function getProxyPackage(platform: BundlePlatform): string {
return `${UPDATEJOB_PROXY}-${platform}.tar.gz`;
}
@@ -425,7 +423,17 @@ export async function getDownloadUrl(
logger: Logger,
features: FeatureEnablement,
): Promise<{ url: string; version: string }> {
const proxyPackage = getProxyPackage();
// Default to linux64 if we don't recognise the platform+arch pair.
// This maintains the behaviour we had before switching to `getBundlePlatform` here.
let platform = getBundlePlatform();
if (platform === undefined) {
logger.warning(
`Unsupported platform ${process.platform} on architecture ${process.arch}, defaulting to ${BundlePlatform.Linux64}`,
);
platform = BundlePlatform.Linux64;
}
const proxyPackage = getProxyPackage(platform);
try {
const useFeaturesToDetermineCLI = await features.getValue(