add yaml to sync test #2
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: Sync to Second Repository | |
| on: | |
| push: | |
| branches: | |
| - main | |
| jobs: | |
| sync: | |
| runs-on: ubuntu-latest | |
| steps: | |
| # 1. Repository 클론 | |
| - name: Checkout Source Repository | |
| uses: actions/checkout@v3 | |
| with: | |
| submodules: true | |
| fetch-depth: 0 # 모든 커밋 히스토리를 가져옴 | |
| # 2. 변경된 파일 탐지 | |
| - name: Detect Changed Files | |
| id: changes | |
| run: | | |
| if git rev-parse HEAD^ >/dev/null 2>&1; then | |
| CHANGED_FILES=$(git diff --name-only HEAD^ HEAD) | |
| else | |
| CHANGED_FILES=$(git ls-files) | |
| fi | |
| echo "changed_files=$CHANGED_FILES" >> $GITHUB_ENV | |
| # 3. 변경된 파일 복사 | |
| - name: Copy Changed Files to Second Repository | |
| run: | | |
| for FILE in $CHANGED_FILES; do | |
| # 두 번째 repository 디렉토리에 파일 복사 | |
| cp --parents "$FILE" sanghoon/ | |
| done | |
| # 4. 두 번째 repository에 변경 사항 커밋 및 Push | |
| - name: Commit and Push to Second Repository | |
| run: | | |
| cd sanghoon | |
| git config user.name "${{ github.actor }}" | |
| git config user.email "${{ github.actor }}@users.noreply.github.com" | |
| # 변경 사항 커밋 | |
| git add . | |
| git commit -m "Sync changes from first repository [skip ci]" || echo "No changes to commit" | |
| # 두 번째 repository에 push | |
| git push origin main |