Skip to content

Commit

Permalink
Autobuild Go in analyze step
Browse files Browse the repository at this point in the history
  • Loading branch information
angelapwen committed Aug 26, 2022
1 parent a59fbe2 commit 781cafc
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
34 changes: 33 additions & 1 deletion src/analyze-action.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// We need to import `performance` on Node 12
import * as fs from "fs";
import { performance } from "perf_hooks";

import * as core from "@actions/core";
Expand All @@ -13,10 +14,12 @@ import {
runQueries,
} from "./analyze";
import { getGitHubVersionActionsOnly } from "./api-client";
import { runAutobuild } from "./autobuild";
import { getCodeQL } from "./codeql";
import { Config, getConfig } from "./config-utils";
import { uploadDatabases } from "./database-upload";
import { GitHubFeatureFlags } from "./feature-flags";
import { FeatureFlag, GitHubFeatureFlags } from "./feature-flags";
import { Language } from "./languages";
import { getActionsLogger, Logger } from "./logging";
import { parseRepositoryNwo } from "./repository";
import { getTotalCacheSize, uploadTrapCaches } from "./trap-caching";
Expand Down Expand Up @@ -97,6 +100,20 @@ function hasBadExpectErrorInput(): boolean {
);
}

// Check for any .trap[.gz] files under the db-go/ folder
function didGolangExtraction(config: Config): boolean {
const golangDbDirectory = util.getCodeQLDatabasePath(config, Language.go);
const extractedFiles = fs
.readdirSync(golangDbDirectory)
.filter(
(fileName) => fileName.endsWith(".trap") || fileName.endsWith(".trap.gz")
);
if (extractedFiles.length !== 0) {
return true;
}
return false;
}

async function run() {
const startedAt = new Date();
let uploadResult: UploadResult | undefined = undefined;
Expand Down Expand Up @@ -166,6 +183,21 @@ async function run() {
logger
);

if (
await featureFlags.getValue(
FeatureFlag.GolangExtractionReconciliationEnabled
)
) {
// Run autobuilder for Go, unless it's already been run or user built manually
if (
Language.go in config.languages &&
process.env["CODEQL_ACTION_DID_AUTOBUILD_GOLANG"] !== "true" &&
!didGolangExtraction(config)
) {
await runAutobuild(Language.go, config, logger);
}
}

dbCreationTimings = await runFinalize(
outputDir,
threads,
Expand Down
3 changes: 3 additions & 0 deletions src/autobuild-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ async function run() {
process.chdir(workingDirectory);
}
await runAutobuild(language, config, logger);
if (language === Language.go) {
core.exportVariable("CODEQL_ACTION_DID_AUTOBUILD_GOLANG", "true");
}
}
} catch (error) {
core.setFailed(
Expand Down
1 change: 1 addition & 0 deletions src/feature-flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export enum FeatureFlag {
LuaTracerConfigEnabled = "lua_tracer_config_enabled",
MlPoweredQueriesEnabled = "ml_powered_queries_enabled",
TrapCachingEnabled = "trap_caching_enabled",
GolangExtractionReconciliationEnabled = "golang_extraction_reconciliation_enabled",
}

/**
Expand Down

0 comments on commit 781cafc

Please sign in to comment.