5757 const fs = require('fs');
5858 const path = require('path');
5959 const keepResultsPerDay = 1;
60+ const monthsToKeep = 6;
61+
62+ function parseDate(dateStr) {
63+ const year = parseInt(dateStr.substring(0, 4), 10);
64+ const month = parseInt(dateStr.substring(4, 6), 10) - 1;
65+ const day = parseInt(dateStr.substring(6, 8), 10);
66+ return new Date(year, month, day);
67+ }
6068
6169 const resultDir = './bin/gh-pages/result';
6270 const results = fs.readdirSync(resultDir).filter(d => {
@@ -71,10 +79,30 @@ jobs:
7179 acc[date].push(dir);
7280 return acc;
7381 }, {});
82+
83+ const cutoff = new Date();
84+ cutoff.setMonth(cutoff.getMonth() - monthsToKeep);
85+ cutoff.setHours(0, 0, 0, 0);
7486
7587 Object.keys(resultsByDate).forEach(date => {
7688 const dirs = resultsByDate[date];
7789 const removeDirs = [];
90+
91+ const pdate = parseDate(date);
92+ if (Number.isNaN(pdate.getTime())) {
93+ core.warning(`Skipping unrecognized date format in ${date}`);
94+ return;
95+ }
96+
97+ if (pdate < cutoff) {
98+ dirs.forEach(dir => {
99+ const dirPath = path.join(resultDir, dir);
100+ fs.rmSync(dirPath, { recursive: true, force: true });
101+ core.info(`Removed ${dirPath} (older than ${monthsToKeep} months)`);
102+ });
103+ return;
104+ }
105+
78106 dirs.forEach(dir => {
79107 const envFilePath = path.join(resultDir, dir, 'env.txt');
80108 if (fs.existsSync(envFilePath)) {
0 commit comments