Update .delete-old-commits.yml #7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
from git_filter_repo import Repo | |
repo = Repo(".") | |
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 | |