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