Skip to content

Update .delete-old-commits.yml #6

Update .delete-old-commits.yml

Update .delete-old-commits.yml #6

name: Delete Old Commits
on:
schedule:
- cron: "0 0 * * *" # Runs daily at midnight
workflow_dispatch:
push:
paths:
- .github/workflows/.delete-old-commits.yml
jobs:
delete_old_commits:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@main
with:
fetch-depth: 0
- name: Set up Git
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
- name: Install git-filter-repo
run: |
pip install git-filter-repo
- name: Delete old commits
run: |
git filter-repo --force --commit-callback '
import datetime
latest_commit_time = datetime.datetime.fromtimestamp(int(repo.head.commit.author_date.decode("utf-8").split()[0]))
one_day_ago = latest_commit_time - datetime.timedelta(days=1)
commit_time = datetime.datetime.fromtimestamp(int(commit.author_date.decode("utf-8").split()[0]))
if commit_time < one_day_ago:
commit.skip()
'
- name: Dry run - Print git log
if: github.event_name != 'schedule'
run: |
git log --oneline
- name: Force push changes
if: github.event_name == 'schedule'
run: |
git push origin --force --all