|
| 1 | +name: Sync Changes to different CMS repos on PR Merge |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [closed] # Triggers when a PR is closed |
| 6 | + branches: |
| 7 | + - dev # Change this to your default branch if needed |
| 8 | + |
| 9 | +jobs: |
| 10 | + sync-on-merge: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + |
| 13 | + permissions: |
| 14 | + contents: write |
| 15 | + pull-requests: write |
| 16 | + |
| 17 | + steps: |
| 18 | + - name: Check if PR was merged |
| 19 | + id: check_merge |
| 20 | + run: | |
| 21 | + if [ "${{ github.event.pull_request.merged }}" = "true" ]; then |
| 22 | + echo "PR was merged. Proceeding with sync." |
| 23 | + echo "merged=true" >> $GITHUB_ENV |
| 24 | + else |
| 25 | + echo "PR was closed without merging. Skipping sync." |
| 26 | + echo "merged=false" >> $GITHUB_ENV |
| 27 | + fi |
| 28 | + shell: bash |
| 29 | + |
| 30 | + - name: Checkout migration-v2 |
| 31 | + if: env.merged == 'true' |
| 32 | + uses: actions/checkout@v4 |
| 33 | + with: |
| 34 | + fetch-depth: 0 # Fetch full history to compare changes |
| 35 | + |
| 36 | + - name: Detect changed files |
| 37 | + if: env.merged == 'true' |
| 38 | + id: file_changes |
| 39 | + uses: dorny/paths-filter@v3 |
| 40 | + with: |
| 41 | + filters: | |
| 42 | + api: |
| 43 | + - 'api/**' |
| 44 | + cli: |
| 45 | + - 'cli/**' |
| 46 | + ui: |
| 47 | + - 'ui/**' |
| 48 | + upload-api: |
| 49 | + - 'upload-api/src/** |
| 50 | + migration-sitecore: |
| 51 | + - 'upload-api/migration-sitecore/**' |
| 52 | + migration-contentful: |
| 53 | + - 'upload-api/migration-contentful/**' |
| 54 | +
|
| 55 | + - name: Setup Git |
| 56 | + if: env.merged == 'true' |
| 57 | + run: | |
| 58 | + git config --global user.name "github-actions" |
| 59 | + git config --global user.email "[email protected]" |
| 60 | +
|
| 61 | + - name: Sync changes to sitecore-repo (if applicable) |
| 62 | + if: env.merged == 'true' && (steps.file_changes.outputs.api == 'true' || steps.file_changes.outputs.cli == 'true' || steps.file_changes.outputs.ui == 'true' || steps.file_changes.outputs.upload-api == 'true' || steps.file_changes.outputs.migration-sitecore == 'true') |
| 63 | + run: | |
| 64 | + git clone https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/contentstack-expert-services/migration-tool-sitecore.git |
| 65 | + cd migration-tool-sitecore |
| 66 | + git checkout -b sync-from-migration-v2-${{ github.event.pull_request.number }} |
| 67 | + rsync -av --delete ../api/ ./api/ |
| 68 | + rsync -av --delete ../cli/ ./cli/ |
| 69 | + rsync -av --delete ../ui/ ./ui/ |
| 70 | + rsync -av --delete ../upload-api/src ./upload-api/src |
| 71 | + rsync -av --delete ../upload-api/migration-sitecore ./upload-api/migration-sitecore |
| 72 | + git add . |
| 73 | + git commit -m "Sync changes from migration-v2 PR #${{ github.event.pull_request.number }}" |
| 74 | + git push origin sync-from-migration-v2-${{ github.event.pull_request.number }} |
| 75 | +
|
| 76 | + - name: Create PR in sitecore-repo |
| 77 | + if: env.merged == 'true' && (steps.file_changes.outputs.api == 'true' || steps.file_changes.outputs.cli == 'true' || steps.file_changes.outputs.ui == 'true' || steps.file_changes.outputs.upload-api == 'true' || steps.file_changes.outputs.migration-sitecore == 'true') |
| 78 | + run: | |
| 79 | + gh pr create --repo org/sitecore-repo \ |
| 80 | + --title "Sync changes from migration-v2 PR #${{ github.event.pull_request.number }}" \ |
| 81 | + --body "This PR syncs changes from migration-v2:\n${{ github.event.pull_request.html_url }}" \ |
| 82 | + --head sync-from-migration-v2-${{ github.event.pull_request.number }} \ |
| 83 | + --base main |
| 84 | + env: |
| 85 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 86 | + |
| 87 | + # - name: Sync changes to repo-3 (if applicable) |
| 88 | + # if: env.merged == 'true' && (steps.file_changes.outputs.common == 'true' || steps.file_changes.outputs.child_2 == 'true') |
| 89 | + # run: | |
| 90 | + # git clone https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/RohitKini/migration-github-workflow-variant2.git |
| 91 | + # git checkout -b sync-from-migration-v2-${{ github.event.pull_request.number }} |
| 92 | + # rsync -av --delete ../common/ ./common/ |
| 93 | + # rsync -av --delete ../child_2/ ./child_2/ |
| 94 | + # git add . |
| 95 | + # git commit -m "Sync changes from migration-v2 PR #${{ github.event.pull_request.number }}" |
| 96 | + # git push origin sync-from-migration-v2-${{ github.event.pull_request.number }} |
| 97 | + |
| 98 | + # - name: Create PR in repo-3 |
| 99 | + if: env.merged == 'true' && (steps.file_changes.outputs.common == 'true' || steps.file_changes.outputs.child_2 == 'true') |
| 100 | + run: | |
| 101 | + gh pr create --repo org/repo-3 \ |
| 102 | + --title "Sync changes from migration-v2 PR #${{ github.event.pull_request.number }}" \ |
| 103 | + --body "This PR syncs changes from migration-v2:\n${{ github.event.pull_request.html_url }}" \ |
| 104 | + --head sync-from-migration-v2-${{ github.event.pull_request.number }} \ |
| 105 | + --base main |
| 106 | + env: |
| 107 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments