Skip to content

Commit 977e6ce

Browse files
authored
Merge pull request #4124 from github/henrymercer/toolcache-bundle-cleanup
Delete unused CodeQL bundles from the toolcache before downloading
2 parents 313a0b9 + 40a6b38 commit 977e6ce

13 files changed

Lines changed: 1367 additions & 394 deletions

.github/workflows/__multi-language-autodetect.yml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CHANGELOG.md

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

55
## [UNRELEASED]
66

7+
- On GitHub-hosted runners, the CodeQL Action now deletes unused CodeQL bundles from the toolcache before downloading a different bundle, which frees up disk space for the analysis. We expect to roll this change out to everyone in September. [#4124](https://github.com/github/codeql-action/pull/4124)
78
- The CodeQL Action now supports CodeQL releases that are compatible with Linux Arm64 and downloads the native `linux-arm64` CodeQL bundle when available. [#4072](https://github.com/github/codeql-action/pull/4072)
89

910
## 4.37.9 - 26 Aug 2026

lib/entry-points.js

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

pr-checks/checks/multi-language-autodetect.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ operatingSystems:
1515
- stable-v2.21.4
1616
- stable-v2.22.4
1717
env:
18+
CODEQL_ACTION_CLEANUP_TOOLCACHE_BUNDLES: true
1819
CODEQL_ACTION_RESOLVE_SUPPORTED_LANGUAGES_USING_CLI: true
1920
installGo: true
2021
installDotNet: true

src/actions-util.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,19 @@ export function isSelfHostedRunner(env: Env = getEnv()) {
283283
return env.getOptional(ActionsEnvVars.RUNNER_ENVIRONMENT) === "self-hosted";
284284
}
285285

286+
/**
287+
* Whether the job is running on a runner that GitHub hosts, and whose toolcache is therefore thrown
288+
* away once the job has finished.
289+
*
290+
* Unlike `looksLikeHostedRunner`, this is based on what the service reports for the job rather than
291+
* on how the runner's filesystem happens to be laid out, so it does not match self-hosted runners
292+
* that are configured to resemble hosted ones, such as those that mount a persistent volume at
293+
* `/opt/hostedtoolcache`.
294+
*/
295+
export function isGitHubHostedRunner(env: Env = getEnv()) {
296+
return env.getOptional(ActionsEnvVars.RUNNER_ENVIRONMENT) === "github-hosted";
297+
}
298+
286299
/** Determines whether the workflow trigger is `dynamic`. */
287300
export function isDynamicWorkflow(env: Env = getEnv()): boolean {
288301
return getWorkflowEventName(env) === "dynamic";

src/caching-utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as core from "@actions/core";
55
import { getOptionalInput, isDefaultSetup } from "./actions-util";
66
import { EnvVar } from "./environment";
77
import { Logger } from "./logging";
8-
import { isHostedRunner, tryGetFolderBytes } from "./util";
8+
import { looksLikeHostedRunner, tryGetFolderBytes } from "./util";
99

1010
/**
1111
* Returns the total size of all the specified paths.
@@ -109,7 +109,7 @@ export function getDependencyCachingEnabled(): CachingKind {
109109
if (dependencyCaching !== undefined) return getCachingKind(dependencyCaching);
110110

111111
// On self-hosted runners which may have dependencies installed centrally, disable caching by default
112-
if (!isHostedRunner()) return CachingKind.None;
112+
if (!looksLikeHostedRunner()) return CachingKind.None;
113113

114114
// Disable in advanced workflows by default.
115115
if (!isDefaultSetup()) return CachingKind.None;

src/config-utils.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,8 @@ import {
9090
Result,
9191
Success,
9292
Failure,
93-
isHostedRunner,
93+
looksLikeHostedRunner,
9494
} from "./util";
95-
9695
export { type Config } from "./config/action-config";
9796

9897
/**
@@ -938,7 +937,7 @@ export async function isTrapCachingEnabled(
938937
if (trapCaching !== undefined) return trapCaching === "true";
939938

940939
// On self-hosted runners which may have slow network access, disable TRAP caching by default.
941-
if (!isHostedRunner()) return false;
940+
if (!looksLikeHostedRunner()) return false;
942941

943942
// If overlay analysis is enabled, then disable TRAP caching since overlay analysis supersedes it.
944943
// This change is gated behind a feature flag.

src/environment.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ export enum EnvVar {
6363
/** Whether the CodeQL Action has already warned the user about low disk space. */
6464
HAS_WARNED_ABOUT_DISK_SPACE = "CODEQL_ACTION_HAS_WARNED_ABOUT_DISK_SPACE",
6565

66+
/**
67+
* Whether a step in this job has already set up CodeQL. Steps that run afterwards may be holding
68+
* a path into the toolcache, so we must not delete anything from it.
69+
*/
70+
HAS_SET_UP_CODEQL = "CODEQL_ACTION_HAS_SET_UP_CODEQL",
71+
6672
/** Whether the `setup-codeql` action has been run. */
6773
SETUP_CODEQL_ACTION_HAS_RUN = "CODEQL_ACTION_SETUP_CODEQL_HAS_RUN",
6874

src/feature-flags.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ export enum Feature {
7474
AllowMergeConfigFiles = "allow_merge_config_files",
7575
/** Controls whether we allow multiple values for the `analysis-kinds` input. */
7676
AllowMultipleAnalysisKinds = "allow_multiple_analysis_kinds",
77+
/**
78+
* Controls whether we delete CodeQL bundles that we are not going to use from the toolcache
79+
* before downloading a different bundle, in order to reclaim disk space.
80+
*/
81+
CleanupToolcacheBundles = "cleanup_toolcache_bundles",
7782
CleanupTrapCaches = "cleanup_trap_caches",
7883
/** Whether to allow the `config-file` input to be specified via a repository property. */
7984
ConfigFileRepositoryProperty = "config_file_repository_property",
@@ -211,6 +216,11 @@ export const featureConfig = {
211216
envVar: "CODEQL_ACTION_ALLOW_MULTIPLE_ANALYSIS_KINDS",
212217
minimumVersion: undefined,
213218
},
219+
[Feature.CleanupToolcacheBundles]: {
220+
defaultValue: false,
221+
envVar: "CODEQL_ACTION_CLEANUP_TOOLCACHE_BUNDLES",
222+
minimumVersion: undefined,
223+
},
214224
[Feature.CleanupTrapCaches]: {
215225
defaultValue: false,
216226
envVar: "CODEQL_ACTION_CLEANUP_TRAP_CACHES",

0 commit comments

Comments
 (0)