Skip to content

Commit c5a2f4b

Browse files
authored
Merge pull request #4245 from github/henrymercer/graduate-overlay-trap-caching
Graduate overlay TRAP caching defaults
2 parents 61a5a80 + e344c79 commit c5a2f4b

5 files changed

Lines changed: 44 additions & 75 deletions

File tree

‎init/action.yml‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,10 @@ inputs:
153153
required: false
154154
trap-caching:
155155
description: >-
156-
Explicitly enable or disable TRAP caching rather than respecting the feature flag for it.
156+
Explicitly enable or disable TRAP caching instead of using the automatically determined default.
157+
TRAP caching is disabled by default when improved incremental analysis is enabled,
158+
because improved incremental analysis of a pull request only extracts changed files,
159+
which rarely benefit from TRAP caching.
157160
required: false
158161
dependency-caching:
159162
description: >-

‎lib/entry-points.js‎

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

‎src/config-utils.test.ts‎

Lines changed: 27 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2126,85 +2126,68 @@ test.serial("getPrimaryAnalysisConfig - Code Scanning + Code Quality", (t) => {
21262126
});
21272127

21282128
test.serial(
2129-
"isTrapCachingEnabled: explicit input true is respected",
2129+
"isTrapCachingEnabled: explicit true input overrides self-hosted default",
21302130
async (t) => {
21312131
return await withTmpDir(async (tmpDir) => {
21322132
setupActionsVars(tmpDir, tmpDir);
21332133
sinon
21342134
.stub(actionsUtil, "getOptionalInput")
21352135
.withArgs("trap-caching")
21362136
.returns("true");
2137-
t.true(
2138-
await configUtils.isTrapCachingEnabled(
2139-
createFeatures([]),
2140-
OverlayDatabaseMode.None,
2141-
),
2142-
);
2137+
t.true(configUtils.isTrapCachingEnabled(OverlayDatabaseMode.None));
21432138
});
21442139
},
21452140
);
21462141

21472142
test.serial(
2148-
"isTrapCachingEnabled: disabled on self-hosted runner by default",
2143+
"isTrapCachingEnabled: explicit true input overrides overlay defaults",
21492144
async (t) => {
21502145
return await withTmpDir(async (tmpDir) => {
2151-
setupActionsVars(tmpDir, tmpDir);
2146+
setupActionsVars(tmpDir, path.join(tmpDir, "hostedtoolcache"));
21522147
sinon
21532148
.stub(actionsUtil, "getOptionalInput")
21542149
.withArgs("trap-caching")
2155-
.returns(undefined);
2156-
t.false(
2157-
await configUtils.isTrapCachingEnabled(
2158-
createFeatures([]),
2159-
OverlayDatabaseMode.None,
2160-
),
2161-
);
2150+
.returns("true");
2151+
for (const overlayDatabaseMode of [
2152+
OverlayDatabaseMode.Overlay,
2153+
OverlayDatabaseMode.OverlayBase,
2154+
]) {
2155+
t.true(configUtils.isTrapCachingEnabled(overlayDatabaseMode));
2156+
}
21622157
});
21632158
},
21642159
);
21652160

21662161
test.serial(
2167-
"isTrapCachingEnabled: enabled on hosted runner by default",
2162+
"isTrapCachingEnabled: explicit false input overrides hosted default",
21682163
async (t) => {
21692164
return await withTmpDir(async (tmpDir) => {
2170-
const hostedToolCache = path.join(tmpDir, "hostedtoolcache");
2171-
setupActionsVars(tmpDir, hostedToolCache);
2165+
setupActionsVars(tmpDir, path.join(tmpDir, "hostedtoolcache"));
21722166
sinon
21732167
.stub(actionsUtil, "getOptionalInput")
21742168
.withArgs("trap-caching")
2175-
.returns(undefined);
2176-
t.true(
2177-
await configUtils.isTrapCachingEnabled(
2178-
createFeatures([]),
2179-
OverlayDatabaseMode.None,
2180-
),
2181-
);
2169+
.returns("false");
2170+
t.false(configUtils.isTrapCachingEnabled(OverlayDatabaseMode.None));
21822171
});
21832172
},
21842173
);
21852174

21862175
test.serial(
2187-
"isTrapCachingEnabled: enabled on hosted runner when overlay enabled but feature flag off",
2176+
"isTrapCachingEnabled: disabled on self-hosted runner by default",
21882177
async (t) => {
21892178
return await withTmpDir(async (tmpDir) => {
2190-
const hostedToolCache = path.join(tmpDir, "hostedtoolcache");
2191-
setupActionsVars(tmpDir, hostedToolCache);
2179+
setupActionsVars(tmpDir, tmpDir);
21922180
sinon
21932181
.stub(actionsUtil, "getOptionalInput")
21942182
.withArgs("trap-caching")
21952183
.returns(undefined);
2196-
t.true(
2197-
await configUtils.isTrapCachingEnabled(
2198-
createFeatures([]),
2199-
OverlayDatabaseMode.Overlay,
2200-
),
2201-
);
2184+
t.false(configUtils.isTrapCachingEnabled(OverlayDatabaseMode.None));
22022185
});
22032186
},
22042187
);
22052188

22062189
test.serial(
2207-
"isTrapCachingEnabled: disabled on hosted runner when overlay enabled and feature flag on",
2190+
"isTrapCachingEnabled: enabled on hosted runner without overlay analysis",
22082191
async (t) => {
22092192
return await withTmpDir(async (tmpDir) => {
22102193
const hostedToolCache = path.join(tmpDir, "hostedtoolcache");
@@ -2213,18 +2196,13 @@ test.serial(
22132196
.stub(actionsUtil, "getOptionalInput")
22142197
.withArgs("trap-caching")
22152198
.returns(undefined);
2216-
t.false(
2217-
await configUtils.isTrapCachingEnabled(
2218-
createFeatures([Feature.OverlayAnalysisDisableTrapCaching]),
2219-
OverlayDatabaseMode.Overlay,
2220-
),
2221-
);
2199+
t.true(configUtils.isTrapCachingEnabled(OverlayDatabaseMode.None));
22222200
});
22232201
},
22242202
);
22252203

22262204
test.serial(
2227-
"isTrapCachingEnabled: enabled on hosted runner when overlay is None even with feature flag on",
2205+
"isTrapCachingEnabled: disabled on hosted runner with overlay analysis",
22282206
async (t) => {
22292207
return await withTmpDir(async (tmpDir) => {
22302208
const hostedToolCache = path.join(tmpDir, "hostedtoolcache");
@@ -2233,12 +2211,12 @@ test.serial(
22332211
.stub(actionsUtil, "getOptionalInput")
22342212
.withArgs("trap-caching")
22352213
.returns(undefined);
2236-
t.true(
2237-
await configUtils.isTrapCachingEnabled(
2238-
createFeatures([Feature.OverlayAnalysisDisableTrapCaching]),
2239-
OverlayDatabaseMode.None,
2240-
),
2241-
);
2214+
for (const overlayDatabaseMode of [
2215+
OverlayDatabaseMode.Overlay,
2216+
OverlayDatabaseMode.OverlayBase,
2217+
]) {
2218+
t.false(configUtils.isTrapCachingEnabled(overlayDatabaseMode));
2219+
}
22422220
});
22432221
},
22442222
);

‎src/config-utils.ts‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -944,23 +944,23 @@ async function validateOverlayDatabaseMode(
944944
});
945945
}
946946

947-
export async function isTrapCachingEnabled(
948-
features: FeatureEnablement,
947+
/**
948+
* Determines whether TRAP caching is enabled for the current run.
949+
*
950+
* @returns Whether TRAP caches should be downloaded and uploaded.
951+
*/
952+
export function isTrapCachingEnabled(
949953
overlayDatabaseMode: OverlayDatabaseMode,
950-
): Promise<boolean> {
954+
): boolean {
951955
// If the workflow specified something, always respect that.
952956
const trapCaching = getOptionalInput("trap-caching");
953957
if (trapCaching !== undefined) return trapCaching === "true";
954958

955959
// On self-hosted runners which may have slow network access, disable TRAP caching by default.
956960
if (!looksLikeHostedRunner()) return false;
957961

958-
// If overlay analysis is enabled, then disable TRAP caching since overlay analysis supersedes it.
959-
// This change is gated behind a feature flag.
960-
if (
961-
overlayDatabaseMode !== OverlayDatabaseMode.None &&
962-
(await features.getValue(Feature.OverlayAnalysisDisableTrapCaching))
963-
) {
962+
// Overlay analysis supersedes TRAP caching, so disable TRAP caching by default when it is active.
963+
if (overlayDatabaseMode !== OverlayDatabaseMode.None) {
964964
return false;
965965
}
966966

@@ -1302,7 +1302,7 @@ export async function initConfig(
13021302
logger,
13031303
);
13041304

1305-
if (await isTrapCachingEnabled(features, config.overlayDatabaseMode)) {
1305+
if (isTrapCachingEnabled(config.overlayDatabaseMode)) {
13061306
const { trapCaches, trapCacheDownloadTime } = await downloadCacheWithTime(
13071307
inputs.codeql,
13081308
config.languages,

‎src/feature-flags.ts‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,6 @@ export enum Feature {
103103
OverlayAnalysisCodeScanningRuby = "overlay_analysis_code_scanning_ruby",
104104
OverlayAnalysisCpp = "overlay_analysis_cpp",
105105
OverlayAnalysisCsharp = "overlay_analysis_csharp",
106-
/** Disable TRAP caching when overlay analysis is enabled. */
107-
OverlayAnalysisDisableTrapCaching = "overlay_analysis_disable_trap_caching",
108106
OverlayAnalysisGo = "overlay_analysis_go",
109107
OverlayAnalysisJava = "overlay_analysis_java",
110108
OverlayAnalysisJavascript = "overlay_analysis_javascript",
@@ -369,11 +367,6 @@ export const featureConfig = {
369367
minimumVersion: CODEQL_OVERLAY_MINIMUM_VERSION_RUBY,
370368
},
371369
// Other overlay-related feature flags
372-
[Feature.OverlayAnalysisDisableTrapCaching]: {
373-
defaultValue: false,
374-
envVar: "CODEQL_ACTION_OVERLAY_ANALYSIS_DISABLE_TRAP_CACHING",
375-
minimumVersion: undefined,
376-
},
377370
[Feature.OverlayAnalysisMatchCodeqlVersion]: {
378371
defaultValue: false,
379372
envVar: "CODEQL_ACTION_OVERLAY_ANALYSIS_MATCH_CODEQL_VERSION",

0 commit comments

Comments
 (0)