Skip to content

Commit 6963dfb

Browse files
committed
Add logging and telemetry for mode
1 parent d426d33 commit 6963dfb

7 files changed

Lines changed: 265 additions & 27 deletions

File tree

lib/entry-points.js

Lines changed: 46 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/config/resolve-tools-input.test.ts

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import test from "ava";
22

3-
import { resolveToolsInput } from "../config/resolve-tools-input";
3+
import {
4+
EffectiveToolsInputSource,
5+
resolveToolsInput,
6+
resolveToolsInputWithMetadata,
7+
} from "../config/resolve-tools-input";
48
import {
59
RepositoryPropertyName,
610
ToolsModeRepositoryPropertyValue,
@@ -56,7 +60,7 @@ test("resolveToolsInput returns repository property when only repository propert
5660
t.is(loggedMessages.length, 1);
5761
t.is(
5862
loggedMessages[0].message,
59-
"Setting tools: toolcache based on the 'github-codeql-tools' repository property.",
63+
"Setting tools: toolcache based on the 'github-codeql-tools' repository property (mode: 'enforce').",
6064
);
6165
});
6266

@@ -95,7 +99,7 @@ test("resolveToolsInput treats empty string workflow input as not set", (t) => {
9599
t.is(loggedMessages.length, 1);
96100
t.is(
97101
loggedMessages[0].message,
98-
"Setting tools: toolcache based on the 'github-codeql-tools' repository property.",
102+
"Setting tools: toolcache based on the 'github-codeql-tools' repository property (mode: 'enforce').",
99103
);
100104
});
101105

@@ -135,7 +139,7 @@ test("resolveToolsInput returns repository property when workflow input is not s
135139
t.is(loggedMessages.length, 1);
136140
t.is(
137141
loggedMessages[0].message,
138-
"Setting tools: toolcache based on the 'github-codeql-tools' repository property.",
142+
"Setting tools: toolcache based on the 'github-codeql-tools' repository property (mode: 'enforce').",
139143
);
140144
});
141145

@@ -169,7 +173,7 @@ test("resolveToolsInput applies tools property in enforce mode for static workfl
169173
t.is(loggedMessages.length, 1);
170174
t.is(
171175
loggedMessages[0].message,
172-
"Setting tools: toolcache based on the 'github-codeql-tools' repository property.",
176+
"Setting tools: toolcache based on the 'github-codeql-tools' repository property (mode: 'enforce').",
173177
);
174178
});
175179

@@ -188,7 +192,7 @@ test("resolveToolsInput applies tools property in dynamic mode for dynamic workf
188192
t.is(loggedMessages.length, 1);
189193
t.is(
190194
loggedMessages[0].message,
191-
"Setting tools: toolcache based on the 'github-codeql-tools' repository property.",
195+
"Setting tools: toolcache based on the 'github-codeql-tools' repository property (mode: 'dynamic').",
192196
);
193197
});
194198

@@ -215,3 +219,54 @@ test("resolveToolsInput ignores tools property in dynamic mode for static workfl
215219
"Ignoring 'github-codeql-tools' repository property because 'github-codeql-tools-mode' is set to 'dynamic' and this is not a dynamic workflow.",
216220
);
217221
});
222+
223+
test("resolveToolsInputWithMetadata reports workflow input source", (t) => {
224+
const logger = getRecordingLogger([]);
225+
226+
const result = resolveToolsInputWithMetadata("latest", false, {}, logger);
227+
228+
t.is(result.effectiveToolsInput, "latest");
229+
t.is(result.effectiveToolsInputSource, EffectiveToolsInputSource.WorkflowInput);
230+
t.is(result.toolsRepoPropertyMode, undefined);
231+
});
232+
233+
test("resolveToolsInputWithMetadata reports repository property source and mode", (t) => {
234+
const logger = getRecordingLogger([]);
235+
236+
const result = resolveToolsInputWithMetadata(
237+
undefined,
238+
false,
239+
{
240+
[RepositoryPropertyName.TOOLS]: "toolcache",
241+
[RepositoryPropertyName.TOOLS_MODE]:
242+
ToolsModeRepositoryPropertyValue.Enforce,
243+
},
244+
logger,
245+
);
246+
247+
t.is(result.effectiveToolsInput, "toolcache");
248+
t.is(
249+
result.effectiveToolsInputSource,
250+
EffectiveToolsInputSource.RepositoryProperty,
251+
);
252+
t.is(result.toolsRepoPropertyMode, ToolsModeRepositoryPropertyValue.Enforce);
253+
});
254+
255+
test("resolveToolsInputWithMetadata reports dynamic-mode skip on static workflows", (t) => {
256+
const logger = getRecordingLogger([]);
257+
258+
const result = resolveToolsInputWithMetadata(
259+
undefined,
260+
false,
261+
{
262+
[RepositoryPropertyName.TOOLS]: "toolcache",
263+
[RepositoryPropertyName.TOOLS_MODE]:
264+
ToolsModeRepositoryPropertyValue.Dynamic,
265+
},
266+
logger,
267+
);
268+
269+
t.is(result.effectiveToolsInput, undefined);
270+
t.is(result.effectiveToolsInputSource, EffectiveToolsInputSource.None);
271+
t.is(result.toolsRepoPropertyMode, ToolsModeRepositoryPropertyValue.Dynamic);
272+
});

src/config/resolve-tools-input.ts

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@ import {
55
} from "../feature-flags/properties";
66
import { Logger } from "../logging";
77

8+
export enum EffectiveToolsInputSource {
9+
WorkflowInput = "workflow-input",
10+
RepositoryProperty = "repository-property",
11+
None = "none",
12+
}
13+
14+
export type ResolvedToolsInput = {
15+
effectiveToolsInput: string | undefined;
16+
effectiveToolsInputSource: EffectiveToolsInputSource;
17+
toolsRepoPropertyMode: ToolsModeRepositoryPropertyValue | undefined;
18+
};
19+
820
/**
921
* Resolves the effective tools input by combining the workflow input and repository properties.
1022
* The explicit `tools` workflow input takes precedence. If none is provided,
@@ -24,11 +36,29 @@ export function resolveToolsInput(
2436
repositoryProperties: RepositoryProperties,
2537
logger: Logger,
2638
): string | undefined {
39+
return resolveToolsInputWithMetadata(
40+
toolsWorkflowInput,
41+
isDynamicWorkflow,
42+
repositoryProperties,
43+
logger,
44+
).effectiveToolsInput;
45+
}
46+
47+
export function resolveToolsInputWithMetadata(
48+
toolsWorkflowInput: string | undefined,
49+
isDynamicWorkflow: boolean,
50+
repositoryProperties: RepositoryProperties,
51+
logger: Logger,
52+
): ResolvedToolsInput {
2753
if (toolsWorkflowInput) {
2854
logger.info(
2955
`Setting tools: ${toolsWorkflowInput} based on workflow input.`,
3056
);
31-
return toolsWorkflowInput;
57+
return {
58+
effectiveToolsInput: toolsWorkflowInput,
59+
effectiveToolsInputSource: EffectiveToolsInputSource.WorkflowInput,
60+
toolsRepoPropertyMode: undefined,
61+
};
3262
}
3363

3464
const toolsPropertyValue = repositoryProperties[RepositoryPropertyName.TOOLS];
@@ -44,15 +74,27 @@ export function resolveToolsInput(
4474
logger.info(
4575
`Ignoring '${RepositoryPropertyName.TOOLS}' repository property because '${RepositoryPropertyName.TOOLS_MODE}' is set to '${toolsMode}' and this is not a dynamic workflow.`,
4676
);
47-
return undefined;
77+
return {
78+
effectiveToolsInput: undefined,
79+
effectiveToolsInputSource: EffectiveToolsInputSource.None,
80+
toolsRepoPropertyMode: toolsMode,
81+
};
4882
}
4983

5084
if (toolsPropertyValue) {
5185
logger.info(
52-
`Setting tools: ${toolsPropertyValue} based on the '${RepositoryPropertyName.TOOLS}' repository property.`,
86+
`Setting tools: ${toolsPropertyValue} based on the '${RepositoryPropertyName.TOOLS}' repository property (mode: '${toolsMode}').`,
5387
);
54-
return toolsPropertyValue;
88+
return {
89+
effectiveToolsInput: toolsPropertyValue,
90+
effectiveToolsInputSource: EffectiveToolsInputSource.RepositoryProperty,
91+
toolsRepoPropertyMode: toolsMode,
92+
};
5593
}
5694

57-
return undefined;
95+
return {
96+
effectiveToolsInput: undefined,
97+
effectiveToolsInputSource: EffectiveToolsInputSource.None,
98+
toolsRepoPropertyMode: undefined,
99+
};
58100
}

0 commit comments

Comments
 (0)