Skip to content

Git Optimizer

Git Optimizer #1

Workflow file for this run

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.");