Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions .github/workflows/cleanup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: Cleanup

# 1) Cleans PRs with no activity for 1 day:
# a. convert it to draft
# b. drop its `deployed` label, if set
# 2) Deletes Branches with no activity for 3 month

# =============================================================================
# WORKFLOW CONFIGURATION
# =============================================================================

on:
schedule:
- cron: '17 * * * *' # hourly -> stale-pr
- cron: '41 4 * * *' # daily -> stale-branches
workflow_dispatch:

permissions:
contents: read

# =============================================================================
# JOBS
# =============================================================================

jobs:
stale-pr:
name: Draft Stale PRs
if: github.event_name == 'workflow_dispatch' || github.event.schedule == '17 * * * *'
runs-on: ubuntu-latest
steps:
- name: Draft stale PRs and drop deployed label
env:
GH_TOKEN: ${{ secrets.PR_WRITE_ACCESS_TOKEN }}
REPO: ${{ github.repository }}
IDLE_DAYS: "1"
run: |
set -o pipefail
gh pr list --repo "$REPO" --state open --limit 100 \
--search "updated:<$(date -u -d "$IDLE_DAYS days ago" +%Y-%m-%dT%H:%M:%SZ) sort:updated-asc" \
--json number,labels \
--jq '.[] | "\(.number) \([.labels[].name] | index("deployed") != null)"' |
while read -r pr deployed; do
echo "Cleaning idle PR #$pr"
gh pr ready "$pr" --repo "$REPO" --undo || echo "::warning::could not draft #$pr"
if [ "$deployed" = true ]; then
gh api --silent -X DELETE "repos/$REPO/issues/$pr/labels/deployed"
sleep 20 # so that cleanup don't collide on the fleet push
fi
done


stale-branches:
name: Delete Stale Branches
if: github.event_name == 'workflow_dispatch' || github.event.schedule == '41 4 * * *'
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Delete branches with no commits for MAX_AGE_DAYS
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
MAX_AGE_DAYS: "60"
run: |
set -o pipefail
CUTOFF=$(date -u -d "$MAX_AGE_DAYS days ago" +%Y-%m-%dT%H:%M:%SZ)
echo "Deleting branches with no commit since $CUTOFF"

gh api --paginate "repos/$REPO/branches?protected=false&per_page=100" \
--jq '.[].name' |
while read -r br; do
last=$(gh api "repos/$REPO/commits/$br" --jq '.commit.committer.date')
[[ "$last" < "$CUTOFF" ]] || continue
echo "Deleting $br (last commit $last)"
gh api --silent -X DELETE "repos/$REPO/git/refs/heads/$br"
done
5 changes: 0 additions & 5 deletions tests/integration/bootstrap/helm-values-tmp.yaml

This file was deleted.