Skip to content

Commit 81a9508

Browse files
authored
Merge pull request #2876 from github/henrymercer/fix-diff-informed-multiple-analyze
Do not fail diff informed analyses when analyze is run twice in the same job
2 parents 40e16ed + 1569f4c commit 81a9508

File tree

7 files changed

+98
-80
lines changed

7 files changed

+98
-80
lines changed

.github/workflows/codescanning-config-cli.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
name: Code-Scanning config CLI tests
44
env:
55
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6+
# Diff informed queries add an additional query filter which is not yet
7+
# taken into account by these tests.
8+
CODEQL_ACTION_DIFF_INFORMED_QUERIES: false
69

710
on:
811
push:

lib/analyze.js

Lines changed: 6 additions & 1 deletion
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: 40 additions & 38 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.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,13 @@ function writeDiffRangeDataExtensionPack(
507507
actionsUtil.getTemporaryDirectory(),
508508
"pr-diff-range",
509509
);
510-
fs.mkdirSync(diffRangeDir);
510+
511+
// We expect the Actions temporary directory to already exist, so are mainly
512+
// using `recursive: true` to avoid errors if the directory already exists,
513+
// for example if the analyze Action is run multiple times in the same job.
514+
// This is not really something that is supported, but we make use of it in
515+
// tests.
516+
fs.mkdirSync(diffRangeDir, { recursive: true });
511517
fs.writeFileSync(
512518
path.join(diffRangeDir, "qlpack.yml"),
513519
`

src/dependency-caching.ts

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -41,42 +41,44 @@ export function getJavaTempDependencyDir(): string {
4141
/**
4242
* Default caching configurations per language.
4343
*/
44-
const CODEQL_DEFAULT_CACHE_CONFIG: { [language: string]: CacheConfig } = {
45-
java: {
46-
paths: [
47-
// Maven
48-
join(os.homedir(), ".m2", "repository"),
49-
// Gradle
50-
join(os.homedir(), ".gradle", "caches"),
51-
// CodeQL Java build-mode: none
52-
getJavaTempDependencyDir(),
53-
],
54-
hash: [
55-
// Maven
56-
"**/pom.xml",
57-
// Gradle
58-
"**/*.gradle*",
59-
"**/gradle-wrapper.properties",
60-
"buildSrc/**/Versions.kt",
61-
"buildSrc/**/Dependencies.kt",
62-
"gradle/*.versions.toml",
63-
"**/versions.properties",
64-
],
65-
},
66-
csharp: {
67-
paths: [join(os.homedir(), ".nuget", "packages")],
68-
hash: [
69-
// NuGet
70-
"**/packages.lock.json",
71-
// Paket
72-
"**/paket.lock",
73-
],
74-
},
75-
go: {
76-
paths: [join(os.homedir(), "go", "pkg", "mod")],
77-
hash: ["**/go.sum"],
78-
},
79-
};
44+
function getDefaultCacheConfig(): { [language: string]: CacheConfig } {
45+
return {
46+
java: {
47+
paths: [
48+
// Maven
49+
join(os.homedir(), ".m2", "repository"),
50+
// Gradle
51+
join(os.homedir(), ".gradle", "caches"),
52+
// CodeQL Java build-mode: none
53+
getJavaTempDependencyDir(),
54+
],
55+
hash: [
56+
// Maven
57+
"**/pom.xml",
58+
// Gradle
59+
"**/*.gradle*",
60+
"**/gradle-wrapper.properties",
61+
"buildSrc/**/Versions.kt",
62+
"buildSrc/**/Dependencies.kt",
63+
"gradle/*.versions.toml",
64+
"**/versions.properties",
65+
],
66+
},
67+
csharp: {
68+
paths: [join(os.homedir(), ".nuget", "packages")],
69+
hash: [
70+
// NuGet
71+
"**/packages.lock.json",
72+
// Paket
73+
"**/paket.lock",
74+
],
75+
},
76+
go: {
77+
paths: [join(os.homedir(), "go", "pkg", "mod")],
78+
hash: ["**/go.sum"],
79+
},
80+
};
81+
}
8082

8183
async function makeGlobber(patterns: string[]): Promise<glob.Globber> {
8284
return glob.create(patterns.join("\n"));
@@ -96,7 +98,7 @@ export async function downloadDependencyCaches(
9698
const restoredCaches: Language[] = [];
9799

98100
for (const language of languages) {
99-
const cacheConfig = CODEQL_DEFAULT_CACHE_CONFIG[language];
101+
const cacheConfig = getDefaultCacheConfig()[language];
100102

101103
if (cacheConfig === undefined) {
102104
logger.info(
@@ -150,7 +152,7 @@ export async function downloadDependencyCaches(
150152
*/
151153
export async function uploadDependencyCaches(config: Config, logger: Logger) {
152154
for (const language of config.languages) {
153-
const cacheConfig = CODEQL_DEFAULT_CACHE_CONFIG[language];
155+
const cacheConfig = getDefaultCacheConfig()[language];
154156

155157
if (cacheConfig === undefined) {
156158
logger.info(

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