Skip to content

Commit b5f155e

Browse files
committed
✨Feat: 권한 설정 추가
1 parent f0c9dfc commit b5f155e

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

.github/workflows/delete_branch.yml

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ name: Delete Merged Branches
22

33
on:
44
schedule:
5-
- cron: '0 0 * * *' # 매일 자정에 실행
6-
workflow_dispatch: # 수동 실행 가능
5+
- cron: '0 0 * * *'
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: write
710

811
jobs:
912
delete-merged-branches:
@@ -13,43 +16,42 @@ jobs:
1316
uses: actions/checkout@v3
1417
with:
1518
fetch-depth: 0
19+
token: ${{ secrets.GITHUB_TOKEN }}
1620

1721
- name: Delete old merged branches
1822
run: |
19-
# 시작 로그
2023
echo "Starting branch cleanup process..."
2124
2225
git config --global user.name 'github-actions'
2326
git config --global user.email '[email protected]'
2427
25-
# develop 브랜치로 전환
2628
echo "Switching to develop branch..."
2729
git checkout develop
2830
29-
# 현재 시간 기록
3031
echo "Current time: $(date)"
3132
32-
# 병합된 브랜치 검사 및 삭제
33+
# 원격 브랜치 최신 정보 업데이트
34+
git fetch --prune origin
35+
3336
echo "Checking for merged branches older than 7 days..."
3437
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' | \
3839
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)
4145
echo "Last commit date: $last_commit_date"
4246
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"
4750
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)"
4952
fi
5053
done
5154
52-
# 완료 로그
5355
echo "Branch cleanup process completed"
5456
env:
5557
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)