Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
23 changes: 6 additions & 17 deletions lib/init-action.js

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

3 changes: 1 addition & 2 deletions src/codeql.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -503,11 +503,10 @@ const injectedConfigMacro = test.macro({
...stubConfig,
...configOverride,
tempDir,
augmentationProperties,
};
thisStubConfig.computedConfig = generateCodeScanningConfig(
thisStubConfig.originalUserInput,
thisStubConfig.augmentationProperties,
augmentationProperties,
);

await codeqlObject.databaseInitCluster(
Expand Down
10 changes: 5 additions & 5 deletions src/config-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,17 +157,18 @@ test("load empty config", async (t) => {
}),
);

t.deepEqual(
config,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { augmentationProperties, ...expectedConfig } =
await configUtils.getDefaultConfig(
createTestInitConfigInputs({
languagesInput: languages,
tempDir,
codeql,
logger,
}),
),
);
);

t.deepEqual(config, expectedConfig);
});
});

Expand Down Expand Up @@ -344,7 +345,6 @@ test("load non-empty input", async (t) => {
debugMode: false,
debugArtifactName: "my-artifact",
debugDatabaseName: "my-db",
augmentationProperties: configUtils.defaultAugmentationProperties,
trapCaches: {},
trapCacheDownloadTime: 0,
dependencyCachingEnabled: CachingKind.None,
Expand Down
14 changes: 5 additions & 9 deletions src/config-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,6 @@ export interface Config {
* Specifies the name of the database in the debugging artifact.
*/
debugDatabaseName: string;

/**
* Describes how to augment the user configuration with inputs from the action.
*/
augmentationProperties: AugmentationProperties;

/**
* The configuration we computed by combining `originalUserInput` with `augmentationProperties`,
* as well as adjustments made to it based on unsupported or required options.
Expand Down Expand Up @@ -536,7 +530,9 @@ export async function getDefaultConfig({
githubVersion,
features,
logger,
}: InitConfigInputs): Promise<Config> {
}: InitConfigInputs): Promise<
Config & { augmentationProperties: AugmentationProperties }
> {
const analysisKinds = await parseAnalysisKinds(analysisKindsInput);

// For backwards compatibility, add Code Quality to the enabled analysis kinds
Expand Down Expand Up @@ -1104,14 +1100,14 @@ export async function initConfig(inputs: InitConfigInputs): Promise<Config> {
);
}

const config = await getDefaultConfig(inputs);
const { augmentationProperties, ...config } = await getDefaultConfig(inputs);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that we only use getDefaultConfig in this function, consider having getDefaultConfig populate computedConfig directly to simplify the flow.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have made the UserConfig (from the inputs) an argument to getDefaultConfig (now initActionState), set it there, and generate computedConfig there. That avoids having to return augmentationProperties as well.

config.originalUserInput = userConfig;

// Compute the full Code Scanning configuration that combines the configuration from the
// configuration file / `config` input with other inputs, such as `queries`.
config.computedConfig = generateCodeScanningConfig(
userConfig,
config.augmentationProperties,
augmentationProperties,
);

// The choice of overlay database mode depends on the selection of languages
Expand Down
27 changes: 4 additions & 23 deletions src/init-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ import {
ConfigurationError,
wrapError,
checkActionVersion,
cloneObject,
getErrorMessage,
} from "./util";
import { validateWorkflow } from "./workflow";
Expand Down Expand Up @@ -206,28 +205,10 @@ async function sendCompletedStatusReport(
}

let packs: Record<string, string[]> = {};
if (
(config.augmentationProperties.packsInputCombines ||
!config.augmentationProperties.packsInput) &&
config.originalUserInput.packs
) {
// Make a copy, because we might modify `packs`.
const copyPacksFromOriginalUserInput = cloneObject(
config.originalUserInput.packs,
);
// If it is an array, then assume there is only a single language being analyzed.
if (Array.isArray(copyPacksFromOriginalUserInput)) {
packs[config.languages[0]] = copyPacksFromOriginalUserInput;
} else {
packs = copyPacksFromOriginalUserInput;
}
}

if (config.augmentationProperties.packsInput) {
packs[config.languages[0]] ??= [];
packs[config.languages[0]].push(
...config.augmentationProperties.packsInput,
);
if (Array.isArray(config.computedConfig.packs)) {
packs[config.languages[0]] = config.computedConfig.packs;
} else if (config.computedConfig.packs !== undefined) {
packs = config.computedConfig.packs;
}

// Append fields that are dependent on `config`
Expand Down
6 changes: 1 addition & 5 deletions src/testing-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import * as apiClient from "./api-client";
import { GitHubApiDetails } from "./api-client";
import { CachingKind } from "./caching-utils";
import * as codeql from "./codeql";
import { AugmentationProperties, Config } from "./config-utils";
import { Config } from "./config-utils";
import * as defaults from "./defaults.json";
import {
CodeQLDefaultVersionInfo,
Expand Down Expand Up @@ -370,10 +370,6 @@ export function createTestConfig(overrides: Partial<Config>): Config {
debugMode: false,
debugArtifactName: DEFAULT_DEBUG_ARTIFACT_NAME,
debugDatabaseName: DEFAULT_DEBUG_DATABASE_NAME,
augmentationProperties: {
packsInputCombines: false,
queriesInputCombines: false,
} satisfies AugmentationProperties,
trapCaches: {},
trapCacheDownloadTime: 0,
dependencyCachingEnabled: CachingKind.None,
Expand Down
Loading