mirror of
https://github.com/nubenetes/awesome-kubernetes.git
synced 2026-07-13 18:30:44 +00:00
Bumps the action-updates group with 3 updates: [actions/checkout](https://github.com/actions/checkout), [actions/cache](https://github.com/actions/cache) and [peter-evans/repository-dispatch](https://github.com/peter-evans/repository-dispatch). Updates `actions/checkout` from 6 to 7 - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v6...v7) Updates `actions/cache` from 5 to 6 - [Release notes](https://github.com/actions/cache/releases) - [Changelog](https://github.com/actions/cache/blob/main/RELEASES.md) - [Commits](https://github.com/actions/cache/compare/v5...v6) Updates `peter-evans/repository-dispatch` from 3 to 4 - [Release notes](https://github.com/peter-evans/repository-dispatch/releases) - [Commits](https://github.com/peter-evans/repository-dispatch/compare/v3...v4) --- updated-dependencies: - dependency-name: actions/checkout dependency-version: '7' dependency-type: direct:production update-type: version-update:semver-major dependency-group: action-updates - dependency-name: actions/cache dependency-version: '6' dependency-type: direct:production update-type: version-update:semver-major dependency-group: action-updates - dependency-name: peter-evans/repository-dispatch dependency-version: '4' dependency-type: direct:production update-type: version-update:semver-major dependency-group: action-updates ... Signed-off-by: dependabot[bot] <support@github.com>
76 lines
3.0 KiB
YAML
76 lines
3.0 KiB
YAML
name: 08.1. Branch Lifecycle Cleanup
|
|
|
|
on:
|
|
schedule:
|
|
# Runs at 00:00 on day 1 and 15 of every month
|
|
- cron: '0 0 1,15 * *'
|
|
workflow_dispatch: # Allow manual trigger for testing
|
|
|
|
jobs:
|
|
cleanup:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v7
|
|
with:
|
|
ref: develop # Operamos sobre develop para usar la lógica de limpieza más reciente
|
|
fetch-depth: 0
|
|
|
|
- name: Delete merged and stale branches
|
|
env:
|
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
run: |
|
|
git config --global user.name "github-actions[bot]"
|
|
git config --global user.email "github-actions[bot]@users.noreply.github.com"
|
|
|
|
echo "Fetching latest changes..."
|
|
git fetch --prune
|
|
|
|
current_date=$(date +%s)
|
|
stale_seconds=$((30 * 24 * 60 * 60)) # 30 days
|
|
|
|
echo "Auditing remote branches..."
|
|
# Get all remote branches (excluding protected ones)
|
|
branches=$(git branch -r | grep -vE 'origin/(master|develop|gh-pages|HEAD)' | sed 's/.*origin\///')
|
|
|
|
for branch in $branches; do
|
|
echo "[*] Checking branch: $branch"
|
|
|
|
# 1. Check if it's merged into develop (Git check)
|
|
if git branch -r --merged origin/develop | grep -q "origin/$branch"; then
|
|
echo " [+] Branch is merged in git. Deleting..."
|
|
git push origin --delete "$branch"
|
|
continue
|
|
fi
|
|
|
|
# 2. Check PR status via GitHub CLI
|
|
# Returns state (OPEN, CLOSED, MERGED) and PR number
|
|
pr_info=$(gh pr list --head "$branch" --state all --json state,number --jq '.[0] | "\(.state) \(.number)"' 2>/dev/null || echo "")
|
|
|
|
if [ -n "$pr_info" ] && [ "$pr_info" != "null null" ]; then
|
|
state=$(echo "$pr_info" | cut -d' ' -f1)
|
|
number=$(echo "$pr_info" | cut -d' ' -f2)
|
|
|
|
if [ "$state" == "OPEN" ]; then
|
|
echo " [-] Skipping: Open PR found (#$number)"
|
|
continue
|
|
elif [ "$state" == "CLOSED" ] || [ "$state" == "MERGED" ]; then
|
|
echo " [+] Deleting: Associated PR #$number is $state"
|
|
git push origin --delete "$branch"
|
|
continue
|
|
fi
|
|
fi
|
|
|
|
# 3. If no PR, check stale inactivity (30 days)
|
|
last_commit_unix=$(git log -1 --format=%at "origin/$branch")
|
|
age=$((current_date - last_commit_unix))
|
|
|
|
if [ "$age" -gt "$stale_seconds" ]; then
|
|
last_date=$(date -d "@$last_commit_unix" +"%Y-%m-%d")
|
|
echo " [+] Deleting stale branch (No PR, Inactive since $last_date)"
|
|
git push origin --delete "$branch"
|
|
else
|
|
echo " [-] Keeping: Active branch (No PR, last commit less than 30 days ago)"
|
|
fi
|
|
done
|