Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
1,511 changes: 761 additions & 750 deletions lib/entry-points.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package-lock.json

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

6 changes: 0 additions & 6 deletions src/actions-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,6 @@ export function getTemporaryDirectory(env: ReadOnlyEnv = getEnv()): string {
);
}

const PR_DIFF_RANGE_JSON_FILENAME = "pr-diff-range.json";

export function getDiffRangesJsonFilePath(env: Env = getEnv()): string {
return path.join(getTemporaryDirectory(env), PR_DIFF_RANGE_JSON_FILENAME);
}

export function getActionVersion(): string {
return __CODEQL_ACTION_VERSION__;
}
Expand Down
10 changes: 7 additions & 3 deletions src/analyze.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ import {
} from "./dependency-caching";
import { addDiagnostic, makeDiagnostic } from "./diagnostics";
import {
DiffThunkRange,
type DiffThunkRange,
getDiffRangesJsonFilePath,
readDiffRangesJsonFile,
} from "./diff-informed-analysis-utils";
} from "./diff-informed";
import { EnvVar } from "./environment";
import { FeatureEnablement, Feature } from "./feature-flags";
import { getGitRoot } from "./git-utils";
Expand Down Expand Up @@ -295,7 +296,10 @@ export async function setupDiffInformedQueryRun(
return await withGroupAsync(
"Generating diff range extension pack",
async () => {
const diffRanges = readDiffRangesJsonFile(logger);
const diffRanges = readDiffRangesJsonFile(
logger,
getDiffRangesJsonFilePath(),
);
if (diffRanges === undefined) {
logger.info(
"No precomputed diff ranges found; skipping diff-informed analysis stage.",
Expand Down
29 changes: 18 additions & 11 deletions src/config-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { createStubCodeQL } from "./codeql";
import { UserConfig } from "./config/db-config";
import * as file from "./config/file";
import * as configUtils from "./config-utils";
import { ActionsEnvVars } from "./environment";
import * as errorMessages from "./error-messages";
import { Feature } from "./feature-flags";
import { RepositoryProperties } from "./feature-flags/properties";
Expand Down Expand Up @@ -42,6 +43,7 @@ import {
SAMPLE_DOTCOM_API_DETAILS,
AssertableTarget,
RecordingLogger,
getTestEnv,
} from "./testing-utils";
import {
GitHubVariant,
Expand Down Expand Up @@ -151,9 +153,11 @@ function mockListLanguages(languages: string[]) {
test.serial("load empty config", async (t) => {
return await withTmpDir(async (tempDir) => {
const logger = new RecordingLogger();
const state = initAllState({ logger });

const languages = "javascript,python";

setupActionsVars(tempDir, tempDir);
setupActionsVars(tempDir, tempDir, {}, state.env);

const codeql = createStubCodeQL({
async resolveLanguages() {
Expand All @@ -166,7 +170,6 @@ test.serial("load empty config", async (t) => {
},
});

const state = initAllState({ logger });
const config = await configUtils.initConfig(
state,
createTestInitConfigInputs({
Expand Down Expand Up @@ -197,9 +200,10 @@ test.serial("load empty config", async (t) => {
test.serial("load code quality config", async (t) => {
return await withTmpDir(async (tempDir) => {
const logger = new RecordingLogger();
const state = initAllState({ logger });
const languages = "actions";

setupActionsVars(tempDir, tempDir);
setupActionsVars(tempDir, tempDir, {}, state.env);

const codeql = createStubCodeQL({
async resolveLanguages() {
Expand All @@ -211,7 +215,6 @@ test.serial("load code quality config", async (t) => {
},
});

const state = initAllState({ logger });
const config = await configUtils.initConfig(
state,
createTestInitConfigInputs({
Expand Down Expand Up @@ -253,9 +256,10 @@ test.serial(
async (t) => {
return await withTmpDir(async (tempDir) => {
const logger = new RecordingLogger();
const state = initAllState({ logger });
const languages = "javascript";

setupActionsVars(tempDir, tempDir);
setupActionsVars(tempDir, tempDir, {}, state.env);

const codeql = createStubCodeQL({
async resolveLanguages() {
Expand Down Expand Up @@ -291,7 +295,6 @@ test.serial(
repositoryProperties,
});

const state = initAllState({ logger });
await t.notThrowsAsync(async () => {
const config = await configUtils.initConfig(
state,
Expand All @@ -316,6 +319,8 @@ test.serial(
test.serial("loading a saved config produces the same config", async (t) => {
return await withTmpDir(async (tempDir) => {
const logger = new RecordingLogger();
const state = initAllState({ logger });
setupActionsVars(tempDir, tempDir, {}, state.env);

const codeql = createStubCodeQL({
async resolveLanguages() {
Expand All @@ -334,7 +339,6 @@ test.serial("loading a saved config produces the same config", async (t) => {
// Sanity check that getConfig returns undefined before we have called initConfig
t.deepEqual(await configUtils.getConfig(tempDir, logger), undefined);

const state = initAllState({ logger });
const config1 = await configUtils.initConfig(
state,
createTestInitConfigInputs({
Expand Down Expand Up @@ -364,6 +368,8 @@ test.serial("loading a saved config produces the same config", async (t) => {
test.serial("loading config with version mismatch throws", async (t) => {
return await withTmpDir(async (tempDir) => {
const logger = new RecordingLogger();
const state = initAllState({ logger });
setupActionsVars(tempDir, tempDir, {}, state.env);

const codeql = createStubCodeQL({
async resolveLanguages() {
Expand All @@ -387,7 +393,6 @@ test.serial("loading config with version mismatch throws", async (t) => {
.stub(actionsUtil, "getActionVersion")
.returns("does-not-exist");

const state = initAllState({ logger });
const config = await configUtils.initConfig(
state,
createTestInitConfigInputs({
Expand Down Expand Up @@ -497,7 +502,8 @@ const otherConfigFileContents = `

test.serial("load non-empty input", async (t) => {
return await withTmpDir(async (tempDir) => {
setupActionsVars(tempDir, tempDir);
const state = initAllState();
setupActionsVars(tempDir, tempDir, {}, state.env);

const codeql = createStubCodeQL({
async resolveLanguages() {
Expand Down Expand Up @@ -538,7 +544,6 @@ test.serial("load non-empty input", async (t) => {
const languagesInput = "javascript";
const configFilePath = createConfigFile(otherConfigFileContents, tempDir);

const state = initAllState();
const actualConfig = await configUtils.initConfig(
state,
createTestInitConfigInputs({
Expand Down Expand Up @@ -657,7 +662,9 @@ test.serial("API client used when reading remote config", async (t) => {
const configFile = "octo-org/codeql-config/config.yaml@main";
const languagesInput = "javascript";

const state = initAllState();
const state = initAllState({
env: getTestEnv({ [ActionsEnvVars.RUNNER_TEMP]: tempDir }),
});
await configUtils.initConfig(
state,
createTestInitConfigInputs({
Expand Down
10 changes: 7 additions & 3 deletions src/config-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ import {
addNoLanguageDiagnostic,
makeTelemetryDiagnostic,
} from "./diagnostics";
import { prepareDiffInformedAnalysis } from "./diff-informed-analysis-utils";
import {
getDiffRangesJsonFilePath,
prepareDiffInformedAnalysis,
} from "./diff-informed";
import { EnvVar, exportEnvVar, getEnv } from "./environment";
import * as errorMessages from "./error-messages";
import { Feature, FeatureEnablement, FeatureWithoutCLI } from "./feature-flags";
Expand Down Expand Up @@ -1288,9 +1291,10 @@ export async function initConfig(
}

const hasDiffRanges = await prepareDiffInformedAnalysis(
inputs.codeql,
inputs.features,
logger,
inputs.features,
inputs.codeql,
getDiffRangesJsonFilePath(actionState.env),
);

await applyIncrementalAnalysisSettings(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import test, { ExecutionContext } from "ava";
import * as sinon from "sinon";

import * as actionsUtil from "./actions-util";
import type { PullRequestBranches } from "./actions-util";
import * as apiClient from "./api-client";
import {
getDiffInformedAnalysisBranches,
prepareDiffInformedAnalysis,
exportedForTesting,
} from "./diff-informed-analysis-utils";
import { Feature, FeatureEnablement, initFeatures } from "./feature-flags";
import { parseRepositoryNwo } from "./repository";
import * as actionsUtil from "../actions-util";
import type { PullRequestBranches } from "../actions-util";
import * as apiClient from "../api-client";
import { getEnv } from "../environment";
import { Feature, FeatureEnablement, initFeatures } from "../feature-flags";
import { parseRepositoryNwo } from "../repository";
import {
setupTests,
createFeatures,
Expand All @@ -19,9 +15,16 @@ import {
setupActionsVars,
makeMacro,
RecordingLogger,
} from "./testing-utils";
import { GitHubVariant, withTmpDir } from "./util";
import type { GitHubVersion } from "./util";
} from "../testing-utils";
import { GitHubVariant, withTmpDir } from "../util";
import type { GitHubVersion } from "../util";

import {
getDiffInformedAnalysisBranches,
prepareDiffInformedAnalysis,
exportedForTesting,
getDiffRangesJsonFilePath,
} from ".";

setupTests(test);

Expand Down Expand Up @@ -192,9 +195,10 @@ test.serial(
.resolves({ type: GitHubVariant.DOTCOM });

const result = await prepareDiffInformedAnalysis(
codeql,
features,
logger,
features,
codeql,
getDiffRangesJsonFilePath(getEnv()),
);

t.false(result);
Expand Down Expand Up @@ -222,9 +226,10 @@ test.serial(
};

const result = await prepareDiffInformedAnalysis(
codeql,
features,
logger,
features,
codeql,
getDiffRangesJsonFilePath(getEnv()),
);

t.false(result);
Expand Down Expand Up @@ -259,9 +264,10 @@ test.serial(
} as any);

const result = await prepareDiffInformedAnalysis(
codeql,
features,
logger,
features,
codeql,
getDiffRangesJsonFilePath(getEnv()),
);

t.true(result);
Expand Down Expand Up @@ -296,9 +302,10 @@ test.serial(
} as any);

const result = await prepareDiffInformedAnalysis(
codeql,
features,
logger,
features,
codeql,
getDiffRangesJsonFilePath(getEnv()),
);

t.false(result);
Expand Down
Loading
Loading