Skip to content

Commit 11daff7

Browse files
committed
Clear old builds
1 parent 393c494 commit 11daff7

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

web/scripts/runner.mjs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,40 @@ async function buildAndCopyCoreJS() {
184184
console.timeEnd(`Core JS bundle built`);
185185
}
186186

187+
async function getExcludedBuilds() {
188+
const branchBuilds = await fs.readdir('./branches/');
189+
const excluded = new Set();
190+
for (const branch of branchBuilds) {
191+
const link = await fs.readlink(`./branches/${branch}`);
192+
if (!link) continue;
193+
const parts = link.split('/');
194+
const buildId = parts[parts.length - 2];
195+
excluded.add(buildId);
196+
}
197+
const latestBuildLink = await fs.readlink(`./latest`);
198+
if (latestBuildLink) {
199+
const parts = latestBuildLink.split('/');
200+
const buildId = parts[parts.length - 2];
201+
excluded.add(buildId);
202+
}
203+
204+
return Array.from(excluded);
205+
}
206+
207+
async function clearOldBuilds() {
208+
console.log(`Clearing old builds...`);
209+
console.time(`Cleared old builds`);
210+
const excluded = await getExcludedBuilds();
211+
const builds = await fs.readdir(buildsRootDir);
212+
for (const build of builds) {
213+
if (!excluded.includes(build)) {
214+
await exec(`rm -rf ${path.join('./', buildsRootDir, '/', build)}`);
215+
console.log(`Build removed: "${path.join('./', buildsRootDir, '/', build)}"`, path);
216+
}
217+
}
218+
console.timeEnd(`Cleared old builds`);
219+
}
220+
187221
async function run() {
188222
console.time('Finished in');
189223
await createBuildDir();
@@ -216,6 +250,7 @@ async function run() {
216250
await switchBranchToLatestBuild(targetBranch);
217251
}
218252
await clearBuildDir();
253+
await clearOldBuilds();
219254
console.timeEnd('Finished in');
220255
}
221256

0 commit comments

Comments
 (0)