diff --git a/.github-new/workflows/pull-v4-into-v4-next.yml b/.github-new/workflows/pull-v4-into-v4-next.yml new file mode 100644 index 000000000000..efa6bdefb2b6 --- /dev/null +++ b/.github-new/workflows/pull-v4-into-v4-next.yml @@ -0,0 +1,110 @@ +name: Pull v4 into v4-next + +on: + schedule: + # Run every 15 minutes to catch v4 merges promptly + - cron: '*/15 * * * *' + workflow_dispatch: + +permissions: + contents: write + pull-requests: write + +jobs: + pull-v4-into-v4-next: + runs-on: ubuntu-latest + steps: + - name: Checkout v4-next + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 + with: + ref: v4-next + fetch-depth: 0 + token: ${{ secrets.AZTEC_BOT_GITHUB_TOKEN }} + + - name: Configure Git + run: | + git config user.name "AztecBot" + git config user.email "tech@aztecprotocol.com" + + - name: Check if v4 is ahead of v4-next + id: check + run: | + git fetch origin v4 + AHEAD=$(git rev-list --count v4-next..origin/v4) + echo "ahead=$AHEAD" + if [ "$AHEAD" -eq 0 ]; then + echo "v4-next is already up to date with v4." + echo "needs_merge=false" >> $GITHUB_OUTPUT + else + echo "v4 is $AHEAD commit(s) ahead of v4-next." + echo "needs_merge=true" >> $GITHUB_OUTPUT + fi + + - name: Attempt to merge v4 into v4-next + if: steps.check.outputs.needs_merge == 'true' + id: merge + run: | + if git merge origin/v4 --no-edit; then + echo "conflict=false" >> $GITHUB_OUTPUT + echo "Merge succeeded without conflicts." + else + git merge --abort + echo "conflict=true" >> $GITHUB_OUTPUT + echo "Merge has conflicts." + fi + + - name: Push merged v4-next + if: steps.check.outputs.needs_merge == 'true' && steps.merge.outputs.conflict == 'false' + run: git push origin v4-next + + - name: Create conflict-resolution PR + if: steps.check.outputs.needs_merge == 'true' && steps.merge.outputs.conflict == 'true' + id: conflict-pr + env: + GH_TOKEN: ${{ secrets.AZTEC_BOT_GITHUB_TOKEN }} + run: | + SYNC_BRANCH="sync/v4-into-v4-next-$(date -u +%Y%m%d-%H%M%S)" + git merge --abort 2>/dev/null || true + git checkout -b "$SYNC_BRANCH" + + # Merge with conflicts left in place + git merge origin/v4 --no-commit --no-ff || true + git add -A + git commit -m "chore: merge v4 into v4-next (conflicts need resolution)" || true + git push origin "$SYNC_BRANCH" + + # Check if there's already an open sync PR by branch naming convention + EXISTING_PR=$(gh pr list --base v4-next --state open --json number,headRefName --jq '[.[] | select(.headRefName | startswith("sync/v4-into-v4-next-"))][0].number // empty') + + if [ -n "$EXISTING_PR" ]; then + gh pr comment "$EXISTING_PR" --body "New v4 changes pushed. A fresh sync branch \`$SYNC_BRANCH\` has been created. Please resolve conflicts there or close this PR and use the new branch." + echo "pr_url=$(gh pr view "$EXISTING_PR" --json url --jq '.url')" >> $GITHUB_OUTPUT + else + PR_URL=$(gh pr create \ + --base v4-next \ + --head "$SYNC_BRANCH" \ + --title "chore: merge v4 into v4-next (resolve conflicts)" \ + --body "$(cat <<'EOF' +## Automatic v4 → v4-next sync + +This PR was created because merging `v4` into `v4-next` resulted in conflicts. + +Please resolve the conflicts and merge this PR to keep `v4-next` up to date. + +This PR was auto-generated by the `pull-v4-into-v4-next` workflow. +EOF + )") + echo "pr_url=$PR_URL" >> $GITHUB_OUTPUT + fi + + - name: Notify Slack + if: steps.check.outputs.needs_merge == 'true' && steps.merge.outputs.conflict == 'true' + env: + SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} + run: | + PR_URL="${{ steps.conflict-pr.outputs.pr_url }}" + TEXT=$(printf '⚠️ Auto-merge v4 → v4-next failed due to conflicts. <%s|View PR>. @Claudebox' "$PR_URL") + curl -sS -X POST https://slack.com/api/chat.postMessage \ + -H "Authorization: Bearer $SLACK_BOT_TOKEN" \ + -H "Content-type: application/json" \ + -d "$(jq -n --arg c "#backports" --arg t "$TEXT" '{channel:$c, text:$t}')"