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

Lines changed: 1 addition & 1 deletion
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

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

lib/analyze-action-post.js.map

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

lib/analyze.js

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

lib/analyze.js.map

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

lib/dependency-caching.js

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

lib/dependency-caching.js.map

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

src/analyze-action-post.ts

Lines changed: 17 additions & 0 deletions
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

Lines changed: 11 additions & 0 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy