Skip to content

Commit

Permalink
Merge pull request #197 from crazy-max/gc-keep-one-day
Browse files Browse the repository at this point in the history
gc: keep a single result per day
  • Loading branch information
crazy-max authored Dec 4, 2024
2 parents 86d040b + c4aadc1 commit 54c1940
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions .github/workflows/gc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ jobs:
script: |
const fs = require('fs');
const path = require('path');
const keepResultsPerDay = 1;
const resultDir = './bin/gh-pages/result';
const results = fs.readdirSync(resultDir).filter(d => {
Expand All @@ -66,25 +67,23 @@ jobs:
Object.keys(resultsByDate).forEach(date => {
const dirs = resultsByDate[date];
const keepDirs = [];
const removeDirs = [];
dirs.forEach(dir => {
const envFilePath = path.join(resultDir, dir, 'env.txt');
if (fs.existsSync(envFilePath)) {
const envContent = fs.readFileSync(envFilePath, 'utf8');
if (envContent.includes('GITHUB_EVENT_NAME=schedule')) {
keepDirs.push(dir);
// always keep scheduled results
return;
}
}
removeDirs.push(dir);
});
if (removeDirs.length === 0) {
return;
}
removeDirs.sort().reverse();
keepDirs.push(...removeDirs.slice(0, 3));
removeDirs.slice(3).forEach(dir => {
removeDirs.slice(keepResultsPerDay).forEach(dir => {
const dirPath = path.join(resultDir, dir);
fs.rmSync(dirPath, { recursive: true, force: true });
core.info(`Removed ${dirPath}`);
Expand Down

0 comments on commit 54c1940

Please sign in to comment.