Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions lib/entry-points.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/action-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ export interface BaseState {
name: ActionName;
/** When the Action was started. */
startedAt: Date;
/** The platform the Action is running on. */
platform: NodeJS.Platform;
/** The architecture of the host. */
arch: NodeJS.Architecture;
}

/** Describes different state features that an Action may have. */
Expand Down Expand Up @@ -98,6 +102,8 @@ export async function runInActions(action: Action) {
const actionState = {
name: action.name,
startedAt,
platform: process.platform,
arch: process.arch,
logger,
env,
actions: actionsEnv,
Expand Down
2 changes: 1 addition & 1 deletion src/start-proxy-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ async function run(action: ActionState<["Base", "Logger", "Env", "Actions"]>) {
};

// Start the Proxy
const proxyBin = await getProxyBinaryPath(logger, features);
const proxyBin = await getProxyBinaryPath({ ...action, features });
const proxyInfo = await startProxy(
proxyBin,
proxyConfig,
Expand Down
106 changes: 82 additions & 24 deletions src/start-proxy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,22 @@ import * as toolcache from "@actions/tool-cache";
import test, { ExecutionContext } from "ava";
import sinon from "sinon";

import { ActionState } from "./action-common";
import * as apiClient from "./api-client";
import * as defaults from "./defaults.json";
import { setUpFeatureFlagTests } from "./feature-flags/testing-util";
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 {
assertNotLogged,
checkExpectedLogMessages,
createFeatures,
initAllState,
makeMacro,
makeTestToken,
RecordingLogger,
Expand Down Expand Up @@ -685,6 +688,12 @@ test("getCredentials always returns ALWAYS_ENABLED_REGISTRY_TYPE credentials for
}
});

test("getProxyPackage - includes platform in name", (t) => {
for (const platform of Object.values(BundlePlatform)) {
t.true(startProxyExports.getProxyPackage(platform).includes(platform));
}
});

function mockGetApiClient(endpoints: any) {
return (
sinon
Expand Down Expand Up @@ -721,23 +730,61 @@ function mockOfflineFeatures(tempDir: string, logger: Logger) {
return setUpFeatureFlagTests(tempDir, logger, gitHubVersion);
}

/** Gets the `BundlePlatform` based on the `action` state, but defaults to `Linux64` if undefined. */
function getTestPlatform(action: ActionState<["Base"]>) {
return (
getBundlePlatform(action.platform, action.arch) ?? BundlePlatform.Linux64
);
}

test.serial(
"getDownloadUrl returns fallback when `getReleaseByVersion` rejects",
"getDownloadUrl logs unknown platforms/arch and defaults to linux64",
async (t) => {
const logger = new RecordingLogger();
mockGetReleaseByTag();

await withTmpDir(async (tempDir) => {
const features = mockOfflineFeatures(tempDir, logger);
const info = await startProxyExports.getDownloadUrl(
getRunnerLogger(true),
const state = initAllState({
platform: "android",
arch: "ppc",
logger,
features,
});
const info = await startProxyExports.getDownloadUrl(state);

t.is(info.version, startProxyExports.UPDATEJOB_PROXY_VERSION);
t.is(
info.url,
startProxyExports.getFallbackUrl(
startProxyExports.getProxyPackage(BundlePlatform.Linux64),
),
);

t.true(
logger.hasMessage(`Unsupported platform android on architecture ppc`),
);
});
},
);

test.serial(
"getDownloadUrl returns fallback when `getReleaseByVersion` rejects",
async (t) => {
const logger = new RecordingLogger();
mockGetReleaseByTag();

await withTmpDir(async (tempDir) => {
const features = mockOfflineFeatures(tempDir, logger);
const state = initAllState({ logger, features });
const info = await startProxyExports.getDownloadUrl(state);

t.is(info.version, startProxyExports.UPDATEJOB_PROXY_VERSION);
t.is(
info.url,
startProxyExports.getFallbackUrl(startProxyExports.getProxyPackage()),
startProxyExports.getFallbackUrl(
startProxyExports.getProxyPackage(getTestPlatform(state)),
),
);
});
},
Expand All @@ -751,18 +798,18 @@ test.serial(

await withTmpDir(async (tempDir) => {
const features = mockOfflineFeatures(tempDir, logger);
const state = initAllState({ logger, features });

for (const assets of testAssets) {
const stub = mockGetReleaseByTag(assets);
const info = await startProxyExports.getDownloadUrl(
getRunnerLogger(true),
features,
);
const info = await startProxyExports.getDownloadUrl(state);

t.is(info.version, startProxyExports.UPDATEJOB_PROXY_VERSION);
t.is(
info.url,
startProxyExports.getFallbackUrl(startProxyExports.getProxyPackage()),
startProxyExports.getFallbackUrl(
startProxyExports.getProxyPackage(getTestPlatform(state)),
),
);

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

test.serial("getDownloadUrl returns matching release asset", async (t) => {
const logger = new RecordingLogger();
const state = initAllState({ logger });
const assets = [
{ name: "foo", url: "other-url" },
{ name: startProxyExports.getProxyPackage(), url: "url-we-want" },
{
name: startProxyExports.getProxyPackage(getTestPlatform(state)),
url: "url-we-want",
},
];
mockGetReleaseByTag(assets);

await withTmpDir(async (tempDir) => {
const features = mockOfflineFeatures(tempDir, logger);
const info = await startProxyExports.getDownloadUrl(
getRunnerLogger(true),
features,
);
const info = await startProxyExports.getDownloadUrl({ ...state, features });

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

const features = mockOfflineFeatures(tempDir, logger);
const path = await startProxyExports.getProxyBinaryPath(logger, features);
const path = await startProxyExports.getProxyBinaryPath(
initAllState({ logger, features }),
);

t.assert(path);
t.is(
Expand All @@ -933,9 +983,13 @@ test.serial(
"getProxyBinaryPath - downloads proxy if not in cache",
async (t) => {
const logger = new RecordingLogger();
const state = initAllState({ logger });
const downloadUrl = "url-we-want";
mockGetReleaseByTag([
{ name: startProxyExports.getProxyPackage(), url: downloadUrl },
{
name: startProxyExports.getProxyPackage(getTestPlatform(state)),
url: downloadUrl,
},
]);

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

const path = await startProxyExports.getProxyBinaryPath(
logger,
createFeatures([]),
);
const path = await startProxyExports.getProxyBinaryPath({
...state,
features: createFeatures([]),
});

t.assert(find.calledOnce);
t.assert(getApiDetails.calledOnce);
Expand All @@ -976,7 +1030,7 @@ test.serial(
);

checkExpectedLogMessages(t, logger.messages, [
`Found '${startProxyExports.getProxyPackage()}' in release '${defaults.bundleVersion}' at '${downloadUrl}'`,
`Found '${startProxyExports.getProxyPackage(getTestPlatform(state))}' in release '${defaults.bundleVersion}' at '${downloadUrl}'`,
]);
},
);
Expand All @@ -985,6 +1039,7 @@ test.serial(
"getProxyBinaryPath - downloads proxy based on features if not in cache",
async (t) => {
const logger = new RecordingLogger();
const state = initAllState({ logger });
const expectedTag = "codeql-bundle-v2.20.1";
const expectedParams = {
owner: "github",
Expand All @@ -994,7 +1049,7 @@ test.serial(
const downloadUrl = "url-we-want";
const assets = [
{
name: startProxyExports.getProxyPackage(),
name: startProxyExports.getProxyPackage(getTestPlatform(state)),
url: downloadUrl,
},
];
Expand Down Expand Up @@ -1045,7 +1100,10 @@ test.serial(
.resolves({
enabledVersions: [{ cliVersion: "2.20.1", tagName: expectedTag }],
});
const path = await startProxyExports.getProxyBinaryPath(logger, features);
const path = await startProxyExports.getProxyBinaryPath({
...state,
features,
});

t.assert(getDefaultCliVersion.calledOnce);
sinon.assert.calledOnceWithMatch(
Expand All @@ -1067,7 +1125,7 @@ test.serial(
});

checkExpectedLogMessages(t, logger.messages, [
`Found '${startProxyExports.getProxyPackage()}' in release '${expectedTag}' at '${downloadUrl}'`,
`Found '${startProxyExports.getProxyPackage(getTestPlatform(state))}' in release '${expectedTag}' at '${downloadUrl}'`,
]);
},
);
Loading
Loading