Generalise getToolsInput into getComputedInput

This commit is contained in:
Michael B. Gale
2026-07-24 17:02:08 +01:00
parent c54d34d000
commit 6e76342b54
3 changed files with 61 additions and 14 deletions

17
lib/entry-points.js generated
View File

@@ -148424,13 +148424,10 @@ function parseUserConfig(logger, pathInput, contents, validateConfig) {
}
// src/config/inputs.ts
async function getToolsInput(action, repositoryProperties) {
const name = "tools" /* Tools */;
async function getComputedInput(action, repositoryProperties, name, options) {
const input = action.actions.getOptionalInput(name);
const propertyValue = repositoryProperties["github-codeql-tools" /* TOOLS */];
const allowRepositoryProperty = await action.features.getValue(
"tools_repository_property" /* ToolsRepositoryProperty */
);
const allowRepositoryProperty = options.repositoryPropertyName !== void 0;
const propertyValue = options.repositoryPropertyName !== void 0 ? repositoryProperties[options.repositoryPropertyName] : void 0;
if (allowRepositoryProperty && propertyValue?.startsWith("!")) {
action.logger.info(
`Using ${name} input from repository property (enforced): ${propertyValue}`
@@ -148456,6 +148453,14 @@ async function getToolsInput(action, repositoryProperties) {
}
return void 0;
}
async function getToolsInput(action, repositoryProperties) {
const allowRepositoryProperty = await action.features.getValue(
"tools_repository_property" /* ToolsRepositoryProperty */
);
return getComputedInput(action, repositoryProperties, "tools" /* Tools */, {
repositoryPropertyName: allowRepositoryProperty ? "github-codeql-tools" /* TOOLS */ : void 0
});
}
// src/config/remote-file.ts
var DEFAULT_CONFIG_FILE_NAME = ".github/codeql-action.yaml";

View File

@@ -3,6 +3,7 @@ import { Feature } from "../feature-flags";
import {
RepositoryProperties,
RepositoryPropertyName,
StringRepositoryPropertyNames,
} from "../feature-flags/properties";
/** Enumerates input names. */
@@ -29,23 +30,35 @@ export type ComputedInput = {
};
/**
* Gets the computed `tools` input. This comes from either the workflow or
* Represents options for how to compute an input.
*/
export interface ComputedInputOptions {
repositoryPropertyName?: StringRepositoryPropertyNames;
}
/**
* Gets the computed input for `name`. This comes from either the workflow or
* the repository property.
*
* @param action The Action state.
* @param repositoryProperties The values of known repository properties.
* @param name The name of the input to compute.
* @param options Options for how to compute the input value.
*
* @returns The computed input or `undefined` if there is no input.
*/
export async function getToolsInput(
export async function getComputedInput(
action: ActionState<["Logger", "Actions", "FeatureFlags"]>,
repositoryProperties: Partial<RepositoryProperties>,
repositoryProperties: RepositoryProperties,
name: InputName,
options: ComputedInputOptions,
): Promise<ComputedInput | undefined> {
const name = InputName.Tools;
const input = action.actions.getOptionalInput(name);
const propertyValue = repositoryProperties[RepositoryPropertyName.TOOLS];
const allowRepositoryProperty = await action.features.getValue(
Feature.ToolsRepositoryProperty,
);
const allowRepositoryProperty = options.repositoryPropertyName !== undefined;
const propertyValue =
options.repositoryPropertyName !== undefined
? repositoryProperties[options.repositoryPropertyName]
: undefined;
// The repository property takes precedence if it starts with an '!'.
if (allowRepositoryProperty && propertyValue?.startsWith("!")) {
@@ -79,3 +92,25 @@ export async function getToolsInput(
// There's no input.
return undefined;
}
/**
* Gets the computed `tools` input. This comes from either the workflow or
* the repository property.
*
* @param action The Action state.
* @param repositoryProperties The values of known repository properties.
* @returns The computed input or `undefined` if there is no input.
*/
export async function getToolsInput(
action: ActionState<["Logger", "Actions", "FeatureFlags"]>,
repositoryProperties: Partial<RepositoryProperties>,
): Promise<ComputedInput | undefined> {
const allowRepositoryProperty = await action.features.getValue(
Feature.ToolsRepositoryProperty,
);
return getComputedInput(action, repositoryProperties, InputName.Tools, {
repositoryPropertyName: allowRepositoryProperty
? RepositoryPropertyName.TOOLS
: undefined,
});
}

View File

@@ -29,6 +29,13 @@ export type AllRepositoryProperties = {
[RepositoryPropertyName.TOOLS]: string;
};
/** The subset of known repository properties which are of type `string`. */
export type StringRepositoryPropertyNames = keyof {
[K in keyof AllRepositoryProperties as AllRepositoryProperties[K] extends string
? K
: never]: AllRepositoryProperties[K];
};
/** Parsed repository properties. */
export type RepositoryProperties = Partial<AllRepositoryProperties>;