Skip to content

Commit f9b6569

Browse files
committed
More fixes from CR
1 parent 3782e65 commit f9b6569

5 files changed

Lines changed: 37 additions & 52 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ See the [releases page](https://github.com/github/codeql-action/releases) for th
44

55
## [UNRELEASED]
66

7-
- Organizations can now create a custom repository property with the name `github-codeql-tools` to set the default CodeQL CLI tools value for their repositories. For more information, see [Managing custom properties for repositories in your organization](https://docs.github.com/en/organizations/managing-organization-settings/managing-custom-properties-for-repositories-in-your-organization), [Repository properties for Code Scanning](https://docs.github.com/en/code-security/concepts/code-scanning/repository-properties) and [Customizing your advanced setup for code scanning](https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning).
7+
- Organizations can now create a custom repository property with the name `github-codeql-tools` to set the default CodeQL CLI tools value for dynamic workflows. If a workflow provides an explicit `tools:` input, that input takes precedence. For more information, see [Managing custom properties for repositories in your organization](https://docs.github.com/en/organizations/managing-organization-settings/managing-custom-properties-for-repositories-in-your-organization), [Repository properties for Code Scanning](https://docs.github.com/en/code-security/concepts/code-scanning/repository-properties) and [Customizing your advanced setup for code scanning](https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning).
88

99
## 4.36.0 - 22 May 2026
1010

src/init-action.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import * as semver from "semver";
77
import { v4 as uuidV4 } from "uuid";
88

99
import {
10+
isDynamicWorkflow,
1011
FileCmdNotFoundError,
1112
getActionVersion,
1213
getFileType,
@@ -297,9 +298,10 @@ async function run(startedAt: Date) {
297298

298299
// Determine the effective tools input.
299300
// The explicit `tools` workflow input takes precedence. If none is provided,
300-
// fall back to the 'github-codeql-tools' repository property (if set).
301+
// fall back to the 'github-codeql-tools' repository property (if set) only for dynamic workflows.
301302
effectiveToolsInput = resolveToolsInput(
302303
getOptionalInput("tools"),
304+
isDynamicWorkflow(),
303305
repositoryProperties,
304306
logger,
305307
);

src/resolve-tools-input.test.ts

Lines changed: 20 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ test("resolveToolsInput returns undefined when no tools input or repository prop
1111
const loggedMessages: LoggedMessage[] = [];
1212
const logger = getRecordingLogger(loggedMessages);
1313

14-
const result = resolveToolsInput(undefined, {}, logger);
14+
const result = resolveToolsInput(undefined, true, {}, logger);
1515

1616
t.is(result, undefined);
1717
t.is(loggedMessages.length, 0);
@@ -21,7 +21,7 @@ test("resolveToolsInput returns workflow input when only workflow input is provi
2121
const loggedMessages: LoggedMessage[] = [];
2222
const logger = getRecordingLogger(loggedMessages);
2323

24-
const result = resolveToolsInput("latest", {}, logger);
24+
const result = resolveToolsInput("latest", true, {}, logger);
2525

2626
t.is(result, "latest");
2727
t.is(loggedMessages.length, 1);
@@ -38,7 +38,7 @@ test("resolveToolsInput returns repository property when only repository propert
3838
const repositoryProperties: RepositoryProperties = {
3939
[RepositoryPropertyName.TOOLS]: "toolcache",
4040
};
41-
const result = resolveToolsInput(undefined, repositoryProperties, logger);
41+
const result = resolveToolsInput(undefined, true, repositoryProperties, logger);
4242

4343
t.is(result, "toolcache");
4444
t.is(loggedMessages.length, 1);
@@ -55,7 +55,7 @@ test("resolveToolsInput prioritizes workflow input over repository property", (t
5555
const repositoryProperties: RepositoryProperties = {
5656
[RepositoryPropertyName.TOOLS]: "toolcache",
5757
};
58-
const result = resolveToolsInput("nightly", repositoryProperties, logger);
58+
const result = resolveToolsInput("nightly", true, repositoryProperties, logger);
5959

6060
t.is(result, "nightly");
6161
t.is(loggedMessages.length, 1);
@@ -72,7 +72,7 @@ test("resolveToolsInput treats empty string workflow input as not set", (t) => {
7272
const repositoryProperties: RepositoryProperties = {
7373
[RepositoryPropertyName.TOOLS]: "toolcache",
7474
};
75-
const result = resolveToolsInput("", repositoryProperties, logger);
75+
const result = resolveToolsInput("", true, repositoryProperties, logger);
7676

7777
t.is(result, "toolcache");
7878
t.is(loggedMessages.length, 1);
@@ -82,62 +82,34 @@ test("resolveToolsInput treats empty string workflow input as not set", (t) => {
8282
);
8383
});
8484

85-
test("resolveToolsInput returns workflow input with URL value", (t) => {
86-
const loggedMessages: LoggedMessage[] = [];
87-
const logger = getRecordingLogger(loggedMessages);
88-
89-
const url = "https://example.com/codeql-bundle.tar.gz";
90-
const result = resolveToolsInput(url, {}, logger);
91-
92-
t.is(result, url);
93-
t.is(loggedMessages.length, 1);
94-
t.is(
95-
loggedMessages[0].message,
96-
`Setting tools: ${url} based on workflow input.`,
97-
);
98-
});
99-
100-
test("resolveToolsInput returns repository property with 'latest' value", (t) => {
101-
const loggedMessages: LoggedMessage[] = [];
102-
const logger = getRecordingLogger(loggedMessages);
103-
104-
const repositoryProperties: RepositoryProperties = {
105-
[RepositoryPropertyName.TOOLS]: "latest",
106-
};
107-
const result = resolveToolsInput(undefined, repositoryProperties, logger);
108-
109-
t.is(result, "latest");
110-
t.is(
111-
loggedMessages[0].message,
112-
"Setting tools: latest based on the 'github-codeql-tools' repository property.",
113-
);
114-
});
115-
116-
test("resolveToolsInput returns repository property with specific version", (t) => {
85+
test("resolveToolsInput returns undefined when repository property is undefined", (t) => {
11786
const loggedMessages: LoggedMessage[] = [];
11887
const logger = getRecordingLogger(loggedMessages);
11988

12089
const repositoryProperties: RepositoryProperties = {
121-
[RepositoryPropertyName.TOOLS]: "2.16.1",
90+
[RepositoryPropertyName.TOOLS]: undefined,
12291
};
123-
const result = resolveToolsInput(undefined, repositoryProperties, logger);
92+
const result = resolveToolsInput(undefined, true, repositoryProperties, logger);
12493

125-
t.is(result, "2.16.1");
126-
t.is(
127-
loggedMessages[0].message,
128-
"Setting tools: 2.16.1 based on the 'github-codeql-tools' repository property.",
129-
);
94+
t.is(result, undefined);
95+
t.is(loggedMessages.length, 0);
13096
});
13197

132-
test("resolveToolsInput returns undefined when repository property is undefined", (t) => {
98+
test("resolveToolsInput ignores repository property when fallback is disabled", (t) => {
13399
const loggedMessages: LoggedMessage[] = [];
134100
const logger = getRecordingLogger(loggedMessages);
135101

136102
const repositoryProperties: RepositoryProperties = {
137-
[RepositoryPropertyName.TOOLS]: undefined,
103+
[RepositoryPropertyName.TOOLS]: "toolcache",
138104
};
139-
const result = resolveToolsInput(undefined, repositoryProperties, logger);
105+
const result = resolveToolsInput(undefined, false, repositoryProperties, logger);
140106

141107
t.is(result, undefined);
142-
t.is(loggedMessages.length, 0);
108+
t.is(loggedMessages.length, 1);
109+
const fallbackDisabledMessage = String(loggedMessages[0].message);
110+
t.true(
111+
/Ignoring 'github-codeql-tools' repository property because it is only supported for (dynamic workflows|default setup)\./.test(
112+
fallbackDisabledMessage,
113+
),
114+
);
143115
});

src/resolve-tools-input.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@ import { Logger } from "./logging";
77
/**
88
* Resolves the effective tools input by combining the workflow input and repository properties.
99
* The explicit `tools` workflow input takes precedence. If none is provided,
10-
* falls back to the repository property (if set).
10+
* falls back to the repository property (if set and enabled for this workflow).
1111
*
1212
* @param toolsWorkflowInput - The value of the `tools` workflow input, if provided.
13+
* @param allowRepositoryPropertyFallback - Whether the repository property fallback is enabled.
1314
* @param repositoryProperties - The parsed repository properties.
1415
* @param logger - Logger for outputting resolution messages.
1516
* @returns The effective tools input value.
1617
*/
1718
export function resolveToolsInput(
1819
toolsWorkflowInput: string | undefined,
20+
allowRepositoryPropertyFallback: boolean,
1921
repositoryProperties: RepositoryProperties,
2022
logger: Logger,
2123
): string | undefined {
@@ -26,6 +28,13 @@ export function resolveToolsInput(
2628
return toolsWorkflowInput;
2729
}
2830

31+
if (!allowRepositoryPropertyFallback) {
32+
logger.info(
33+
`No explicit tools input was provided. Ignoring '${RepositoryPropertyName.TOOLS}' repository property because it is only supported for dynamic workflows.`,
34+
);
35+
return undefined;
36+
}
37+
2938
const toolsPropertyValue = repositoryProperties[RepositoryPropertyName.TOOLS];
3039
if (toolsPropertyValue) {
3140
logger.info(

src/setup-codeql-action.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as core from "@actions/core";
22
import { v4 as uuidV4 } from "uuid";
33

44
import {
5+
isDynamicWorkflow,
56
getActionVersion,
67
getOptionalInput,
78
getRequiredInput,
@@ -156,9 +157,10 @@ async function run(startedAt: Date): Promise<void> {
156157

157158
// Determine the effective tools input.
158159
// The explicit `tools` workflow input takes precedence. If none is provided,
159-
// fall back to the 'github-codeql-tools' repository property (if set).
160+
// fall back to the 'github-codeql-tools' repository property (if set) only for dynamic workflows.
160161
effectiveToolsInput = resolveToolsInput(
161162
getOptionalInput("tools"),
163+
isDynamicWorkflow(),
162164
repositoryProperties,
163165
logger,
164166
);

0 commit comments

Comments
 (0)