diff --git a/lib/entry-points.js b/lib/entry-points.js index 5a8e49bc9..73417126b 100644 --- a/lib/entry-points.js +++ b/lib/entry-points.js @@ -163637,8 +163637,7 @@ function getCredentials(logger, registrySecrets, registriesCredentials, language } return out; } -function getProxyPackage() { - const platform2 = process.platform === "win32" ? "win64" : process.platform === "darwin" ? "osx64" : "linux64"; +function getProxyPackage(platform2) { return `${UPDATEJOB_PROXY}-${platform2}.tar.gz`; } function getFallbackUrl(proxyPackage) { @@ -163656,7 +163655,14 @@ async function getCliVersionFromFeatures(features) { return await features.getEnabledDefaultCliVersions(gitHubVersion.type); } async function getDownloadUrl(logger, features) { - const proxyPackage = getProxyPackage(); + let platform2 = getBundlePlatform(); + if (platform2 === void 0) { + logger.warning( + `Unsupported platform ${process.platform} on architecture ${process.arch}, defaulting to ${"linux64" /* Linux64 */}` + ); + platform2 = "linux64" /* Linux64 */; + } + const proxyPackage = getProxyPackage(platform2); try { const useFeaturesToDetermineCLI = await features.getValue( "start_proxy_use_features_release" /* StartProxyUseFeaturesRelease */ diff --git a/src/start-proxy.test.ts b/src/start-proxy.test.ts index ee953798b..6e22aa85b 100644 --- a/src/start-proxy.test.ts +++ b/src/start-proxy.test.ts @@ -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}'`, ]); }, ); diff --git a/src/start-proxy.ts b/src/start-proxy.ts index caa1b3054..b01f35222 100644 --- a/src/start-proxy.ts +++ b/src/start-proxy.ts @@ -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(