-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
17 additions
and
9 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,8 @@ name: Clear Branch | |
|
||
on: | ||
push: | ||
- ci-test | ||
branches: | ||
- ci-test | ||
workflow_dispatch: | ||
inputs: | ||
ref: | ||
|
@@ -13,22 +14,29 @@ jobs: | |
clear_branch: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout the repository | ||
uses: actions/checkout@v3 | ||
- name: Configure Git | ||
run: | | ||
git config user.name "$GITHUB_ACTOR" | ||
git config user.email "[email protected]" | ||
- name: Authenticate GitHub CLI | ||
- name: Get protected branches | ||
id: get_protected_branches | ||
run: | | ||
echo "$GITHUB_TOKEN" | gh auth login --with-token | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
# Get the list of protected branches | ||
protected_branches=$(gh api /repos/${{ github.repository }}/branches --jq '.[] | select(.protected == true) | .name' | tr '\n' ' ') | ||
echo "PROTECTED_BRANCHES=${protected_branches}" >> $GITHUB_ENV | ||
- name: List all branches | ||
run: | | ||
git fetch --prune | ||
for branch in $(git branch -r | grep -v 'HEAD\|main\|master\|ci-test' | sed 's/origin\///'); do | ||
for branch in $(git branch -r | sed 's/origin\///'|grep -v origin); do | ||
if [[ " ${protected_branches_array[@]} " =~ " ${branch} " ]]; then | ||
echo "Skipping protected branch: $branch" | ||
continue | ||
fi | ||
last_commit_date=$(git log -1 --format=%ci origin/$branch) | ||
if [[ $(date -d "$last_commit_date" +%s) -lt $(date -d "1 month ago" +%s) ]]; then | ||
if ! gh pr list --head $branch --repo https://github.com/jiumos/draw/ | grep $branch; then | ||
if ! gh pr list --head $branch --repo https://github.com//${{ github.repository }} | grep $branch; then | ||
echo "Deleting branch: $branch" | ||
git push origin --delete $branch | ||
fi | ||
|