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