chore(ci): sync alpha branch from main on every push#1089
Conversation
Best-effort script to rebase all commits from main into the alpha branch, push to a timestamped work branch, and open a PR against alpha for human review and conflict resolution. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Triggers on every push to main. Creates a timestamped branch off alpha, attempts a rebase of main's new commits, falls back to merge on conflict, and opens a PR against alpha for human review. Skips if an open sync PR already exists. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
|
Caution Review failedPull request was closed or merged during review WalkthroughAdds automation to synchronize commits from Changes
Sequence Diagram(s)sequenceDiagram
participant GH as GitHub (main push)
participant WF as GitHub Actions Workflow
participant Git as Local Git
participant GHCli as GitHub CLI
participant Remote as Remote Repo
GH->>WF: Trigger on push or manual dispatch
WF->>Git: Fetch origin/main and origin/alpha
Git->>Remote: Retrieve branch SHAs
Remote-->>Git: Return SHAs and merge-base
Git-->>WF: Provide commit_count, SHAs
alt sync needed
WF->>GHCli: Query open PRs (base=alpha, head prefix)
GHCli-->>WF: PR exists? (yes/no)
alt no existing PR
WF->>Git: Create timestamped work branch from alpha
Git->>Git: Compute MERGE_BASE and attempt rebase --onto
alt rebase clean
Git-->>WF: rebase_clean=true
else rebase conflicts
Git-->>WF: rebase_clean=false
WF->>Git: Stage files, git rebase --abort
WF->>Git: Attempt git merge origin/main (fallback)
end
WF->>Git: Push work branch
Git->>Remote: Push branch
WF->>GHCli: gh pr create -> target alpha
GHCli->>Remote: Open PR
else PR exists
WF-->>WF: Skip branch/PR creation
end
else no sync needed
WF-->>WF: Alpha already in sync
end
WF->>WF: Write status to GITHUB_STEP_SUMMARY
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In @.github/workflows/sync-alpha-from-main.yml:
- Around line 102-114: The workflow YAML fails because the inline multiline
commit messages in the git merge and git commit commands break YAML parsing;
change those -m "..." uses to a heredoc form so the YAML sees a single-line
shell command (e.g. replace the git merge -m "multi-line..." and git commit -m
"multi-line..." occurrences with heredoc usage like git merge --no-ff
--allow-unrelated-histories origin/main -m "$(cat <<'MSG' ... MSG)" or use
<<'MSG' for the commit message) so the multiline text is handled by the shell,
not the YAML parser.
In `@scripts/rebase-main-to-alpha.sh`:
- Line 61: The git rebase invocation has the --onto flag placed after a
positional argument; move --onto to directly follow git rebase and reorder the
positional arguments so the new base (WORK_BRANCH) is passed to --onto first,
followed by the upstream branch (UPSTREAM/MAIN_BRANCH) and then the branch/range
being rebased (MERGE_BASE) so the correct commit range from main is replayed
onto WORK_BRANCH.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 8250be81-ae28-401c-b705-fab858408514
📒 Files selected for processing (2)
.github/workflows/sync-alpha-from-main.ymlscripts/rebase-main-to-alpha.sh
scripts/rebase-main-to-alpha.sh
Outdated
| # Attempt rebase of main onto the work branch (best-effort) | ||
| log "Rebasing ${UPSTREAM}/${MAIN_BRANCH} onto ${WORK_BRANCH} (best-effort)..." | ||
| REBASE_EXIT=0 | ||
| git rebase "${UPSTREAM}/${MAIN_BRANCH}" --onto "${WORK_BRANCH}" "${MERGE_BASE}" || REBASE_EXIT=$? |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
cat -n scripts/rebase-main-to-alpha.shRepository: ambient-code/platform
Length of output: 5907
🌐 Web query:
git rebase --onto syntax argument order documentation
💡 Result:
The syntax for git rebase --onto is: git rebase [--onto ] [] [] When using --onto, the argument order is: 1. --onto (the new base commit where rebased commits will be placed on top) 2. (the old base; commits reachable from are excluded from rebasing; defaults to if --onto omitted) 3. (the branch/commits to rebase; defaults to HEAD or current branch) Examples from official docs: - git rebase --onto master next topic rebases commits in topic since it diverged from next, onto master. - git rebase --onto master topicA topicB rebases commits in topicB since topicA, onto master. If is given, Git switches to it first. The range rebased is commits reachable from (exclusive ). Note: --onto and --keep-base/--root are incompatible in some cases.
Citations:
- 1: https://git-scm.com/docs/git-rebase
- 2: https://git-scm.com/docs/git-rebase.html
- 3: https://git-scm.com/docs/git-rebase/2.33.1.html
- 4: https://linux.die.net/man/1/git-rebase
Fix git rebase --onto argument order to replay the correct commit range.
Line 61 places the --onto flag after a positional argument, which violates git rebase syntax. The --onto option must come immediately after git rebase for correct parsing and behavior. Without this fix, the command fails to reliably replay main's commits onto WORK_BRANCH, forcing an unnecessary fallback to merge.
Suggested fix
-git rebase "${UPSTREAM}/${MAIN_BRANCH}" --onto "${WORK_BRANCH}" "${MERGE_BASE}" || REBASE_EXIT=$?
+git rebase --onto "${WORK_BRANCH}" "${MERGE_BASE}" "${UPSTREAM}/${MAIN_BRANCH}" || REBASE_EXIT=$?📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| git rebase "${UPSTREAM}/${MAIN_BRANCH}" --onto "${WORK_BRANCH}" "${MERGE_BASE}" || REBASE_EXIT=$? | |
| git rebase --onto "${WORK_BRANCH}" "${MERGE_BASE}" "${UPSTREAM}/${MAIN_BRANCH}" || REBASE_EXIT=$? |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@scripts/rebase-main-to-alpha.sh` at line 61, The git rebase invocation has
the --onto flag placed after a positional argument; move --onto to directly
follow git rebase and reorder the positional arguments so the new base
(WORK_BRANCH) is passed to --onto first, followed by the upstream branch
(UPSTREAM/MAIN_BRANCH) and then the branch/range being rebased (MERGE_BASE) so
the correct commit range from main is replayed onto WORK_BRANCH.
- Fix YAML-breaking multiline commit messages in workflow by using heredoc form instead of inline -m "..." multiline strings - Fix incorrect git rebase --onto argument order in shell script: was: git rebase <upstream> --onto <newbase> <merge-base> now: git rebase --onto <newbase> <upstream> <branch> 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Summary
scripts/rebase-main-to-alpha.sh— manual best-effort rebase script.github/workflows/sync-alpha-from-main.yml— automated trigger on every push tomainOn each
mainpush the workflow:alphais already up to date (exits early if so)alpha, attempts rebase, falls back to merge on conflictalphafor human review and conflict resolutionTest plan
mainalpha🤖 Generated with Claude Code