File tree Expand file tree Collapse file tree 1 file changed +55
-0
lines changed Expand file tree Collapse file tree 1 file changed +55
-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
+ jobs :
9
+ delete-merged-branches :
10
+ runs-on : ubuntu-latest
11
+ steps :
12
+ - name : Checkout code
13
+ uses : actions/checkout@v3
14
+ with :
15
+ fetch-depth : 0
16
+
17
+ - name : Delete old merged branches
18
+ run : |
19
+ # 시작 로그
20
+ echo "Starting branch cleanup process..."
21
+
22
+ git config --global user.name 'github-actions'
23
+ git config --global user.email '[email protected] '
24
+
25
+ # develop 브랜치로 전환
26
+ echo "Switching to develop branch..."
27
+ git checkout develop
28
+
29
+ # 현재 시간 기록
30
+ echo "Current time: $(date)"
31
+
32
+ # 병합된 브랜치 검사 및 삭제
33
+ echo "Checking for merged branches older than 7 days..."
34
+ git branch -r --merged develop | \
35
+ grep -v 'main\|develop' | \
36
+ grep "origin/" | \
37
+ cut -d "/" -f 2- | \
38
+ while read branch; do
39
+ echo "Checking branch: $branch"
40
+ last_commit_date=$(git log -1 --format=%cd origin/$branch)
41
+ echo "Last commit date: $last_commit_date"
42
+
43
+ if [[ $(git log -1 --since='7 days ago' origin/$branch) == "" ]]; then
44
+ echo "Branch '$branch' is older than 7 days and will be deleted"
45
+ git push origin --delete $branch
46
+ echo "Successfully deleted branch: $branch"
47
+ else
48
+ echo "Branch '$branch' is still active (less than 7 days old)"
49
+ fi
50
+ done
51
+
52
+ # 완료 로그
53
+ echo "Branch cleanup process completed"
54
+ env :
55
+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
You can’t perform that action at this time.
0 commit comments