@@ -2,8 +2,11 @@ name: Delete Merged Branches
2
2
3
3
on :
4
4
schedule :
5
- - cron : ' 0 0 * * *' # 매일 자정에 실행
6
- workflow_dispatch : # 수동 실행 가능
5
+ - cron : ' 0 0 * * *'
6
+ workflow_dispatch :
7
+
8
+ permissions :
9
+ contents : write
7
10
8
11
jobs :
9
12
delete-merged-branches :
@@ -13,43 +16,42 @@ jobs:
13
16
uses : actions/checkout@v3
14
17
with :
15
18
fetch-depth : 0
19
+ token : ${{ secrets.GITHUB_TOKEN }}
16
20
17
21
- name : Delete old merged branches
18
22
run : |
19
- # 시작 로그
20
23
echo "Starting branch cleanup process..."
21
24
22
25
git config --global user.name 'github-actions'
23
26
git config --global user.email '[email protected] '
24
27
25
- # develop 브랜치로 전환
26
28
echo "Switching to develop branch..."
27
29
git checkout develop
28
30
29
- # 현재 시간 기록
30
31
echo "Current time: $(date)"
31
32
32
- # 병합된 브랜치 검사 및 삭제
33
+ # 원격 브랜치 최신 정보 업데이트
34
+ git fetch --prune origin
35
+
33
36
echo "Checking for merged branches older than 7 days..."
34
37
git branch -r --merged develop | \
35
- grep -v 'main\|develop' | \
36
- grep "origin/" | \
37
- cut -d "/" -f 2- | \
38
+ grep -v 'origin/main\|origin/develop' | \
38
39
while read branch; do
39
- echo "Checking branch: $branch"
40
- last_commit_date=$(git log -1 --format=%cd origin/$branch)
40
+ branch_name=${branch#origin/}
41
+ echo "Checking branch: $branch_name"
42
+
43
+ # 마지막 커밋 날짜 확인
44
+ last_commit_date=$(git log -1 --format=%cd $branch)
41
45
echo "Last commit date: $last_commit_date"
42
46
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
+ 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"
47
50
else
48
- echo "Branch '$branch ' is still active (less than 7 days old)"
51
+ echo "Branch '$branch_name ' is still active (less than 7 days old)"
49
52
fi
50
53
done
51
54
52
- # 완료 로그
53
55
echo "Branch cleanup process completed"
54
56
env :
55
57
GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
0 commit comments