Merge pull request #3708 from SalesforceCommerceCloud/avinash.W-21430145 #442
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 Extra Features E2E Branch with Develop | |
| on: | |
| # Trigger when develop branch is updated | |
| push: | |
| branches: | |
| - develop | |
| # Run daily at 11 PM PST (7 AM UTC) to catch any missed syncs | |
| schedule: | |
| - cron: '0 7 * * *' | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| issues: write | |
| pull-requests: read | |
| jobs: | |
| sync-branch: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Configure git | |
| run: | | |
| git config --global user.name ${{ secrets.GIT_CONFIG_USERNAME }} | |
| git config --global user.email ${{ secrets.GIT_CONFIG_EMAIL }} | |
| - name: Sync extra-features-e2e-branch with develop | |
| id: sync | |
| continue-on-error: true | |
| run: | | |
| set -e | |
| # Fetch all branches | |
| git fetch origin | |
| # Check if the target branch exists | |
| if ! git show-ref --verify --quiet refs/remotes/origin/extra-features-e2e-branch; then | |
| echo "Branch extra-features-e2e-branch does not exist. Creating it from develop..." | |
| git checkout -b extra-features-e2e-branch origin/develop | |
| git push origin extra-features-e2e-branch | |
| echo "✅ Created extra-features-e2e-branch branch from develop" | |
| echo "status=created" >> $GITHUB_OUTPUT | |
| exit 0 | |
| fi | |
| # Switch to the target branch | |
| git checkout extra-features-e2e-branch | |
| git reset --hard origin/extra-features-e2e-branch | |
| # Check if we're already up to date | |
| if git merge-base --is-ancestor origin/develop HEAD; then | |
| echo "✅ extra-features-e2e-branch is already up to date with develop" | |
| echo "status=up-to-date" >> $GITHUB_OUTPUT | |
| exit 0 | |
| fi | |
| if git merge origin/develop --no-edit; then | |
| echo "✅ Successfully merged develop into extra-features-e2e-branch" | |
| git push origin extra-features-e2e-branch | |
| echo "status=merged" >> $GITHUB_OUTPUT | |
| else | |
| echo "❌ Merge conflicts detected!" | |
| echo "📋 Files with conflicts:" | |
| git diff --name-only --diff-filter=U || true | |
| git merge --abort | |
| echo "status=conflict" >> $GITHUB_OUTPUT | |
| exit 1 | |
| fi | |
| - name: Create conflict resolution issue | |
| if: steps.sync.outputs.status == 'conflict' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const conflictFiles = `${{ steps.sync.outputs.conflict_files || 'Unknown files' }}`; | |
| const issueBody = ` | |
| ## 🚨 Automatic Sync Failed - Merge Conflicts Detected | |
| Some features in PWA kit are defaulted to be off in \`develop\` branch (e.g. if they only work with private client). | |
| Hence there is another site that has these features enabled that E2E tests of these extra features are run against. | |
| The \`extra-features-e2e-branch\` is used for this site. | |
| A job is run nightly to sync \`develop\` to \`extra-features-e2e-branch\` branch, but today this automatic sync from \`develop\` to \`extra-features-e2e-branch\` failed due to merge conflicts. | |
| ### Conflicting Files: | |
| \`\`\` | |
| ${conflictFiles} | |
| \`\`\` | |
| ### Manual Resolution: | |
| \`\`\`bash | |
| git checkout extra-features-e2e-branch | |
| git pull origin extra-features-e2e-branch | |
| git merge develop | |
| # Resolve conflicts manually | |
| git add . | |
| git commit -m "Resolve merge conflicts from develop" | |
| git push origin extra-features-e2e-branch | |
| \`\`\` | |
| ### After resolving the conflicts, close this issue | |
| `; | |
| // Check if issue already exists | |
| const existingIssues = await github.rest.issues.listForRepo({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| state: 'open', | |
| labels: 'sync-conflict' | |
| }); | |
| if (existingIssues.data.length === 0) { | |
| await github.rest.issues.create({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| title: '🚨 Extra Features E2E Branch Sync Conflict - Manual Resolution Required', | |
| body: issueBody, | |
| labels: ['sync-conflict', 'automation'] | |
| }); | |
| } | |
| deploy: | |
| needs: sync-branch | |
| if: needs.sync-branch.outputs.status != 'conflict' && needs.sync-branch.outputs.status != 'up-to-date' | |
| runs-on: ubuntu-latest | |
| environment: extra-features-e2e | |
| steps: | |
| - name: Checkout extra-features-e2e-branch branch | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: extra-features-e2e-branch | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 24 | |
| cache: 'npm' | |
| - name: Install Monorepo Dependencies | |
| run: | | |
| # Install node dependencies | |
| node ./scripts/gtime.js monorepo_install npm ci | |
| - name: Build project | |
| run: | | |
| cd packages/template-retail-react-app | |
| npm run build | |
| - name: Create MRT credentials file | |
| uses: "./.github/actions/create_mrt" | |
| with: | |
| mobify_user: ${{ secrets.MOBIFY_CLIENT_USER }} | |
| mobify_api_key: ${{ secrets.MOBIFY_CLIENT_API_KEY }} | |
| - name: Deploy to MRT | |
| uses: "./.github/actions/push_to_mrt" | |
| with: | |
| CWD: "./packages/template-retail-react-app" | |
| TARGET: extra-features-e2e | |
| PROJECT: scaffold-pwa | |
| MESSAGE: "Auto-sync from develop - build ${{ github.run_id }} (${{ github.sha }})" | |
| FLAGS: --wait |