-
Notifications
You must be signed in to change notification settings - Fork 0
65 lines (53 loc) · 1.98 KB
/
move-leetcode.yml
File metadata and controls
65 lines (53 loc) · 1.98 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
name: Move LeetCode Solutions
permissions:
contents: write
on:
workflow_dispatch:
push:
paths:
- '[0-9][0-9][0-9][0-9]-*/**'
jobs:
move-files:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0 # 전체 히스토리 가져오기
persist-credentials: true # GITHUB_TOKEN으로 인증 유지
ref: ${{ github.ref_name }} # 현재 브랜치 체크아웃
- name: Move LeetCode solutions
run: |
echo "Current directory contents:"
ls -la
mkdir -p LeetCode
echo "Changed files in this push:"
# 안전하게 이전 커밋이 없을 수도 있으니 에러 무시
git diff --name-only HEAD^ HEAD || true
found=0
for d in [0-9][0-9][0-9][0-9]-*; do
if [ -d "$d" ]; then
echo "Moving directory: $d"
mv "$d" "LeetCode/" && found=1
fi
done
if [ $found -eq 0 ]; then
echo "No matching directories found to move"
fi
- name: Commit & Push changes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if git status --porcelain | grep .; then
# Commit author를 현재 액터로 설정
git config --global user.name "${{ github.actor }}"
git config --global user.email "${{ github.actor }}@users.noreply.github.com"
git add -A
git commit -m "chore: Move LeetCode solutions to LeetCode folder" || echo "No changes to commit"
# 원격의 변경사항을 rebase로 먼저 반영 (충돌 발생 시 워크플로우 실패 — 수동 해결 필요)
git pull --rebase origin "${{ github.ref_name }}" || true
# 현재 브랜치에 푸시
git push origin "${{ github.ref_name }}"
else
echo "No changes to commit"
fi