-
Notifications
You must be signed in to change notification settings - Fork 0
154 lines (131 loc) · 5.28 KB
/
leetcode-move.yml
File metadata and controls
154 lines (131 loc) · 5.28 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# name: Move LeetCode Solutions
# on:
# workflow_dispatch: # 수동 실행 옵션 유지
# push:
# paths:
# - "[0-9][0-9][0-9][0-9]-*/**" # LeetHub가 생성하는 폴더 패턴 (예: 0020-valid-parentheses)
# jobs:
# move-files:
# runs-on: ubuntu-latest
# steps:
# - name: Checkout repository
# uses: actions/checkout@v3
# with:
# fetch-depth: 2 # 최근 커밋 기록을 가져오기 위해 설정
# - name: Move LeetCode solutions
# run: |
# # 디버깅을 위한 현재 디렉토리 내용 출력
# echo "Current directory contents:"
# ls -la
# # 리트코드 폴더가 없다면 생성
# mkdir -p 리트코드
# # 변경된 파일 목록 확인
# echo "Changed files in this push:"
# git diff --name-only HEAD^ HEAD
# # LeetHub가 생성한 폴더들을 LeetCode 폴더로 이동
# found=0
# for d in [0-9][0-9][0-9][0-9]-*; do
# if [ -d "$d" ]; then
# echo "Moving directory: $d"
# mv "$d" "리트코드/" && found=1
# fi
# done
# # 이동할 폴더를 찾지 못했을 경우에도 오류로 처리하지 않음
# if [ $found -eq 0 ]; then
# echo "No matching directories found to move"
# fi
# - name: Commit & Push changes
# run: |
# # 변경사항이 있는지 확인
# if git status --porcelain | grep .; then
# git config --global user.name 'github-actions[bot]'
# git config --global user.email 'github-actions[bot]@users.noreply.github.com'
# git add -A
# git commit -m "chore: Move 리트코드 solutions to 리트코드 folder"
# git push
# else
# echo "No changes to commit"
# fi
name: Move LeetCode Solutions
on:
workflow_dispatch: # 수동 실행 옵션 유지
push:
paths:
- "[0-9][0-9][0-9][0-9]-*/**" # LeetHub가 생성하는 폴더 패턴 (예: 0020-valid-parentheses)
jobs:
move-files:
runs-on: ubuntu-latest
permissions:
contents: write # 중요: 푸시 권한 명시
steps:
- name: Checkout repository
uses: actions/checkout@v4 # 최신 버전 사용
with:
fetch-depth: 0 # 전체 히스토리 가져오기
token: ${{ secrets.GITHUB_TOKEN }} # 토큰 명시
- name: Pull latest changes
run: |
echo "Pulling latest changes..."
git fetch origin
git status
echo "Current branch: $(git branch --show-current)"
git pull origin $(git branch --show-current) || echo "Pull failed, will try rebase later"
- name: Move LeetCode solutions
run: |
# 디버깅을 위한 현재 디렉토리 내용 출력
echo "Current directory contents:"
ls -la
# 리트코드 폴더가 없다면 생성
mkdir -p 리트코드
# 변경된 파일 목록 확인
echo "Changed files in this push:"
git diff --name-only HEAD~1 HEAD 2>/dev/null || echo "Unable to get diff"
# LeetHub가 생성한 폴더들을 LeetCode 폴더로 이동
found=0
for d in [0-9][0-9][0-9][0-9]-*; do
if [ -d "$d" ] && [ "$d" != "리트코드" ]; then
echo "Moving directory: $d"
# 이미 같은 이름의 폴더가 있는지 확인
if [ -d "리트코드/$d" ]; then
echo "Directory 리트코드/$d already exists, removing old one"
rm -rf "리트코드/$d"
fi
mv "$d" "리트코드/" && found=1
fi
done
# 이동할 폴더를 찾지 못했을 경우에도 오류로 처리하지 않음
if [ $found -eq 0 ]; then
echo "No matching directories found to move"
fi
- name: Commit & Push changes
run: |
# Git 설정
git config --local user.name 'github-actions[bot]'
git config --local user.email 'github-actions[bot]@users.noreply.github.com'
# 변경사항이 있는지 확인
if git status --porcelain | grep -q .; then
echo "Changes detected, committing..."
git add -A
git commit -m "chore: Move 리트코드 solutions to 리트코드 folder"
# 현재 브랜치 확인
current_branch=$(git branch --show-current)
echo "Current branch: $current_branch"
# 강제로 최신 상태 동기화
echo "Fetching latest changes..."
git fetch origin
# rebase로 충돌 해결
echo "Rebasing changes..."
git rebase origin/$current_branch || {
echo "Rebase failed, trying merge..."
git merge origin/$current_branch || {
echo "Merge also failed, using force push with lease"
git push --force-with-lease origin $current_branch
exit 0
}
}
# 정상 푸시
echo "Pushing changes..."
git push origin $current_branch
else
echo "No changes to commit"
fi