Skip to content

Commit 2b529fb

Browse files
authored
Merge pull request github#12213 from github/erik-krogh/patch-test
CI: inline the move-caches script into the action
2 parents 35b6016 + 767da59 commit 2b529fb

File tree

3 files changed

+79
-90
lines changed

3 files changed

+79
-90
lines changed

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

Lines changed: 79 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,83 @@ runs:
4343
codeql-compile-${{ inputs.key }}-${{ github.ref_name }}-
4444
codeql-compile-${{ inputs.key }}-main-
4545
- name: Fill compilation cache directory
46-
id: fill-compilation-dir
47-
shell: bash
48-
run: |
49-
# Move all the existing cache into another folder, so we only preserve the cache for the current queries.
50-
node $GITHUB_WORKSPACE/.github/actions/cache-query-compilation/move-caches.js ${COMBINED_CACHE_DIR}
51-
52-
echo "compdir=${COMBINED_CACHE_DIR}" >> $GITHUB_OUTPUT
53-
env:
46+
uses: actions/github-script@v6
47+
env:
5448
COMBINED_CACHE_DIR: ${{ runner.temp }}/compilation-dir
49+
with:
50+
script: |
51+
// # Move all the existing cache into another folder, so we only preserve the cache for the current queries.
52+
// mkdir -p ${COMBINED_CACHE_DIR}
53+
// rm -f **/.cache/{lock,size} # -f to avoid errors if the cache is empty.
54+
// # copy the contents of the .cache folders into the combined cache folder.
55+
// cp -r **/.cache/* ${COMBINED_CACHE_DIR}/ || : # ignore missing files
56+
// # clean up the .cache folders
57+
// rm -rf **/.cache/*
58+
59+
const fs = require("fs");
60+
const path = require("path");
61+
62+
// the first argv is the cache folder to create.
63+
const COMBINED_CACHE_DIR = process.env.COMBINED_CACHE_DIR;
64+
65+
function* walkCaches(dir) {
66+
const files = fs.readdirSync(dir, { withFileTypes: true });
67+
for (const file of files) {
68+
if (file.isDirectory()) {
69+
const filePath = path.join(dir, file.name);
70+
yield* walkCaches(filePath);
71+
if (file.name === ".cache") {
72+
yield filePath;
73+
}
74+
}
75+
}
76+
}
77+
78+
async function copyDir(src, dest) {
79+
for await (const file of await fs.promises.readdir(src, { withFileTypes: true })) {
80+
const srcPath = path.join(src, file.name);
81+
const destPath = path.join(dest, file.name);
82+
if (file.isDirectory()) {
83+
if (!fs.existsSync(destPath)) {
84+
fs.mkdirSync(destPath);
85+
}
86+
await copyDir(srcPath, destPath);
87+
} else {
88+
await fs.promises.copyFile(srcPath, destPath);
89+
}
90+
}
91+
}
92+
93+
async function main() {
94+
const cacheDirs = [...walkCaches(".")];
95+
96+
for (const dir of cacheDirs) {
97+
console.log(`Found .cache dir at ${dir}`);
98+
}
99+
100+
// mkdir -p ${COMBINED_CACHE_DIR}
101+
fs.mkdirSync(COMBINED_CACHE_DIR, { recursive: true });
102+
103+
// rm -f **/.cache/{lock,size} # -f to avoid errors if the cache is empty.
104+
await Promise.all(
105+
cacheDirs.map((cacheDir) =>
106+
(async function () {
107+
await fs.promises.rm(path.join(cacheDir, "lock"), { force: true });
108+
await fs.promises.rm(path.join(cacheDir, "size"), { force: true });
109+
})()
110+
)
111+
);
112+
113+
// # copy the contents of the .cache folders into the combined cache folder.
114+
// cp -r **/.cache/* ${COMBINED_CACHE_DIR}/ || : # ignore missing files
115+
await Promise.all(
116+
cacheDirs.map((cacheDir) => copyDir(cacheDir, COMBINED_CACHE_DIR))
117+
);
118+
119+
// # clean up the .cache folders
120+
// rm -rf **/.cache/*
121+
await Promise.all(
122+
cacheDirs.map((cacheDir) => fs.promises.rm(cacheDir, { recursive: true }))
123+
);
124+
}
125+
main();

.github/actions/cache-query-compilation/move-caches.js

Lines changed: 0 additions & 75 deletions
This file was deleted.

.github/workflows/ql-for-ql-build.yml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,6 @@ on:
55
branches: [main]
66
pull_request:
77
branches: [main]
8-
paths:
9-
- "ql/**"
10-
- "**.qll"
11-
- "**.ql"
12-
- "**.dbscheme"
13-
- "**/qlpack.yml"
14-
- ".github/workflows/ql-for-ql-build.yml"
158

169
env:
1710
CARGO_TERM_COLOR: always

0 commit comments

Comments
 (0)