name: Push to forked Repo
on:
push:
branches: [main]
jobs:
push-to-personal-repo:
runs-on: ubuntu-latest
steps:
- name: Checkout Frontend repo
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Clone main Repo
run: |
git clone https://github.com/staccato20/FitnessMate-FE-Deploy main
- name: Remove all files in main Repo
run: |
rm -rf main/* # 기존 파일 모두 삭제
- name: Copy changes to main Repo
run: |
rsync -av --delete --exclude='.git' --exclude='node_modules/' --exclude='main/' . main/
ls -al main/ # 복사된 파일 목록 확인
- name: Commit and Push changes to main repo main branch
run: |
cd main
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.github.com"
git status # 변경된 파일 목록 확인
git add -A # 모든 변경 사항 추가
git commit -m "Update from Frontend repo by ${{ github.actor }}" || echo "No changes to commit"
git push https://x-access-token:${{ secrets.FITMATE_STACCATO20 }}@github.com/staccato20/FitnessMate-FE-Deploy.git main
해당 액션은 organization의 main 브랜치에 push 가 되었을때 실행된다.
Vercel로 배포를 하고 있는데 팀 레포(organization)를 대상으로 배포하면 프로 계정을 사야하고 가격이 비싸서 팀 레포와 개인 레포를 연동해서 사용하고 있다.
즉, 배포 대상은 fork한 개인 레포로 두고, 팀 레포의 main에 push가 되면 해당 내용을 복사해서 개인 레포의 main에 옮기는 방식이다. 이렇게 하면, 자동으로 배포가 된다.
과정을 순서대로 설명하자면,
현재 레포지토리의 모든 커밋 히스토리 가져오기
현재 레포지토리의 기본 브랜치(main)를 복사(clone) (참고로 여기서 맨 뒤에 붙은 main은 임의로 설정한 디렉토리 이름으로 배포 레포지토리에 보낼 내용을 담은 디렉토리다.)
복사한 내용 전체 삭제
현재 최신 커밋이 반영된 레포지토리를 main 레포지토리에 복사(동기화)
커밋 과 푸시
checkout 과 git clone 이 혼재git clone이 불필요함.checkout 모든 커밋 이력을 가져옴git push origin main 으로 push 처리name: Push to deploy Repo
on:
push:
branches: [main]
jobs:
push-to-personal-repo:
runs-on: ubuntu-latest
steps:
- name: Checkout develop repo
uses: actions/checkout@v2
with:
fetch-depth: 1
- name: Copy changes to deploy Repo
run: |
rsync -av --delete --exclude='.git' --exclude='node_modules/' --progress . clone/
ls -al clone/
- name: Commit and Push changes to deploy repo main branch
run: |
cd clone
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.github.com"
git status
git add -A
git commit -m "Update from Frontend repo by ${{ github.actor }}" || echo "No changes to commit"
git push origin main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

오류가 나서 보니까 배포 레포지토리의 main 브랜치가 현재 Protected Branch로 설정되어있어 직접 push가 안된다는 것이다.
protect를 해제해 해결하였다.