develop → main 자동 머지 #5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: develop → main 자동 머지 | |
| # docs/ blog/ static/img/ 제외한 코드 변경이 develop에 있을 때만 | |
| # npm run build 통과 후 main으로 머지한다. | |
| on: | |
| schedule: | |
| - cron: '0 2 * * *' # 매일 UTC 02:00 = KST 11:00 | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| jobs: | |
| merge: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout develop | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: develop | |
| fetch-depth: 0 | |
| - name: 코드 변경 감지 (콘텐츠 디렉토리 제외) | |
| id: diff | |
| run: | | |
| git fetch origin main | |
| DIFF=$(git diff origin/main..HEAD -- . \ | |
| ':(exclude)docs/' \ | |
| ':(exclude)blog/' \ | |
| ':(exclude)static/img/') | |
| if [ -z "$DIFF" ]; then | |
| echo "has_changes=false" >> $GITHUB_OUTPUT | |
| echo "변경 없음 — 머지 스킵" | |
| else | |
| echo "has_changes=true" >> $GITHUB_OUTPUT | |
| echo "코드 변경 감지 — 빌드 후 머지 진행" | |
| fi | |
| - name: Setup Node.js | |
| if: steps.diff.outputs.has_changes == 'true' | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| cache: npm | |
| - name: Install dependencies | |
| if: steps.diff.outputs.has_changes == 'true' | |
| run: npm ci | |
| - name: Checkout docs/ from main (빌드용 콘텐츠) | |
| if: steps.diff.outputs.has_changes == 'true' | |
| run: git checkout origin/main -- docs/ blog/ static/img/ | |
| - name: Build gate | |
| if: steps.diff.outputs.has_changes == 'true' | |
| run: npm run build | |
| - name: develop → main 머지 | |
| if: steps.diff.outputs.has_changes == 'true' | |
| run: | | |
| git stash | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git checkout main | |
| git pull origin main | |
| if git merge develop --no-edit; then | |
| git push origin main | |
| echo "머지 완료 (충돌 없음)" | |
| exit 0 | |
| fi | |
| # 충돌 발생 — .notion-sync.json 이외의 충돌 파일 확인 | |
| NON_SYNC=$(git diff --name-only --diff-filter=U | grep -v '\.notion-sync\.json$' || true) | |
| if [ -n "$NON_SYNC" ]; then | |
| echo "실제 충돌 감지 — 수동 해결 필요:" | |
| echo "$NON_SYNC" | |
| exit 1 | |
| fi | |
| # .notion-sync.json 충돌만 존재 → main 버전 유지 | |
| echo ".notion-sync.json 충돌 자동 해소 (main 버전 유지)" | |
| git diff --name-only --diff-filter=U | xargs -r git checkout --ours -- | |
| git add -A | |
| git commit --no-edit | |
| git push origin main |