From 781cafc0cbfa361f5eab173301fed27b217b93b7 Mon Sep 17 00:00:00 2001 From: Angela P Wen Date: Fri, 26 Aug 2022 15:06:09 -0700 Subject: [PATCH] Autobuild Go in analyze step --- src/analyze-action.ts | 34 +++++++++++++++++++++++++++++++++- src/autobuild-action.ts | 3 +++ src/feature-flags.ts | 1 + 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/analyze-action.ts b/src/analyze-action.ts index 74d71b6df4..752168e700 100644 --- a/src/analyze-action.ts +++ b/src/analyze-action.ts @@ -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"; @@ -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"; @@ -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; @@ -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, diff --git a/src/autobuild-action.ts b/src/autobuild-action.ts index be216b64e4..5f7b2ec61f 100644 --- a/src/autobuild-action.ts +++ b/src/autobuild-action.ts @@ -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( diff --git a/src/feature-flags.ts b/src/feature-flags.ts index e220c585ae..0d7359d25b 100644 --- a/src/feature-flags.ts +++ b/src/feature-flags.ts @@ -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", } /**