Skip to content

Commit 61817fa

Browse files
authored
Merge pull request #4181 from github/mbg/start-proxy/linux-arm64
Support `linux-arm64` assets in `start-proxy`
2 parents 85c0c09 + 8e838ff commit 61817fa

6 files changed

Lines changed: 139 additions & 58 deletions

File tree

‎lib/entry-points.js‎

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

‎src/action-common.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ export interface BaseState {
1919
name: ActionName;
2020
/** When the Action was started. */
2121
startedAt: Date;
22+
/** The platform the Action is running on. */
23+
platform: NodeJS.Platform;
24+
/** The architecture of the host. */
25+
arch: NodeJS.Architecture;
2226
}
2327

2428
/** Describes different state features that an Action may have. */
@@ -98,6 +102,8 @@ export async function runInActions(action: Action) {
98102
const actionState = {
99103
name: action.name,
100104
startedAt,
105+
platform: process.platform,
106+
arch: process.arch,
101107
logger,
102108
env,
103109
actions: actionsEnv,

‎src/start-proxy-action.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ async function run(action: ActionState<["Base", "Logger", "Env", "Actions"]>) {
9898
};
9999

100100
// Start the Proxy
101-
const proxyBin = await getProxyBinaryPath(logger, features);
101+
const proxyBin = await getProxyBinaryPath({ ...action, features });
102102
const proxyInfo = await startProxy(
103103
proxyBin,
104104
proxyConfig,

‎src/start-proxy.test.ts‎

Lines changed: 82 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,22 @@ import * as toolcache from "@actions/tool-cache";
55
import test, { ExecutionContext } from "ava";
66
import sinon from "sinon";
77

8+
import { ActionState } from "./action-common";
89
import * as apiClient from "./api-client";
910
import * as defaults from "./defaults.json";
1011
import { setUpFeatureFlagTests } from "./feature-flags/testing-util";
1112
import { UnvalidatedObject, validateSchema } from "./json";
1213
import { makeFromSchema } from "./json/testing-util";
1314
import { BuiltInLanguage } from "./languages";
1415
import { getRunnerLogger, Logger } from "./logging";
16+
import { BundlePlatform, getBundlePlatform } from "./platform";
1517
import * as startProxyExports from "./start-proxy";
1618
import * as statusReport from "./status-report";
1719
import {
1820
assertNotLogged,
1921
checkExpectedLogMessages,
2022
createFeatures,
23+
initAllState,
2124
makeMacro,
2225
makeTestToken,
2326
RecordingLogger,
@@ -685,6 +688,12 @@ test("getCredentials always returns ALWAYS_ENABLED_REGISTRY_TYPE credentials for
685688
}
686689
});
687690

691+
test("getProxyPackage - includes platform in name", (t) => {
692+
for (const platform of Object.values(BundlePlatform)) {
693+
t.true(startProxyExports.getProxyPackage(platform).includes(platform));
694+
}
695+
});
696+
688697
function mockGetApiClient(endpoints: any) {
689698
return (
690699
sinon
@@ -721,23 +730,61 @@ function mockOfflineFeatures(tempDir: string, logger: Logger) {
721730
return setUpFeatureFlagTests(tempDir, logger, gitHubVersion);
722731
}
723732

733+
/** Gets the `BundlePlatform` based on the `action` state, but defaults to `Linux64` if undefined. */
734+
function getTestPlatform(action: ActionState<["Base"]>) {
735+
return (
736+
getBundlePlatform(action.platform, action.arch) ?? BundlePlatform.Linux64
737+
);
738+
}
739+
724740
test.serial(
725-
"getDownloadUrl returns fallback when `getReleaseByVersion` rejects",
741+
"getDownloadUrl logs unknown platforms/arch and defaults to linux64",
726742
async (t) => {
727743
const logger = new RecordingLogger();
728744
mockGetReleaseByTag();
729745

730746
await withTmpDir(async (tempDir) => {
731747
const features = mockOfflineFeatures(tempDir, logger);
732-
const info = await startProxyExports.getDownloadUrl(
733-
getRunnerLogger(true),
748+
const state = initAllState({
749+
platform: "android",
750+
arch: "ppc",
751+
logger,
734752
features,
753+
});
754+
const info = await startProxyExports.getDownloadUrl(state);
755+
756+
t.is(info.version, startProxyExports.UPDATEJOB_PROXY_VERSION);
757+
t.is(
758+
info.url,
759+
startProxyExports.getFallbackUrl(
760+
startProxyExports.getProxyPackage(BundlePlatform.Linux64),
761+
),
762+
);
763+
764+
t.true(
765+
logger.hasMessage(`Unsupported platform android on architecture ppc`),
735766
);
767+
});
768+
},
769+
);
770+
771+
test.serial(
772+
"getDownloadUrl returns fallback when `getReleaseByVersion` rejects",
773+
async (t) => {
774+
const logger = new RecordingLogger();
775+
mockGetReleaseByTag();
776+
777+
await withTmpDir(async (tempDir) => {
778+
const features = mockOfflineFeatures(tempDir, logger);
779+
const state = initAllState({ logger, features });
780+
const info = await startProxyExports.getDownloadUrl(state);
736781

737782
t.is(info.version, startProxyExports.UPDATEJOB_PROXY_VERSION);
738783
t.is(
739784
info.url,
740-
startProxyExports.getFallbackUrl(startProxyExports.getProxyPackage()),
785+
startProxyExports.getFallbackUrl(
786+
startProxyExports.getProxyPackage(getTestPlatform(state)),
787+
),
741788
);
742789
});
743790
},
@@ -751,18 +798,18 @@ test.serial(
751798

752799
await withTmpDir(async (tempDir) => {
753800
const features = mockOfflineFeatures(tempDir, logger);
801+
const state = initAllState({ logger, features });
754802

755803
for (const assets of testAssets) {
756804
const stub = mockGetReleaseByTag(assets);
757-
const info = await startProxyExports.getDownloadUrl(
758-
getRunnerLogger(true),
759-
features,
760-
);
805+
const info = await startProxyExports.getDownloadUrl(state);
761806

762807
t.is(info.version, startProxyExports.UPDATEJOB_PROXY_VERSION);
763808
t.is(
764809
info.url,
765-
startProxyExports.getFallbackUrl(startProxyExports.getProxyPackage()),
810+
startProxyExports.getFallbackUrl(
811+
startProxyExports.getProxyPackage(getTestPlatform(state)),
812+
),
766813
);
767814

768815
stub.restore();
@@ -773,18 +820,19 @@ test.serial(
773820

774821
test.serial("getDownloadUrl returns matching release asset", async (t) => {
775822
const logger = new RecordingLogger();
823+
const state = initAllState({ logger });
776824
const assets = [
777825
{ name: "foo", url: "other-url" },
778-
{ name: startProxyExports.getProxyPackage(), url: "url-we-want" },
826+
{
827+
name: startProxyExports.getProxyPackage(getTestPlatform(state)),
828+
url: "url-we-want",
829+
},
779830
];
780831
mockGetReleaseByTag(assets);
781832

782833
await withTmpDir(async (tempDir) => {
783834
const features = mockOfflineFeatures(tempDir, logger);
784-
const info = await startProxyExports.getDownloadUrl(
785-
getRunnerLogger(true),
786-
features,
787-
);
835+
const info = await startProxyExports.getDownloadUrl({ ...state, features });
788836

789837
t.is(info.version, defaults.cliVersion);
790838
t.is(info.url, "url-we-want");
@@ -918,7 +966,9 @@ test.serial(
918966
sinon.stub(toolcache, "find").returns(toolcachePath);
919967

920968
const features = mockOfflineFeatures(tempDir, logger);
921-
const path = await startProxyExports.getProxyBinaryPath(logger, features);
969+
const path = await startProxyExports.getProxyBinaryPath(
970+
initAllState({ logger, features }),
971+
);
922972

923973
t.assert(path);
924974
t.is(
@@ -933,9 +983,13 @@ test.serial(
933983
"getProxyBinaryPath - downloads proxy if not in cache",
934984
async (t) => {
935985
const logger = new RecordingLogger();
986+
const state = initAllState({ logger });
936987
const downloadUrl = "url-we-want";
937988
mockGetReleaseByTag([
938-
{ name: startProxyExports.getProxyPackage(), url: downloadUrl },
989+
{
990+
name: startProxyExports.getProxyPackage(getTestPlatform(state)),
991+
url: downloadUrl,
992+
},
939993
]);
940994

941995
const toolcachePath = "/path/to/proxy/dir";
@@ -958,10 +1012,10 @@ test.serial(
9581012
.resolves(extractedPath);
9591013
const cacheDir = sinon.stub(toolcache, "cacheDir").resolves(toolcachePath);
9601014

961-
const path = await startProxyExports.getProxyBinaryPath(
962-
logger,
963-
createFeatures([]),
964-
);
1015+
const path = await startProxyExports.getProxyBinaryPath({
1016+
...state,
1017+
features: createFeatures([]),
1018+
});
9651019

9661020
t.assert(find.calledOnce);
9671021
t.assert(getApiDetails.calledOnce);
@@ -976,7 +1030,7 @@ test.serial(
9761030
);
9771031

9781032
checkExpectedLogMessages(t, logger.messages, [
979-
`Found '${startProxyExports.getProxyPackage()}' in release '${defaults.bundleVersion}' at '${downloadUrl}'`,
1033+
`Found '${startProxyExports.getProxyPackage(getTestPlatform(state))}' in release '${defaults.bundleVersion}' at '${downloadUrl}'`,
9801034
]);
9811035
},
9821036
);
@@ -985,6 +1039,7 @@ test.serial(
9851039
"getProxyBinaryPath - downloads proxy based on features if not in cache",
9861040
async (t) => {
9871041
const logger = new RecordingLogger();
1042+
const state = initAllState({ logger });
9881043
const expectedTag = "codeql-bundle-v2.20.1";
9891044
const expectedParams = {
9901045
owner: "github",
@@ -994,7 +1049,7 @@ test.serial(
9941049
const downloadUrl = "url-we-want";
9951050
const assets = [
9961051
{
997-
name: startProxyExports.getProxyPackage(),
1052+
name: startProxyExports.getProxyPackage(getTestPlatform(state)),
9981053
url: downloadUrl,
9991054
},
10001055
];
@@ -1045,7 +1100,10 @@ test.serial(
10451100
.resolves({
10461101
enabledVersions: [{ cliVersion: "2.20.1", tagName: expectedTag }],
10471102
});
1048-
const path = await startProxyExports.getProxyBinaryPath(logger, features);
1103+
const path = await startProxyExports.getProxyBinaryPath({
1104+
...state,
1105+
features,
1106+
});
10491107

10501108
t.assert(getDefaultCliVersion.calledOnce);
10511109
sinon.assert.calledOnceWithMatch(
@@ -1067,7 +1125,7 @@ test.serial(
10671125
});
10681126

10691127
checkExpectedLogMessages(t, logger.messages, [
1070-
`Found '${startProxyExports.getProxyPackage()}' in release '${expectedTag}' at '${downloadUrl}'`,
1128+
`Found '${startProxyExports.getProxyPackage(getTestPlatform(state))}' in release '${expectedTag}' at '${downloadUrl}'`,
10711129
]);
10721130
},
10731131
);

0 commit comments

Comments
 (0)