8000 Send tools telemetry to `init` status report by angelapwen · Pull Request #1497 · github/codeql-action · GitHub
[go: up one dir, main page]

Skip to content

Send tools telemetry to init status report #1497

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Improve CodeQL tools tests
  • Loading branch information
angelapwen committed Jan 23, 2023
commit 89a2e6bdcd5402ec989449cca0aa73ccddcd7ba4
19 changes: 15 additions & 4 deletions lib/codeql.test.js

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

2 changes: 1 addition & 1 deletion lib/codeql.test.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions lib/setup-codeql.js

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

2 changes: 1 addition & 1 deletion lib/setup-codeql.js.map

Large diffs are not rendered by default.

22 changes: 18 additions & 4 deletions src/codeql.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as fs from "fs";
import path from "path";
import { performance } from "perf_hooks";

import * as toolrunner from "@actions/exec/lib/toolrunner";
import * as toolcache from "@actions/tool-cache";
Expand Down Expand Up @@ -42,6 +43,8 @@ const sampleGHAEApiDetails = {
apiURL: "https://example.githubenterprise.com/api/v3",
};

const performanceNowFunction = sinon.spy(performance, "now");

const SAMPLE_DEFAULT_CLI_VERSION: CodeQLDefaultVersionInfo = {
cliVersion: "2.0.0",
variant: util.GitHubVariant.DOTCOM,
Expand Down Expand Up @@ -76,6 +79,8 @@ test.beforeEach(() => {
trapCaches: {},
trapCacheDownloadTime: 0,
};

performanceNowFunction.resetHistory();
});

/**
Expand Down Expand Up @@ -204,9 +209,11 @@ test("downloads and caches explicitly requested bundles that aren't in the toolc
getRunnerLogger(true),
false
);

t.assert(toolcache.find("CodeQL", `0.0.0-${version}`));
t.is(result.toolsVersion, `0.0.0-${version}`);
t.is(result.toolsSource, ToolsSource.Download);
t.assert(performanceNowFunction.notCalled);
t.not(result.toolsDownloadDurationMs, undefined);
}

Expand Down Expand Up @@ -292,6 +299,7 @@ for (const {
t.assert(toolcache.find("CodeQL", expectedToolcacheVersion));
t.deepEqual(result.toolsVersion, cliVersion);
t.is(result.toolsSource, ToolsSource.Download);
t.assert(performanceNowFunction.notCalled);
t.not(result.toolsDownloadDurationMs, undefined);
});
});
Expand Down Expand Up @@ -364,10 +372,12 @@ for (const { isCached, tagName, toolcacheCliVersion } of [

if (isCached) {
t.is(result.toolsSource, ToolsSource.Toolcache);
t.assert(performanceNowFunction.notCalled);
t.is(result.toolsDownloadDurationMs, undefined);
} else {
t.is(result.toolsSource, ToolsSource.Download);
t.not(result.toolsDownloadDurationMs, undefined);
t.assert(performanceNowFunction.calledTwice);
t.is(typeof result.toolsDownloadDurationMs, "number");
}
});
});
Expand Down Expand Up @@ -400,6 +410,7 @@ for (const variant of [util.GitHubVariant.GHAE, util.GitHubVariant.GHES]) {
);
t.deepEqual(result.toolsVersion, "0.0.0-20200601");
t.is(result.toolsSource, ToolsSource.Toolcache);
t.assert(performanceNowFunction.notCalled);
t.is(result.toolsDownloadDurationMs, undefined);

const cachedVersions = toolcache.findAllVersions("CodeQL");
Expand Down Expand Up @@ -436,7 +447,8 @@ for (const variant of [util.GitHubVariant.GHAE, util.GitHubVariant.GHES]) {
);
t.deepEqual(result.toolsVersion, defaults.cliVersion);
t.is(result.toolsSource, ToolsSource.Download);
t.not(result.toolsDownloadDurationMs, undefined);
t.assert(performanceNowFunction.calledTwice);
t.is(typeof result.toolsDownloadDurationMs, "number");

const cachedVersions = toolcache.findAllVersions("CodeQL");
t.is(cachedVersions.length, 2);
Expand Down Expand Up @@ -469,7 +481,8 @@ test('downloads bundle if "latest" tools specified but not cached', async (t) =>
);
t.deepEqual(result.toolsVersion, defaults.cliVersion);
t.is(result.toolsSource, ToolsSource.Download);
t.not(result.toolsDownloadDurationMs, undefined);
t.assert(performanceNowFunction.calledTwice);
t.is(typeof result.toolsDownloadDurationMs, "number");

const cachedVersions = toolcache.findAllVersions("CodeQL");
t.is(cachedVersions.length, 2);
Expand Down Expand Up @@ -535,7 +548,8 @@ test("download codeql bundle from github ae endpoint", async (t) => {
);

t.is(result.toolsSource, ToolsSource.Download);
t.not(result.toolsDownloadDurationMs, undefined);
t.assert(performanceNowFunction.calledTwice);
t.is(typeof result.toolsDownloadDurationMs, "number");

const cachedVersions = toolcache.findAllVersions("CodeQL");
t.is(cachedVersions.length, 1);
Expand Down
4 changes: 2 additions & 2 deletions src/setup-codeql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -548,14 +548,14 @@ export async function downloadCodeQL(
headers
);

const start = performance.now();
const toolsDownloadStart = performance.now();
const codeqlPath = await toolcache.downloadTool(
codeqlURL,
dest,
undefined,
finalHeaders
);
const toolsDownloadDurationMs = performance.now() - start;
const toolsDownloadDurationMs = performance.now() - toolsDownloadStart;

logger.debug(`CodeQL bundle download to ${codeqlPath} complete.`);

Expand Down
0