File tree Expand file tree Collapse file tree 1 file changed +60
-0
lines changed
Expand file tree Collapse file tree 1 file changed +60
-0
lines changed Original file line number Diff line number Diff line change 1+ name : Git Optimizer
2+
3+ on :
4+ schedule :
5+ - cron : " 30 18 * * 6" # Runs every Sunday at 00:00 IST (18:30 UTC Saturday)
6+ workflow_dispatch :
7+
8+ permissions :
9+ actions : write
10+ contents : read
11+
12+ jobs :
13+ optimize :
14+ runs-on : ubuntu-latest
15+
16+ steps :
17+ - name : Checkout full history
18+ uses : actions/checkout@v4
19+ with :
20+ fetch-depth : 0
21+
22+ - name : Skip if no commits in last 7 days
23+ run : |
24+ LAST_COMMIT_DATE=$(git log -1 --pretty="%ct")
25+ SEVEN_DAYS_AGO=$(date -d "7 days ago" +%s)
26+
27+ if [ "$LAST_COMMIT_DATE" -lt "$SEVEN_DAYS_AGO" ]; then
28+ echo "⏩ No activity in last 7 days. Skipping optimization."
29+ exit 0
30+ fi
31+
32+ echo "✔ Recent commits detected. Continuing..."
33+
34+ - name : Lightweight Git GC
35+ run : git gc --auto
36+
37+ - name : Compact loose objects
38+ run : git repack -d
39+
40+ - name : Update commit-graph
41+ run : git commit-graph write --reachable --changed-paths
42+
43+ - name : Cleanup GitHub Actions caches
44+ uses : actions/github-script@v7
45+ with :
46+ script : |
47+ const caches = await github.rest.actions.getActionsCacheList({
48+ owner: context.repo.owner,
49+ repo: context.repo.repo,
50+ });
51+
52+ for (const cache of caches.data.actions_caches) {
53+ await github.rest.actions.deleteActionsCacheById({
54+ owner: context.repo.owner,
55+ repo: context.repo.repo,
56+ cache_id: cache.id
57+ });
58+ }
59+
60+ console.log("Done.");
You can’t perform that action at this time.
0 commit comments