Skip to content

Commit 431ec69

Browse files
authored
Create Git Optimizer.yml
1 parent 1c5da77 commit 431ec69

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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.");

0 commit comments

Comments
 (0)