Skip to content

Commit

Permalink
Add detected tar version to telemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
Henry Mercer committed Aug 29, 2024
1 parent ffa1b05 commit 335044a
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 12 deletions.
17 changes: 17 additions & 0 deletions lib/init-action.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/init-action.js.map

Large diffs are not rendered by default.

15 changes: 11 additions & 4 deletions lib/tar.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/tar.js.map

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

26 changes: 26 additions & 0 deletions src/init-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import {
getActionsStatus,
sendStatusReport,
} from "./status-report";
import { isZstdAvailable } from "./tar";
import { ToolsFeature } from "./tools-features";
import { getTotalCacheSize } from "./trap-caching";
import {
Expand Down Expand Up @@ -375,6 +376,8 @@ async function run() {
try {
cleanupDatabaseClusterDirectory(config, logger);

await logZstdAvailability(config, logger);

// Log CodeQL download telemetry, if appropriate
if (toolsDownloadStatusReport) {
addDiagnostic(
Expand Down Expand Up @@ -670,6 +673,29 @@ function getTrapCachingEnabled(): boolean {
return true;
}

async function logZstdAvailability(config: configUtils.Config, logger: Logger) {
// Log zstd availability
const zstdAvailableResult = await isZstdAvailable(logger);
addDiagnostic(
config,
// Arbitrarily choose the first language. We could also choose all languages, but that
// increases the risk of misinterpreting the data.
config.languages[0],
makeDiagnostic(
"codeql-action/zstd-availability",
"Zstandard availability",
{
attributes: zstdAvailableResult,
visibility: {
cliSummaryTable: false,
statusPage: false,
telemetry: true,
},
},
),
);
}

async function runWrapper() {
try {
await run();
Expand Down
21 changes: 15 additions & 6 deletions src/tar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { assertNever } from "./util";
const MIN_REQUIRED_BSD_TAR_VERSION = "3.4.3";
const MIN_REQUIRED_GNU_TAR_VERSION = "1.31";

type TarVersion = {
export type TarVersion = {
type: "gnu" | "bsd";
version: string;
};
Expand Down Expand Up @@ -46,15 +46,24 @@ async function getTarVersion(): Promise<TarVersion> {
}
}

export async function isZstdAvailable(logger: Logger): Promise<boolean> {
export async function isZstdAvailable(
logger: Logger,
): Promise<{ available: boolean; version?: TarVersion }> {
try {
const { type, version } = await getTarVersion();
const tarVersion = await getTarVersion();
const { type, version } = tarVersion;
logger.info(`Found ${type} tar version ${version}.`);
switch (type) {
case "gnu":
return version >= MIN_REQUIRED_GNU_TAR_VERSION;
return {
available: version >= MIN_REQUIRED_GNU_TAR_VERSION,
version: tarVersion,
};
case "bsd":
return version >= MIN_REQUIRED_BSD_TAR_VERSION;
return {
available: version >= MIN_REQUIRED_BSD_TAR_VERSION,
version: tarVersion,
};
default:
assertNever(type);
}
Expand All @@ -63,7 +72,7 @@ export async function isZstdAvailable(logger: Logger): Promise<boolean> {
"Failed to determine tar version, therefore will assume zstd may not be available. " +
`The underlying error was: ${e}`,
);
return false;
return { available: false };
}
}

Expand Down

0 comments on commit 335044a

Please sign in to comment.