Skip to content

Commit 020856c

Browse files
committed
Address comments on the PR
1 parent e74c1ee commit 020856c

File tree

8 files changed

+121
-60
lines changed

8 files changed

+121
-60
lines changed

src/actions-util.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,35 @@ export const getOptionalInput = function (name: string): string | undefined {
4646
return value.length > 0 ? value : undefined;
4747
};
4848

49+
/**
50+
* Resolves the effective tools input by combining workflow input and repository properties.
51+
* The explicit `tools` workflow input takes precedence. If none is provided,
52+
* fall back to the repository property (if set).
53+
*
54+
* @param repositoryProperties - The loaded repository properties object
55+
* @param toolsPropertyName - The name of the tools property to look up
56+
* @returns An object containing the effective tools input and whether it came from repository property
57+
*/
58+
export function resolveToolsInput(
59+
repositoryProperties: Record<string, any>,
60+
toolsPropertyName: string,
61+
): {
62+
effectiveToolsInput: string | undefined;
63+
toolsInputFromRepositoryProperty: boolean;
64+
} {
65+
const toolsWorkflowInput = getOptionalInput("tools");
66+
const toolsPropertyValue: string | undefined =
67+
repositoryProperties[toolsPropertyName];
68+
const effectiveToolsInput = toolsWorkflowInput ?? toolsPropertyValue;
69+
const toolsInputFromRepositoryProperty =
70+
toolsWorkflowInput === undefined && toolsPropertyValue !== undefined;
71+
72+
return {
73+
effectiveToolsInput,
74+
toolsInputFromRepositoryProperty,
75+
};
76+
}
77+
4978
export function getTemporaryDirectory(): string {
5079
const value = process.env["CODEQL_ACTION_TEMP"];
5180
return value !== undefined && value !== ""

src/codeql.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ export async function setupCodeQL(
323323
features: FeatureEnablement,
324324
logger: Logger,
325325
checkVersion: boolean,
326-
toolsInputFromRepositoryProperty = false,
326+
toolsInputFromRepositoryProperty: boolean,
327327
): Promise<{
328328
codeql: CodeQL;
329329
toolsDownloadStatusReport?: ToolsDownloadStatusReport;

src/feature-flags/properties.test.ts

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ test.serial("loadPropertiesFromApi loads known properties", async (t) => {
7878
url: "",
7979
data: [
8080
{ property_name: "github-codeql-extra-queries", value: "+queries" },
81+
{ property_name: "github-codeql-tools", value: "toolcache" },
8182
{ property_name: "unknown-property", value: "something" },
8283
] satisfies properties.GitHubPropertiesResponse,
8384
});
@@ -87,30 +88,12 @@ test.serial("loadPropertiesFromApi loads known properties", async (t) => {
8788
logger,
8889
mockRepositoryNwo,
8990
);
90-
t.deepEqual(response, { "github-codeql-extra-queries": "+queries" });
91+
t.deepEqual(response, {
92+
"github-codeql-extra-queries": "+queries",
93+
"github-codeql-tools": "toolcache",
94+
});
9195
});
9296

93-
test.serial(
94-
"loadPropertiesFromApi loads github-codeql-tools property",
95-
async (t) => {
96-
sinon.stub(api, "getRepositoryProperties").resolves({
97-
headers: {},
98-
status: 200,
99-
url: "",
100-
data: [
101-
{ property_name: "github-codeql-tools", value: "toolcache" },
102-
] satisfies properties.GitHubPropertiesResponse,
103-
});
104-
const logger = getRunnerLogger(true);
105-
const mockRepositoryNwo = parseRepositoryNwo("owner/repo");
106-
const response = await properties.loadPropertiesFromApi(
107-
logger,
108-
mockRepositoryNwo,
109-
);
110-
t.deepEqual(response, { "github-codeql-tools": "toolcache" });
111-
},
112-
);
113-
11497
test.serial("loadPropertiesFromApi parses true boolean property", async (t) => {
11598
sinon.stub(api, "getRepositoryProperties").resolves({
11699
headers: {},

src/init-action.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
getRequiredInput,
1616
getTemporaryDirectory,
1717
persistInputs,
18+
resolveToolsInput,
1819
} from "./actions-util";
1920
import { AnalysisKind, getAnalysisKinds } from "./analyses";
2021
import { getGitHubVersion, GitHubApiCombinedDetails } from "./api-client";
@@ -141,6 +142,7 @@ async function sendCompletedStatusReport(
141142
toolsFeatureFlagsValid: boolean | undefined,
142143
toolsSource: ToolsSource,
143144
toolsVersion: string,
145+
effectiveToolsInput: string | undefined,
144146
overlayBaseDatabaseStats: OverlayBaseDatabaseDownloadStats | undefined,
145147
dependencyCachingResults: DependencyCacheRestoreStatusReport | undefined,
146148
logger: Logger,
@@ -165,7 +167,7 @@ async function sendCompletedStatusReport(
165167

166168
const initStatusReport: InitStatusReport = {
167169
...statusReportBase,
168-
tools_input: getOptionalInput("tools") || "",
170+
tools_input: effectiveToolsInput || "",
169171
tools_resolved_version: toolsVersion,
170172
tools_source: toolsSource || ToolsSource.Unknown,
171173
workflow_languages: workflowLanguages || "",
@@ -220,6 +222,7 @@ async function run(startedAt: Date) {
220222
let toolsSource: ToolsSource;
221223
let toolsVersion: string;
222224
let zstdAvailability: ZstdAvailability | undefined;
225+
let effectiveToolsInput: string | undefined;
223226

224227
try {
225228
initializeEnvironment(getActionVersion());
@@ -302,12 +305,13 @@ async function run(startedAt: Date) {
302305
// Determine the effective tools input.
303306
// The explicit `tools` workflow input takes precedence. If none is provided,
304307
// fall back to the 'github-codeql-tools' repository property (if set).
305-
const toolsWorkflowInput = getOptionalInput("tools");
306-
const toolsPropertyValue: string | undefined =
307-
repositoryPropertiesResult.orElse({})[RepositoryPropertyName.TOOLS];
308-
const effectiveToolsInput = toolsWorkflowInput ?? toolsPropertyValue;
308+
const resolvedToolsInput = resolveToolsInput(
309+
repositoryPropertiesResult.orElse({}),
310+
RepositoryPropertyName.TOOLS,
311+
);
312+
effectiveToolsInput = resolvedToolsInput.effectiveToolsInput;
309313
const toolsInputFromRepositoryProperty =
310-
toolsWorkflowInput === undefined && toolsPropertyValue !== undefined;
314+
resolvedToolsInput.toolsInputFromRepositoryProperty;
311315

312316
const initCodeQLResult = await initCodeQL(
313317
effectiveToolsInput,
@@ -791,6 +795,7 @@ async function run(startedAt: Date) {
791795
toolsFeatureFlagsValid,
792796
toolsSource,
793797
toolsVersion,
798+
effectiveToolsInput,
794799
overlayBaseDatabaseStats,
795800
dependencyCachingStatus,
796801
logger,
@@ -808,6 +813,7 @@ async function run(startedAt: Date) {
808813
toolsFeatureFlagsValid,
809814
toolsSource,
810815
toolsVersion,
816+
effectiveToolsInput,
811817
overlayBaseDatabaseStats,
812818
dependencyCachingStatus,
813819
logger,

src/init.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export async function initCodeQL(
4141
defaultCliVersion: CodeQLDefaultVersionInfo,
4242
features: FeatureEnablement,
4343
logger: Logger,
44-
toolsInputFromRepositoryProperty = false,
44+
toolsInputFromRepositoryProperty: boolean,
4545
): Promise<{
4646
codeql: CodeQL;
4747
toolsDownloadStatusReport?: ToolsDownloadStatusReport;

src/setup-codeql-action.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,16 @@ import {
66
getOptionalInput,
77
getRequiredInput,
88
getTemporaryDirectory,
9+
resolveToolsInput,
910
} from "./actions-util";
1011
import { getGitHubVersion } from "./api-client";
1112
import { CodeQL } from "./codeql";
1213
import { EnvVar } from "./environment";
1314
import { initFeatures } from "./feature-flags";
15+
import {
16+
loadPropertiesFromApi,
17+
RepositoryPropertyName,
18+
} from "./feature-flags/properties";
1419
import { initCodeQL } from "./init";
1520
import { getActionsLogger, Logger } from "./logging";
1621
import { getRepositoryNwo } from "./repository";
@@ -46,6 +51,7 @@ async function sendCompletedStatusReport(
4651
toolsFeatureFlagsValid: boolean | undefined,
4752
toolsSource: ToolsSource,
4853
toolsVersion: string,
54+
effectiveToolsInput: string | undefined,
4955
logger: Logger,
5056
error?: Error,
5157
): Promise<void> {
@@ -66,7 +72,7 @@ async function sendCompletedStatusReport(
6672

6773
const initStatusReport: InitStatusReport = {
6874
...statusReportBase,
69-
tools_input: getOptionalInput("tools") || "",
75+
tools_input: effectiveToolsInput || "",
7076
tools_resolved_version: toolsVersion,
7177
tools_source: toolsSource || ToolsSource.Unknown,
7278
workflow_languages: "",
@@ -97,6 +103,7 @@ async function run(startedAt: Date): Promise<void> {
97103
let toolsFeatureFlagsValid: boolean | undefined;
98104
let toolsSource: ToolsSource;
99105
let toolsVersion: string;
106+
let effectiveToolsInput: string | undefined;
100107

101108
try {
102109
initializeEnvironment(getActionVersion());
@@ -121,6 +128,11 @@ async function run(startedAt: Date): Promise<void> {
121128
logger,
122129
);
123130

131+
const repositoryPropertiesResult = await loadPropertiesFromApi(
132+
logger,
133+
repositoryNwo,
134+
);
135+
124136
const jobRunUuid = uuidV4();
125137
logger.info(`Job run UUID is ${jobRunUuid}.`);
126138
core.exportVariable(EnvVar.JOB_RUN_UUID, jobRunUuid);
@@ -140,14 +152,27 @@ async function run(startedAt: Date): Promise<void> {
140152
gitHubVersion.type,
141153
);
142154
toolsFeatureFlagsValid = codeQLDefaultVersionInfo.toolsFeatureFlagsValid;
155+
156+
// Determine the effective tools input.
157+
// The explicit `tools` workflow input takes precedence. If none is provided,
158+
// fall back to the 'github-codeql-tools' repository property (if set).
159+
const resolvedToolsInput = resolveToolsInput(
160+
repositoryPropertiesResult,
161+
RepositoryPropertyName.TOOLS,
162+
);
163+
effectiveToolsInput = resolvedToolsInput.effectiveToolsInput;
164+
const toolsInputFromRepositoryProperty =
165+
resolvedToolsInput.toolsInputFromRepositoryProperty;
166+
143167
const initCodeQLResult = await initCodeQL(
144-
getOptionalInput("tools"),
168+
effectiveToolsInput,
145169
apiDetails,
146170
getTemporaryDirectory(),
147171
gitHubVersion.type,
148172
codeQLDefaultVersionInfo,
149173
features,
150174
logger,
175+
toolsInputFromRepositoryProperty,
151176
);
152177
codeql = initCodeQLResult.codeql;
153178
toolsDownloadStatusReport = initCodeQLResult.toolsDownloadStatusReport;
@@ -183,6 +208,7 @@ async function run(startedAt: Date): Promise<void> {
183208
toolsFeatureFlagsValid,
184209
toolsSource,
185210
toolsVersion,
211+
effectiveToolsInput,
186212
logger,
187213
);
188214
}

src/setup-codeql.test.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import * as sinon from "sinon";
88
import * as actionsUtil from "./actions-util";
99
import * as api from "./api-client";
1010
import { Feature, FeatureEnablement } from "./feature-flags";
11+
import { RepositoryPropertyName } from "./feature-flags/properties";
1112
import { getRunnerLogger } from "./logging";
1213
import * as setupCodeql from "./setup-codeql";
1314
import * as tar from "./tar";
@@ -112,6 +113,7 @@ test.serial(
112113
false,
113114
features,
114115
getRunnerLogger(true),
116+
false,
115117
);
116118

117119
t.is(source.sourceType, "download");
@@ -135,6 +137,7 @@ test.serial(
135137
false,
136138
features,
137139
getRunnerLogger(true),
140+
false,
138141
);
139142

140143
t.is(source.toolsVersion, LINKED_CLI_VERSION.cliVersion);
@@ -160,6 +163,7 @@ test.serial(
160163
false,
161164
features,
162165
logger,
166+
false,
163167
);
164168

165169
// First, ensure that the CLI version is the linked version, so that backwards
@@ -213,6 +217,7 @@ test.serial(
213217
SAMPLE_DEFAULT_CLI_VERSION,
214218
features,
215219
logger,
220+
false,
216221
);
217222

218223
// Basic sanity check that the version we got back is indeed
@@ -268,6 +273,7 @@ test.serial(
268273
SAMPLE_DEFAULT_CLI_VERSION,
269274
features,
270275
logger,
276+
false,
271277
);
272278

273279
// Basic sanity check that the version we got back is indeed the version that the
@@ -322,6 +328,7 @@ test.serial(
322328
false,
323329
features,
324330
logger,
331+
false,
325332
);
326333

327334
// Check that the `CodeQLToolsSource` object matches our expectations.
@@ -383,6 +390,7 @@ test.serial(
383390
false,
384391
features,
385392
logger,
393+
false,
386394
);
387395

388396
// Check that the `CodeQLToolsSource` object matches our expectations.
@@ -437,6 +445,7 @@ test.serial(
437445
false,
438446
features,
439447
logger,
448+
false,
440449
);
441450

442451
// Check that the toolcache functions were called with the expected arguments
@@ -504,6 +513,7 @@ const toolcacheInputFallbackMacro = test.macro({
504513
false,
505514
features,
506515
logger,
516+
false,
507517
);
508518

509519
// Check that the toolcache functions were called with the expected arguments
@@ -612,7 +622,7 @@ test.serial(
612622
t.is(source.toolsVersion, latestToolcacheVersion);
613623

614624
const expectedMessages: string[] = [
615-
`Attempting to use the latest CodeQL CLI version in the toolcache, as requested by the 'github-codeql-tools' repository property.`,
625+
`Attempting to use the latest CodeQL CLI version in the toolcache, as requested by the '${RepositoryPropertyName.TOOLS}' repository property.`,
616626
`CLI version ${latestToolcacheVersion} is the latest version in the toolcache.`,
617627
`Using CodeQL CLI version ${latestToolcacheVersion} from toolcache at ${latestVersionPath}`,
618628
];
@@ -657,8 +667,8 @@ test.serial(
657667
t.is(source.toolsVersion, SAMPLE_DEFAULT_CLI_VERSION.cliVersion);
658668

659669
const expectedMessages: string[] = [
660-
`Attempting to use the latest CodeQL CLI version in the toolcache, as requested by the 'github-codeql-tools' repository property.`,
661-
`Found no CodeQL CLI in the toolcache, ignoring the 'github-codeql-tools' repository property...`,
670+
`Attempting to use the latest CodeQL CLI version in the toolcache, as requested by the '${RepositoryPropertyName.TOOLS}' repository property.`,
671+
`Found no CodeQL CLI in the toolcache, ignoring the '${RepositoryPropertyName.TOOLS}' repository property...`,
662672
];
663673
for (const expectedMessage of expectedMessages) {
664674
t.assert(

0 commit comments

Comments
 (0)