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
123 changes: 65 additions & 58 deletions lib/entry-points.js

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

3 changes: 2 additions & 1 deletion src/start-proxy-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ async function run(action: ActionState<["Base", "Logger", "Env", "Actions"]>) {
getApiDetails(action.env),
);
const proxyInfo = await startProxy(
proxyBin,
proxyBin.path,
proxyConfig,
proxyLogFilePath,
logger,
Expand All @@ -125,6 +125,7 @@ async function run(action: ActionState<["Base", "Logger", "Env", "Actions"]>) {
languages: language === undefined ? undefined : [language],
},
proxyConfig.all_credentials.map((c) => c.type),
{ proxy_version: proxyBin.version },
logger,
);
} catch (unwrappedError) {
Expand Down
116 changes: 18 additions & 98 deletions src/start-proxy.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as filepath from "path";

import * as core from "@actions/core";
import * as toolcache from "@actions/tool-cache";
import test, { ExecutionContext } from "ava";
import sinon from "sinon";
Expand All @@ -18,7 +17,6 @@ import { getRunnerLogger, Logger } from "./logging";
import { BundlePlatform, getBundlePlatform } from "./platform";
import * as repository from "./setup/repository";
import * as startProxyExports from "./start-proxy";
import * as statusReport from "./status-report";
import {
addSinonAssertions,
assertNotLogged,
Expand All @@ -32,94 +30,10 @@ import {
setupTests,
withRecordingLoggerAsync,
} from "./testing-utils";
import {
ConfigurationError,
GitHubVariant,
GitHubVersion,
withTmpDir,
} from "./util";
import { GitHubVariant, GitHubVersion, withTmpDir } from "./util";

setupTests(test);

const sendFailedStatusReportTest = makeMacro({
exec: async (
t: ExecutionContext<unknown>,
err: Error,
expectedMessage: string,
expectedStatus: statusReport.ActionStatus = "failure",
) => {
const now = new Date();

// Override core.setFailed to avoid it setting the program's exit code
sinon.stub(core, "setFailed").returns();

const createStatusReportBase = sinon.stub(
statusReport,
"createStatusReportBase",
);
createStatusReportBase.resolves(undefined);

await withRecordingLoggerAsync(async (logger) => {
await startProxyExports.sendFailedStatusReport(
logger,
now,
undefined,
err,
);

// Check that the stub has been called exactly once, with the expected arguments,
// but not with the message from the error.
sinon.assert.calledOnceWithExactly(
createStatusReportBase,
statusReport.ActionName.StartProxy,
expectedStatus,
now,
sinon.match.any,
sinon.match.any,
sinon.match.any,
expectedMessage,
);
t.false(
createStatusReportBase.calledWith(
statusReport.ActionName.StartProxy,
expectedStatus,
now,
sinon.match.any,
sinon.match.any,
sinon.match.any,
sinon.match((msg: string) => msg.includes(err.message)),
),
"createStatusReportBase was called with the error message",
);
});
},

title: (providedTitle = "") => `sendFailedStatusReport - ${providedTitle}`,
});

sendFailedStatusReportTest.serial(
"reports generic error message for non-StartProxyError error",
new Error("Something went wrong today"),
"Error from start-proxy Action omitted (Error).",
);

sendFailedStatusReportTest.serial(
"reports generic error message for non-StartProxyError error with safe error message",
new Error(
startProxyExports.getStartProxyErrorMessage(
startProxyExports.StartProxyErrorType.DownloadFailed,
),
),
"Error from start-proxy Action omitted (Error).",
);

sendFailedStatusReportTest.serial(
"reports generic error message for ConfigurationError error",
new ConfigurationError("Something went wrong today"),
"Error from start-proxy Action omitted (ConfigurationError).",
"user-error",
);

const toEncodedJSON = (data: any) =>
Buffer.from(JSON.stringify(data)).toString("base64");

Expand Down Expand Up @@ -1021,16 +935,17 @@ test.serial(
sinon.stub(actionsUtil, "isRunningLocalAction").returns(true);

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

t.assert(path);
t.assert(result);
t.is(
path,
result.path,
filepath.join(toolcachePath, startProxyExports.getProxyFilename()),
);
t.is(result.version, defaults.cliVersion);
});
},
);
Expand Down Expand Up @@ -1067,7 +982,7 @@ test.serial(
sinon.stub(actionsUtil, "isRunningLocalAction").returns(false);
state.env.set(ActionsEnvVars.GITHUB_ACTION_REPOSITORY, "test/repo");

const path = await startProxyExports.getProxyBinaryPath(
const result = await startProxyExports.getProxyBinaryPath(
{
...state,
features: createFeatures([]),
Expand All @@ -1084,11 +999,12 @@ test.serial(
st.onceWith(extractTar, archivePath);
st.onceWith(cacheDir, extractedPath);

t.assert(path);
t.assert(result);
t.is(
path,
result.path,
filepath.join(toolcachePath, startProxyExports.getProxyFilename()),
);
t.is(result.version, defaults.cliVersion);

checkExpectedLogMessages(t, logger.messages, [
`Found private registry proxy ${startProxyExports.getProxyPackage(getTestPlatform(state))} in test/repo on https://github.com with URL ${downloadUrl}`,
Expand All @@ -1101,7 +1017,8 @@ test.serial(
async (t) => {
const logger = new RecordingLogger();
const state = initAllState({ logger });
const expectedTag = "codeql-bundle-v2.20.1";
const expectedVersion = "2.20.1";
const expectedTag = `codeql-bundle-v${expectedVersion}`;
const expectedParams = {
owner: "test",
repo: "repo",
Expand Down Expand Up @@ -1154,14 +1071,16 @@ test.serial(
const getDefaultCliVersion = sinon
.stub(features, "getEnabledDefaultCliVersions")
.resolves({
enabledVersions: [{ cliVersion: "2.20.1", tagName: expectedTag }],
enabledVersions: [
{ cliVersion: expectedVersion, tagName: expectedTag },
],
});

// Stub this to always return `false` so we force `getCodeQLAssetDownloadURL` to use the (mocked) API.
sinon.stub(actionsUtil, "isRunningLocalAction").returns(false);
state.env.set(ActionsEnvVars.GITHUB_ACTION_REPOSITORY, "test/repo");

const path = await startProxyExports.getProxyBinaryPath(
const result = await startProxyExports.getProxyBinaryPath(
{
...state,
features,
Expand All @@ -1179,11 +1098,12 @@ test.serial(
st.onceWith(extractTar, archivePath);
st.onceWith(cacheDir, extractedPath);

t.assert(path);
t.assert(result);
t.is(
path,
result.path,
filepath.join(toolcachePath, startProxyExports.getProxyFilename()),
);
t.is(result.version, expectedVersion);
});

checkExpectedLogMessages(t, logger.messages, [
Expand Down
Loading
Loading