Skip to content

workflow changes

workflow changes #6

Workflow file for this run

name: Sync Changes to different CMS repos on PR Merge
on:
pull_request:
types: [closed] # Triggers when a PR is closed
branches:
- dev # Change this to your default branch if needed
jobs:
sync-on-merge:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Check if PR was merged
id: check_merge
run: |
if [ "${{ github.event.pull_request.merged }}" = "true" ]; then
echo "PR was merged. Proceeding with sync."
echo "merged=true" >> $GITHUB_ENV
else
echo "PR was closed without merging. Skipping sync."
echo "merged=false" >> $GITHUB_ENV
fi
shell: bash
- name: Checkout migration-v2
if: env.merged == 'true'
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch full history to compare changes
- name: Detect changed files
if: env.merged == 'true'
id: file_changes
uses: dorny/paths-filter@v3
with:
filters: |
api:
- 'api/**'
cli:
- 'cli/**'
ui:
- 'ui/**'
upload-api:
- 'upload-api/src/**'
migration-sitecore:
- 'upload-api/migration-sitecore/**'
migration-contentful:
- 'upload-api/migration-contentful/**'
- name: Setup Git
if: env.merged == 'true'
run: |
git config --global user.name "github-actions"
git config --global user.email "[email protected]"
- name: Sync changes to sitecore-repo (if applicable)
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')
run: |
git clone https://x-access-token:${{ secrets.GH_PAT }}@github.com/contentstack-expert-services/migration-tool-sitecore.git
cd migration-tool-sitecore
git checkout -b sync-from-migration-v2-${{ github.event.pull_request.number }}
rsync -av --delete ../api/ ./api/
rsync -av --delete ../cli/ ./cli/
rsync -av --delete ../ui/ ./ui/
rsync -av --delete ../upload-api/src ./upload-api/src
rsync -av --delete ../upload-api/migration-sitecore ./upload-api/migration-sitecore
git add .
git commit -m "Sync changes from migration-v2 PR #${{ github.event.pull_request.number }}"
git push origin sync-from-migration-v2-${{ github.event.pull_request.number }}
- name: Create PR in sitecore-repo
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')
run: |
gh pr create --repo contentstack-expert-services/migration-tool-sitecore \
--title "Sync changes from migration-v2 PR #${{ github.event.pull_request.number }}" \
--body "This PR syncs changes from migration-v2:\n${{ github.event.pull_request.html_url }}" \
--head sync-from-migration-v2-${{ github.event.pull_request.number }} \
--base main
env:
GH_TOKEN: ${{ secrets.GH_PAT }}