Skip to content

Repository Management #84

Repository Management

Repository Management #84

Workflow file for this run

name: Repository Management
on:
schedule:
- cron: '30 1 * * *' # Daily at 1:30 AM UTC
workflow_dispatch:
permissions:
contents: read
pull-requests: write
issues: write
actions: write
jobs:
stale:
name: Close Stale PRs
runs-on: ubuntu-latest
steps:
- name: Stale PR handler
uses: actions/stale@v9
with:
stale-pr-message: |
This PR has been automatically marked as stale because it has not had
recent activity. It will be closed in 7 days if no further activity occurs.
If this PR is still relevant, please:
- Add a comment explaining the status
- Push new changes
- Request a review
close-pr-message: |
This PR has been automatically closed due to inactivity.
Feel free to reopen it if you'd like to continue working on it.
stale-pr-label: 'stale'
days-before-pr-stale: 30
days-before-pr-close: 7
exempt-pr-labels: 'pinned,security,work-in-progress'
operations-per-run: 50
cleanup-caches:
name: Cleanup Old Caches
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Cleanup caches for closed branches
run: |
gh extension install actions/gh-actions-cache || true
echo "Fetching list of cache keys"
cacheKeysForPR=$(gh actions-cache list -R ${{ github.repository }} -L 100 | cut -f 1)
openBranches=$(git ls-remote --heads origin | awk '{print $2}' | sed 's|refs/heads/||')
for cacheKey in $cacheKeysForPR; do
branchName=$(echo $cacheKey | grep -oP 'refs/pull/\d+' || echo "")
if [ -n "$branchName" ]; then
prNumber=$(echo $branchName | grep -oP '\d+')
prState=$(gh pr view $prNumber --json state -q '.state' 2>/dev/null || echo "UNKNOWN")
if [ "$prState" == "CLOSED" ] || [ "$prState" == "MERGED" ]; then
echo "Deleting cache for closed PR: $cacheKey"
gh actions-cache delete "$cacheKey" -R ${{ github.repository }} --confirm || true
fi
fi
done
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}