Skip to content

Commit a676a41

Browse files
Copilothuangyiirene
andcommitted
Fix workflow issues: Improve file existence check and use official GitHub action
Co-authored-by: huangyiirene <7665279+huangyiirene@users.noreply.github.com>
1 parent 63f20f8 commit a676a41

2 files changed

Lines changed: 63 additions & 6 deletions

File tree

.github/workflows/benchmark.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,27 @@ jobs:
4949
timeout-minutes: 3
5050

5151
- name: Run benchmarks
52+
id: run-benchmarks
5253
run: |
5354
echo "Checking for benchmark scripts..."
5455
if pnpm -r list | grep -q "benchmark"; then
5556
echo "Running benchmarks..."
5657
pnpm -r run benchmark --if-present
58+
if [ -f "benchmark-results.json" ]; then
59+
echo "benchmark_file_exists=true" >> $GITHUB_OUTPUT
60+
else
61+
echo "benchmark_file_exists=false" >> $GITHUB_OUTPUT
62+
fi
5763
else
5864
echo "No benchmark scripts found. Skipping benchmarks."
5965
echo "To add benchmarks, add a 'benchmark' script to package.json files."
66+
echo "benchmark_file_exists=false" >> $GITHUB_OUTPUT
6067
fi
6168
timeout-minutes: 5
6269
continue-on-error: true
6370

6471
- name: Store benchmark result
65-
if: github.ref == 'refs/heads/main' && hashFiles('benchmark-results.json') != ''
72+
if: github.ref == 'refs/heads/main' && steps.run-benchmarks.outputs.benchmark_file_exists == 'true'
6673
uses: benchmark-action/github-action-benchmark@v1
6774
with:
6875
name: ObjectQL Benchmarks

.github/workflows/cleanup-runs.yml

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,59 @@ jobs:
1616
timeout-minutes: 10
1717
steps:
1818
- name: Delete workflow runs older than 30 days
19-
uses: Mattraks/delete-workflow-runs@v2
19+
uses: actions/github-script@v7
2020
with:
21-
token: ${{ github.token }}
22-
repository: ${{ github.repository }}
23-
retain_days: 30
24-
keep_minimum_runs: 6
21+
script: |
22+
const days_to_keep = 30;
23+
const minimum_runs_to_keep = 6;
24+
const cutoff_date = new Date(Date.now() - (days_to_keep * 24 * 60 * 60 * 1000));
25+
26+
const workflows = await github.rest.actions.listRepoWorkflows({
27+
owner: context.repo.owner,
28+
repo: context.repo.repo
29+
});
30+
31+
for (const workflow of workflows.data.workflows) {
32+
console.log(`Processing workflow: ${workflow.name} (${workflow.id})`);
33+
34+
const runs = await github.rest.actions.listWorkflowRuns({
35+
owner: context.repo.owner,
36+
repo: context.repo.repo,
37+
workflow_id: workflow.id,
38+
per_page: 100
39+
});
40+
41+
// Sort runs by created date, newest first
42+
const sortedRuns = runs.data.workflow_runs.sort((a, b) =>
43+
new Date(b.created_at) - new Date(a.created_at)
44+
);
45+
46+
// Keep the most recent runs and delete older ones
47+
for (let i = 0; i < sortedRuns.length; i++) {
48+
const run = sortedRuns[i];
49+
const run_date = new Date(run.created_at);
50+
51+
// Keep minimum number of recent runs
52+
if (i < minimum_runs_to_keep) {
53+
console.log(`Keeping recent run #${run.id} (${run.name})`);
54+
continue;
55+
}
56+
57+
// Delete runs older than cutoff date
58+
if (run_date < cutoff_date) {
59+
console.log(`Deleting old run #${run.id} from ${run.created_at}`);
60+
try {
61+
await github.rest.actions.deleteWorkflowRun({
62+
owner: context.repo.owner,
63+
repo: context.repo.repo,
64+
run_id: run.id
65+
});
66+
} catch (error) {
67+
console.log(`Failed to delete run #${run.id}: ${error.message}`);
68+
}
69+
}
70+
}
71+
}
72+
73+
console.log('Cleanup complete!');
74+

0 commit comments

Comments
 (0)