-
Notifications
You must be signed in to change notification settings - Fork 0
57 lines (45 loc) · 1.76 KB
/
delete_branch.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
name: Delete Merged Branches
on:
schedule:
- cron: '0 0 * * *'
workflow_dispatch:
permissions:
contents: write
jobs:
delete-merged-branches:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Delete old merged branches
run: |
echo "Starting branch cleanup process..."
git config --global user.name 'github-actions'
git config --global user.email 'github-actions@github.com'
echo "Switching to develop branch..."
git checkout develop
echo "Current time: $(date)"
# 원격 브랜치 최신 정보 업데이트
git fetch --prune origin
echo "Checking for merged branches older than 7 days..."
git branch -r --merged develop | \
grep -v 'origin/main\|origin/develop' | \
while read branch; do
branch_name=${branch#origin/}
echo "Checking branch: $branch_name"
# 마지막 커밋 날짜 확인
last_commit_date=$(git log -1 --format=%cd $branch)
echo "Last commit date: $last_commit_date"
if [[ $(git log -1 --since='7 days ago' $branch) == "" ]]; then
echo "Branch '$branch_name' is older than 7 days and will be deleted"
git push origin --delete $branch_name || echo "Failed to delete branch: $branch_name"
else
echo "Branch '$branch_name' is still active (less than 7 days old)"
fi
done
echo "Branch cleanup process completed"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}