Skip to content

Commit b927620

Browse files
committed
Generalise status to multiple languages
1 parent 63fce43 commit b927620

File tree

2 files changed

+27
-15
lines changed

2 files changed

+27
-15
lines changed

src/overlay/status.test.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,35 +17,47 @@ function makeDiskUsage(totalGiB: number): DiskUsage {
1717
test("getCacheKey incorporates language, CodeQL version, and disk space", async (t) => {
1818
const codeql = mockCodeQLVersion("2.20.0");
1919
t.is(
20-
await getCacheKey(codeql, "javascript", makeDiskUsage(50)),
20+
await getCacheKey(codeql, ["javascript"], makeDiskUsage(50)),
2121
"codeql-overlay-status-javascript-2.20.0-runner-50GB",
2222
);
2323
t.is(
24-
await getCacheKey(codeql, "python", makeDiskUsage(50)),
24+
await getCacheKey(codeql, ["python"], makeDiskUsage(50)),
2525
"codeql-overlay-status-python-2.20.0-runner-50GB",
2626
);
2727
t.is(
2828
await getCacheKey(
2929
mockCodeQLVersion("2.21.0"),
30-
"javascript",
30+
["javascript"],
3131
makeDiskUsage(50),
3232
),
3333
"codeql-overlay-status-javascript-2.21.0-runner-50GB",
3434
);
3535
t.is(
36-
await getCacheKey(codeql, "javascript", makeDiskUsage(100)),
36+
await getCacheKey(codeql, ["javascript"], makeDiskUsage(100)),
3737
"codeql-overlay-status-javascript-2.20.0-runner-100GB",
3838
);
3939
});
4040

41+
test("getCacheKey sorts and joins multiple languages", async (t) => {
42+
const codeql = mockCodeQLVersion("2.20.0");
43+
t.is(
44+
await getCacheKey(codeql, ["python", "javascript"], makeDiskUsage(50)),
45+
"codeql-overlay-status-javascript+python-2.20.0-runner-50GB",
46+
);
47+
t.is(
48+
await getCacheKey(codeql, ["javascript", "python"], makeDiskUsage(50)),
49+
"codeql-overlay-status-javascript+python-2.20.0-runner-50GB",
50+
);
51+
});
52+
4153
test("getCacheKey rounds disk space down to nearest 10 GiB", async (t) => {
4254
const codeql = mockCodeQLVersion("2.20.0");
4355
t.is(
44-
await getCacheKey(codeql, "javascript", makeDiskUsage(14)),
56+
await getCacheKey(codeql, ["javascript"], makeDiskUsage(14)),
4557
"codeql-overlay-status-javascript-2.20.0-runner-10GB",
4658
);
4759
t.is(
48-
await getCacheKey(codeql, "javascript", makeDiskUsage(19)),
60+
await getCacheKey(codeql, ["javascript"], makeDiskUsage(19)),
4961
"codeql-overlay-status-javascript-2.20.0-runner-10GB",
5062
);
5163
});

src/overlay/status.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const MAX_CACHE_OPERATION_MS = 30_000;
2828
/** File name for the serialized overlay status. */
2929
const STATUS_FILE_NAME = "overlay-status.json";
3030

31-
/** Status of an overlay analysis for a particular language. */
31+
/** Status of an overlay analysis for a set of languages. */
3232
export interface OverlayStatus {
3333
/** Whether the job successfully built an overlay base database. */
3434
builtOverlayBaseDatabase: boolean;
@@ -42,15 +42,15 @@ export interface OverlayStatus {
4242
*/
4343
export async function getOverlayStatus(
4444
codeql: CodeQL,
45-
language: string,
45+
languages: string[],
4646
diskUsage: DiskUsage,
4747
logger: Logger,
4848
): Promise<OverlayStatus | undefined> {
49-
const cacheKey = await getCacheKey(codeql, language, diskUsage);
49+
const cacheKey = await getCacheKey(codeql, languages, diskUsage);
5050
const statusFile = path.join(
5151
getTemporaryDirectory(),
5252
"overlay-status",
53-
language,
53+
languages.sort().join("+"),
5454
STATUS_FILE_NAME,
5555
);
5656
await fs.promises.mkdir(path.dirname(statusFile), { recursive: true });
@@ -92,16 +92,16 @@ export async function getOverlayStatus(
9292
*/
9393
export async function saveOverlayStatus(
9494
codeql: CodeQL,
95-
language: string,
95+
languages: string[],
9696
diskUsage: DiskUsage,
9797
status: OverlayStatus,
9898
logger: Logger,
9999
): Promise<boolean> {
100-
const cacheKey = await getCacheKey(codeql, language, diskUsage);
100+
const cacheKey = await getCacheKey(codeql, languages, diskUsage);
101101
const statusFile = path.join(
102102
getTemporaryDirectory(),
103103
"overlay-status",
104-
language,
104+
languages.sort().join("+"),
105105
STATUS_FILE_NAME,
106106
);
107107
await fs.promises.mkdir(path.dirname(statusFile), { recursive: true });
@@ -129,7 +129,7 @@ export async function saveOverlayStatus(
129129

130130
export async function getCacheKey(
131131
codeql: CodeQL,
132-
language: string,
132+
languages: string[],
133133
diskUsage: DiskUsage,
134134
): Promise<string> {
135135
// Total disk space, rounded to the nearest 10 GB. This is included in the cache key so that if a
@@ -143,5 +143,5 @@ export async function getCacheKey(
143143

144144
// Include the CodeQL version in the cache key so we will try again to use overlay analysis when
145145
// new queries and libraries that may be more efficient are released.
146-
return `codeql-overlay-status-${language}-${(await codeql.getVersion()).version}-runner-${diskSpaceToNearest10Gb}`;
146+
return `codeql-overlay-status-${languages.sort().join("+")}-${(await codeql.getVersion()).version}-runner-${diskSpaceToNearest10Gb}`;
147147
}

0 commit comments

Comments
 (0)