|
1 | 1 | name: Move LeetCode Solutions |
2 | 2 |
|
3 | 3 | on: |
4 | | - workflow_dispatch: # 수동 실행 옵션 유지 |
5 | 4 | push: |
6 | | - paths: |
7 | | - - '[0-9][0-9][0-9][0-9]-*/**' # LeetHub가 생성하는 폴더 패턴 (예: 0020-valid-parentheses) |
| 5 | + branches: [ main ] |
| 6 | + workflow_dispatch: |
8 | 7 |
|
9 | 8 | jobs: |
10 | | - move-files: |
| 9 | + normalize: |
11 | 10 | runs-on: ubuntu-latest |
| 11 | + |
12 | 12 | steps: |
13 | | - - name: Checkout repository |
| 13 | + - name: Checkout |
14 | 14 | uses: actions/checkout@v3 |
15 | | - with: |
16 | | - fetch-depth: 2 # 최근 커밋 기록을 가져오기 위해 설정 |
17 | 15 |
|
18 | | - - name: Move LeetCode solutions |
| 16 | + - name: Normalize LeetCode directories |
19 | 17 | run: | |
20 | | - # 디버깅을 위한 현재 디렉토리 내용 출력 |
21 | | - echo "Current directory contents:" |
22 | | - ls -la |
23 | | - |
24 | | - # LeetCode 폴더가 없다면 생성 |
| 18 | + shopt -s nullglob |
| 19 | +
|
25 | 20 | mkdir -p LeetCode |
26 | | - |
27 | | - # 변경된 파일 목록 확인 |
28 | | - echo "Changed files in this push:" |
29 | | - git diff --name-only HEAD^ HEAD |
30 | | - |
31 | | - # LeetHub가 생성한 폴더들을 LeetCode 폴더로 이동 |
32 | | - found=0 |
33 | | - for d in [0-9][0-9][0-9][0-9]-*; do |
34 | | - if [ -d "$d" ]; then |
35 | | - echo "Moving directory: $d" |
36 | | - mv "$d" "LeetCode/" && found=1 |
| 21 | +
|
| 22 | + echo "=== Before ===" |
| 23 | + ls -la |
| 24 | +
|
| 25 | + for d in ./*; do |
| 26 | + if [[ -d "$d" && "$d" =~ ^\./[0-9]{4}- ]]; then |
| 27 | + folder=$(basename "$d") |
| 28 | + target="LeetCode/$folder" |
| 29 | +
|
| 30 | + echo "Processing: $folder" |
| 31 | +
|
| 32 | + # 이미 존재하면 merge (파일만 이동) |
| 33 | + if [ -d "$target" ]; then |
| 34 | + echo "Merging into existing: $target" |
| 35 | + mv "$d"/* "$target"/ 2>/dev/null || true |
| 36 | + rm -rf "$d" |
| 37 | + else |
| 38 | + echo "Moving to: $target" |
| 39 | + mv "$d" "$target" |
| 40 | + fi |
37 | 41 | fi |
38 | 42 | done |
39 | | - |
40 | | - # 이동할 폴더를 찾지 못했을 경우에도 오류로 처리하지 않음 |
41 | | - if [ $found -eq 0 ]; then |
42 | | - echo "No matching directories found to move" |
43 | | - fi |
44 | 43 |
|
45 | | - - name: Commit & Push changes |
| 44 | + echo "=== After ===" |
| 45 | + ls -la |
| 46 | + ls -la LeetCode |
| 47 | +
|
| 48 | + - name: Commit & Push |
46 | 49 | run: | |
47 | | - # 변경사항이 있는지 확인 |
48 | 50 | if git status --porcelain | grep .; then |
49 | | - git config --global user.name 'github-actions[bot]' |
50 | | - git config --global user.email 'github-actions[bot]@users.noreply.github.com' |
51 | | - git add -A |
52 | | - git commit -m "chore: Move LeetCode solutions to LeetCode folder" |
| 51 | + git config --global user.name "github-actions[bot]" |
| 52 | + git config --global user.email "github-actions[bot]@users.noreply.github.com" |
| 53 | +
|
| 54 | + git add . |
| 55 | + git commit -m "chore: normalize LeetCode directory structure" |
53 | 56 | git push |
54 | 57 | else |
55 | | - echo "No changes to commit" |
| 58 | + echo "No changes" |
56 | 59 | fi |
0 commit comments