chore: clean up old git actions logs (#514)
<!-- .github/pull_request_template.md --> ## Description <!-- Provide a clear description of the changes in this PR --> ## DCO Affirmation I affirm that all code in every commit of this pull request conforms to the terms of the Topoteretes Developer Certificate of Origin <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Chores** - Introduced an automated maintenance process to periodically remove outdated workflow runs. This process runs on a regular weekly schedule and can also be triggered manually, helping keep system operations efficient. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
parent
f3e296b171
commit
ea1c8bd3ca
1 changed files with 47 additions and 0 deletions
47
.github/workflows/clean_old_git_actions.yml
vendored
Normal file
47
.github/workflows/clean_old_git_actions.yml
vendored
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
name: clean | Cleanup Old Workflow Runs
|
||||
|
||||
on:
|
||||
schedule:
|
||||
- cron: '0 3 * * 0' # Runs every Sunday at 03:00 UTC
|
||||
workflow_dispatch: # Allows manual trigger
|
||||
|
||||
jobs:
|
||||
cleanup:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Delete old workflow runs
|
||||
env:
|
||||
GH_PAT: ${{ secrets.GH_PAT }}
|
||||
REPO: ${{ github.repository }}
|
||||
DAYS: 100 # Adjust the number of days if needed
|
||||
run: |
|
||||
# Get current timestamp
|
||||
NOW=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
|
||||
|
||||
# Fetch all workflow runs
|
||||
runs=$(curl -s -H "Authorization: token $GH_PAT" \
|
||||
-H "Accept: application/vnd.github.v3+json" \
|
||||
"https://api.github.com/repos/$REPO/actions/runs" | jq -c '.workflow_runs[]')
|
||||
|
||||
# Loop through each run
|
||||
echo "$runs" | while read -r run; do
|
||||
created_at=$(echo "$run" | jq -r '.created_at')
|
||||
run_id=$(echo "$run" | jq -r '.id')
|
||||
|
||||
# Convert timestamps to seconds
|
||||
created_seconds=$(date -d "$created_at" +%s)
|
||||
now_seconds=$(date -d "$NOW" +%s)
|
||||
|
||||
# Calculate age of workflow run
|
||||
age_days=$(( (now_seconds - created_seconds) / 86400 ))
|
||||
|
||||
if [ "$age_days" -gt "$DAYS" ]; then
|
||||
echo "Deleting workflow run ID: $run_id (Created: $created_at, Age: $age_days days)"
|
||||
curl -X DELETE -H "Authorization: token $GH_PAT" \
|
||||
-H "Accept: application/vnd.github.v3+json" \
|
||||
"https://api.github.com/repos/$REPO/actions/runs/$run_id"
|
||||
else
|
||||
echo "Skipping workflow run ID: $run_id (Created: $created_at, Age: $age_days days)"
|
||||
fi
|
||||
done
|
||||
Loading…
Add table
Reference in a new issue