Skip to content

Commit

Permalink
fix cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mgrybyk committed Jul 23, 2024
1 parent 50a639a commit c21ca5c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
13 changes: 12 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41540,6 +41540,17 @@ const cleanupOutdatedBranches = async (ghPagesBaseDir) => {
console.error('cleanup outdated branches failed.', err);
}
};
const sortRuns = (a, b) => {
const tsA = a.split('_')[1];
const tsb = b.split('_')[1];
if (tsA < tsb) {
return -1;
}
if (tsA > tsb) {
return 1;
}
return 0;
};
const cleanupOutdatedReports = async (ghPagesBaseDir, maxReports) => {
try {
const localBranches = (await promises_.readdir(ghPagesBaseDir, { withFileTypes: true })).filter((d) => d.isDirectory()).map((d) => d.name);
Expand All @@ -41555,7 +41566,7 @@ const cleanupOutdatedReports = async (ghPagesBaseDir, maxReports) => {
.map((d) => d.name);
// run per report
if (runs.length > maxReports) {
runs.sort();
runs.sort(sortRuns);
while (runs.length > maxReports) {
await promises_.rm(external_path_.join(ghPagesBaseDir, localBranch, reportName, runs.shift()), {
recursive: true,
Expand Down
15 changes: 14 additions & 1 deletion src/cleanup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@ export const cleanupOutdatedBranches = async (ghPagesBaseDir: string) => {
}
}

const sortRuns = (a: string, b: string) => {
const tsA = a.split('_')[1]
const tsb = b.split('_')[1]
if (tsA < tsb) {
return -1
}
if (tsA > tsb) {
return 1
}

return 0
}

export const cleanupOutdatedReports = async (ghPagesBaseDir: string, maxReports: number) => {
try {
const localBranches = (await fs.readdir(ghPagesBaseDir, { withFileTypes: true })).filter((d) => d.isDirectory()).map((d) => d.name)
Expand All @@ -42,7 +55,7 @@ export const cleanupOutdatedReports = async (ghPagesBaseDir: string, maxReports:

// run per report
if (runs.length > maxReports) {
runs.sort()
runs.sort(sortRuns)
while (runs.length > maxReports) {
await fs.rm(path.join(ghPagesBaseDir, localBranch, reportName, runs.shift() as string), {
recursive: true,
Expand Down

0 comments on commit c21ca5c

Please sign in to comment.