Skip to content

Commit

Permalink
Moves calls to pack download to the init action
Browse files Browse the repository at this point in the history
This ensures all steps to gather queries happens in the init action.
This is where checking out queries in other repos happens as well.
  • Loading branch information
aeisenberg committed Aug 26, 2022
1 parent a59fbe2 commit a666267
Show file tree
Hide file tree
Showing 9 changed files with 130 additions and 28 deletions.
9 changes: 0 additions & 9 deletions lib/analyze.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/analyze.js.map

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions lib/config-utils.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/config-utils.js.map

Large diffs are not rendered by default.

48 changes: 48 additions & 0 deletions lib/config-utils.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/config-utils.test.js.map

Large diffs are not rendered by default.

15 changes: 0 additions & 15 deletions src/analyze.ts
Expand Up @@ -280,21 +280,6 @@ export async function runQueries(
logger.endGroup();
logger.info(analysisSummary);
} else {
if (hasPackWithCustomQueries) {
logger.info("Performing analysis with custom CodeQL Packs.");
logger.startGroup(`Downloading custom packs for ${language}`);

const results = await codeql.packDownload(packsWithVersion);

logger.info(
`Downloaded packs: ${results.packs
.map((r) => `${r.name}@${r.version || "latest"}`)
.join(", ")}`
);

logger.endGroup();
}

logger.startGroup(`Running queries for ${language}`);
const querySuitePaths: string[] = [];
if (queries["builtin"].length > 0) {
Expand Down
50 changes: 49 additions & 1 deletion src/config-utils.test.ts
Expand Up @@ -6,7 +6,7 @@ import test, { ExecutionContext } from "ava";
import * as sinon from "sinon";

import * as api from "./api-client";
import { getCachedCodeQL, setCodeQL } from "./codeql";
import { getCachedCodeQL, PackDownloadOutput, setCodeQL } from "./codeql";
import * as configUtils from "./config-utils";
import { createFeatureFlags, FeatureFlag } from "./feature-flags";
import { Language } from "./languages";
Expand Down Expand Up @@ -78,6 +78,9 @@ test("load empty config", async (t) => {
multipleDeclaredLanguages: {},
};
},
async packDownload(): Promise<PackDownloadOutput> {
return { packs: [] };
},
});

const config = await configUtils.initConfig(
Expand Down Expand Up @@ -139,6 +142,9 @@ test("loading config saves config", async (t) => {
multipleDeclaredLanguages: {},
};
},
async packDownload(): Promise<PackDownloadOutput> {
return { packs: [] };
},
});

// Sanity check the saved config file does not already exist
Expand Down Expand Up @@ -311,6 +317,9 @@ test("load non-empty input", async (t) => {
multipleDeclaredLanguages: {},
};
},
async packDownload(): Promise<PackDownloadOutput> {
return { packs: [] };
},
});

// Just create a generic config object with non-default values for all fields
Expand Down Expand Up @@ -419,6 +428,9 @@ test("Default queries are used", async (t) => {
multipleDeclaredLanguages: {},
};
},
async packDownload(): Promise<PackDownloadOutput> {
return { packs: [] };
},
});

// The important point of this config is that it doesn't specify
Expand Down Expand Up @@ -504,6 +516,9 @@ test("Queries can be specified in config file", async (t) => {
resolveQueriesArgs.push({ queries, extraSearchPath });
return queriesToResolvedQueryForm(queries);
},
async packDownload(): Promise<PackDownloadOutput> {
return { packs: [] };
},
});

const languages = "javascript";
Expand Down Expand Up @@ -578,6 +593,9 @@ test("Queries from config file can be overridden in workflow file", async (t) =>
resolveQueriesArgs.push({ queries, extraSearchPath });
return queriesToResolvedQueryForm(queries);
},
async packDownload(): Promise<PackDownloadOutput> {
return { packs: [] };
},
});

const languages = "javascript";
Expand Down Expand Up @@ -650,6 +668,9 @@ test("Queries in workflow file can be used in tandem with the 'disable default q
resolveQueriesArgs.push({ queries, extraSearchPath });
return queriesToResolvedQueryForm(queries);
},
async packDownload(): Promise<PackDownloadOutput> {
return { packs: [] };
},
});

const languages = "javascript";
Expand Down Expand Up @@ -713,6 +734,9 @@ test("Multiple queries can be specified in workflow file, no config file require
resolveQueriesArgs.push({ queries, extraSearchPath });
return queriesToResolvedQueryForm(queries);
},
async packDownload(): Promise<PackDownloadOutput> {
return { packs: [] };
},
});

const languages = "javascript";
Expand Down Expand Up @@ -797,6 +821,9 @@ test("Queries in workflow file can be added to the set of queries without overri
resolveQueriesArgs.push({ queries, extraSearchPath });
return queriesToResolvedQueryForm(queries);
},
async packDownload(): Promise<PackDownloadOutput> {
return { packs: [] };
},
});

const languages = "javascript";
Expand Down Expand Up @@ -876,6 +903,9 @@ test("Invalid queries in workflow file handled correctly", async (t) => {
multipleDeclaredLanguages: {},
};
},
async packDownload(): Promise<PackDownloadOutput> {
return { packs: [] };
},
});

try {
Expand Down Expand Up @@ -922,6 +952,9 @@ test("API client used when reading remote config", async (t) => {
multipleDeclaredLanguages: {},
};
},
async packDownload(): Promise<PackDownloadOutput> {
return { packs: [] };
},
});

const inputFileContents = `
Expand Down Expand Up @@ -1051,6 +1084,9 @@ test("No detected languages", async (t) => {
async resolveLanguages() {
return {};
},
async packDownload(): Promise<PackDownloadOutput> {
return { packs: [] };
},
});

try {
Expand Down Expand Up @@ -1124,6 +1160,9 @@ test("Config specifies packages", async (t) => {
multipleDeclaredLanguages: {},
};
},
async packDownload(): Promise<PackDownloadOutput> {
return { packs: [] };
},
});

const inputFileContents = `
Expand Down Expand Up @@ -1175,6 +1214,9 @@ test("Config specifies packages for multiple languages", async (t) => {
multipleDeclaredLanguages: {},
};
},
async packDownload(): Promise<PackDownloadOutput> {
return { packs: [] };
},
});

const inputFileContents = `
Expand Down Expand Up @@ -1255,6 +1297,9 @@ function doInvalidInputTest(
multipleDeclaredLanguages: {},
};
},
async packDownload(): Promise<PackDownloadOutput> {
return { packs: [] };
},
});

const languages = "javascript";
Expand Down Expand Up @@ -1845,6 +1890,9 @@ const mlPoweredQueriesMacro = test.macro({
multipleDeclaredLanguages: {},
};
},
async packDownload(): Promise<PackDownloadOutput> {
return { packs: [] };
},
});

const { packs } = await configUtils.initConfig(
Expand Down

0 comments on commit a666267

Please sign in to comment.