Skip to content

Commit 22eb619

Browse files
authored
Merge pull request github#11467 from erik-krogh/test-ci
CI: fix moving the compilation cache
2 parents 594b7ef + 045e6ef commit 22eb619

File tree

3 files changed

+77
-9
lines changed

3 files changed

+77
-9
lines changed

.github/actions/cache-query-compilation/action.yml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,8 @@ runs:
2424
shell: bash
2525
run: |
2626
# Move all the existing cache into another folder, so we only preserve the cache for the current queries.
27-
mkdir -p ${COMBINED_CACHE_DIR}
28-
rm -f **/.cache/{lock,size} # -f to avoid errors if the cache is empty.
29-
# copy the contents of the .cache folders into the combined cache folder.
30-
cp -r **/.cache/* ${COMBINED_CACHE_DIR}/ || : # ignore missing files
31-
# clean up the .cache folders
32-
rm -rf **/.cache/*
27+
node $GITHUB_WORKSPACE/.github/actions/cache-query-compilation/move-caches.js ${COMBINED_CACHE_DIR}
3328
3429
echo "compdir=${COMBINED_CACHE_DIR}" >> $GITHUB_OUTPUT
3530
env:
36-
COMBINED_CACHE_DIR: ${{ github.workspace }}/compilation-dir
31+
COMBINED_CACHE_DIR: ${{ runner.temp }}/compilation-dir
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// # Move all the existing cache into another folder, so we only preserve the cache for the current queries.
2+
// mkdir -p ${COMBINED_CACHE_DIR}
3+
// rm -f **/.cache/{lock,size} # -f to avoid errors if the cache is empty.
4+
// # copy the contents of the .cache folders into the combined cache folder.
5+
// cp -r **/.cache/* ${COMBINED_CACHE_DIR}/ || : # ignore missing files
6+
// # clean up the .cache folders
7+
// rm -rf **/.cache/*
8+
9+
const fs = require("fs");
10+
const path = require("path");
11+
12+
// the first argv is the cache folder to create.
13+
const COMBINED_CACHE_DIR = process.argv[2];
14+
15+
function* walkCaches(dir) {
16+
const files = fs.readdirSync(dir, { withFileTypes: true });
17+
for (const file of files) {
18+
if (file.isDirectory()) {
19+
const filePath = path.join(dir, file.name);
20+
yield* walkCaches(filePath);
21+
if (file.name === ".cache") {
22+
yield filePath;
23+
}
24+
}
25+
}
26+
}
27+
28+
async function copyDir(src, dest) {
29+
for await (const file of await fs.promises.readdir(src, { withFileTypes: true })) {
30+
const srcPath = path.join(src, file.name);
31+
const destPath = path.join(dest, file.name);
32+
if (file.isDirectory()) {
33+
if (!fs.existsSync(destPath)) {
34+
fs.mkdirSync(destPath);
35+
}
36+
await copyDir(srcPath, destPath);
37+
} else {
38+
await fs.promises.copyFile(srcPath, destPath);
39+
}
40+
}
41+
}
42+
43+
async function main() {
44+
const cacheDirs = [...walkCaches(".")];
45+
46+
for (const dir of cacheDirs) {
47+
console.log(`Found .cache dir at ${dir}`);
48+
}
49+
50+
// mkdir -p ${COMBINED_CACHE_DIR}
51+
fs.mkdirSync(COMBINED_CACHE_DIR, { recursive: true });
52+
53+
// rm -f **/.cache/{lock,size} # -f to avoid errors if the cache is empty.
54+
await Promise.all(
55+
cacheDirs.map((cacheDir) =>
56+
(async function () {
57+
await fs.promises.rm(path.join(cacheDir, "lock"), { force: true });
58+
await fs.promises.rm(path.join(cacheDir, "size"), { force: true });
59+
})()
60+
)
61+
);
62+
63+
// # copy the contents of the .cache folders into the combined cache folder.
64+
// cp -r **/.cache/* ${COMBINED_CACHE_DIR}/ || : # ignore missing files
65+
await Promise.all(
66+
cacheDirs.map((cacheDir) => copyDir(cacheDir, COMBINED_CACHE_DIR))
67+
);
68+
69+
// # clean up the .cache folders
70+
// rm -rf **/.cache/*
71+
await Promise.all(
72+
cacheDirs.map((cacheDir) => fs.promises.rm(cacheDir, { recursive: true }))
73+
);
74+
}
75+
main();

.github/workflows/compile-queries.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,3 @@ jobs:
3535
if : ${{ github.event_name != 'pull_request' }}
3636
shell: bash
3737
run: codeql query compile -j0 */ql/{src,examples} --keep-going --warnings=error --compilation-cache "${{ steps.query-cache.outputs.cache-dir }}"
38-
env:
39-
COMBINED_CACHE_DIR: ${{ github.workspace }}/compilation-dir

0 commit comments

Comments
 (0)