Skip to content

develop → main 자동 머지 #80

develop → main 자동 머지

develop → main 자동 머지 #80

Workflow file for this run

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
actions: write # deploy.yml 수동 트리거용
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'
# rm -rf 없이 git checkout만 하면 develop에만 있고 main엔 없는 파일이 그대로 남아,
# 옛 콘텐츠가 새 authors.yml·sidebar와 충돌해 빌드 게이트가 깨진다.
run: |
rm -rf docs blog static/img
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 머지
id: merge
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 -m "chore: develop → main 머지 [skip-notion]"; 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 -m "chore: develop → main 머지 (sync-json 충돌 자동 해소) [skip-notion]"
git push origin main
# GITHUB_TOKEN push 는 deploy.yml(on: push)을 트리거하지 못한다 (워크플로 재귀 방지).
# workflow_dispatch 는 예외라 명시 호출로 배포를 잇는다.
- name: Trigger deploy
if: steps.merge.outcome == 'success' && steps.diff.outputs.has_changes == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh workflow run deploy.yml --ref main