Skip to content

Commit 55f0237

Browse files
authored
Merge pull request #2802 from github/mbg/dependency-caching/java-buildless
Set and cache dependency directory for Java `build-mode: none`
2 parents 6a151cd + 4c409a5 commit 55f0237

10 files changed

+79
-4
lines changed

CHANGELOG.md

+1-1
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-
No user facing changes.
7+
- Dependency caching should now cache more dependencies for Java `build-mode: none` extractions. This should speed up workflows and avoid inconsistent alerts in some cases.
88

99
## 3.28.11 - 07 Mar 2025
1010

lib/analyze-action-post.js

+14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/analyze-action-post.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/analyze.js

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/analyze.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/dependency-caching.js

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/dependency-caching.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/analyze-action-post.ts

+17
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33
* It will run after the all steps in this job, in reverse order in relation to
44
* other `post:` hooks.
55
*/
6+
import * as fs from "fs";
7+
68
import * as core from "@actions/core";
79

810
import * as actionsUtil from "./actions-util";
911
import { getGitHubVersion } from "./api-client";
1012
import { getCodeQL } from "./codeql";
1113
import { getConfig } from "./config-utils";
1214
import * as debugArtifacts from "./debug-artifacts";
15+
import { getJavaTempDependencyDir } from "./dependency-caching";
1316
import { EnvVar } from "./environment";
1417
import { getActionsLogger } from "./logging";
1518
import { checkGitHubVersionInRange, getErrorMessage } from "./util";
@@ -38,6 +41,20 @@ async function runWrapper() {
3841
);
3942
}
4043
}
44+
45+
// If we analysed Java in build-mode: none, we may have downloaded dependencies
46+
// to the temp directory. Clean these up so they don't persist unnecessarily
47+
// long on self-hosted runners.
48+
const javaTempDependencyDir = getJavaTempDependencyDir();
49+
if (fs.existsSync(javaTempDependencyDir)) {
50+
try {
51+
fs.rmSync(javaTempDependencyDir, { recursive: true });
52+
} catch (error) {
53+
logger.info(
54+
`Failed to remove temporary Java dependencies directory: ${getErrorMessage(error)}`,
55+
);
56+
}
57+
}
4158
} catch (error) {
4259
core.setFailed(
4360
`analyze post-action step failed: ${getErrorMessage(error)}`,

src/analyze.ts

+11
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { getApiClient } from "./api-client";
1111
import { setupCppAutobuild } from "./autobuild";
1212
import { CodeQL, getCodeQL } from "./codeql";
1313
import * as configUtils from "./config-utils";
14+
import { getJavaTempDependencyDir } from "./dependency-caching";
1415
import { addDiagnostic, makeDiagnostic } from "./diagnostics";
1516
import {
1617
DiffThunkRange,
@@ -166,6 +167,16 @@ export async function runExtraction(
166167
) {
167168
await setupCppAutobuild(codeql, logger);
168169
}
170+
171+
// The Java `build-mode: none` extractor places dependencies (.jar files) in the
172+
// database scratch directory by default. For dependency caching purposes, we want
173+
// a stable path that caches can be restored into and that we can cache at the
174+
// end of the workflow (i.e. that does not get removed when the scratch directory is).
175+
if (language === Language.java && config.buildMode === BuildMode.None) {
176+
process.env["CODEQL_EXTRACTOR_JAVA_OPTION_BUILDLESS_DEPENDENCY_DIR"] =
177+
getJavaTempDependencyDir();
178+
}
179+
169180
await codeql.extractUsingBuildMode(config, language);
170181
} else {
171182
await codeql.extractScannedLanguage(config, language);

0 commit comments

Comments
 (0)