Skip to content

chore(ci): sync alpha branch from main on every push#1089

Merged
Gkrumbach07 merged 3 commits intomainfrom
feat/sync-alpha-from-main
Mar 30, 2026
Merged

chore(ci): sync alpha branch from main on every push#1089
Gkrumbach07 merged 3 commits intomainfrom
feat/sync-alpha-from-main

Conversation

@markturansky
Copy link
Copy Markdown
Contributor

Summary

  • Adds scripts/rebase-main-to-alpha.sh — manual best-effort rebase script
  • Adds .github/workflows/sync-alpha-from-main.yml — automated trigger on every push to main

On each main push the workflow:

  1. Checks if alpha is already up to date (exits early if so)
  2. Skips if an open sync PR already exists
  3. Creates a timestamped branch off alpha, attempts rebase, falls back to merge on conflict
  4. Opens a PR against alpha for human review and conflict resolution

Test plan

  • Verify workflow triggers on next push to main
  • Verify PR is opened against alpha
  • Verify early-exit when alpha is already up to date
  • Verify deduplication — no second PR opened if one already exists

🤖 Generated with Claude Code

Ambient Code Bot and others added 2 commits March 28, 2026 14:00
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>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 28, 2026

Caution

Review failed

Pull request was closed or merged during review

Walkthrough

Adds automation to synchronize commits from main into alpha: a new GitHub Actions workflow triggers on pushes/manual dispatch and invokes logic to detect needed syncs, create a timestamped work branch, attempt a rebase (with merge fallback on conflicts), push the branch, and open a PR; a companion shell script provides equivalent local automation.

Changes

Cohort / File(s) Summary
GitHub Actions workflow
.github/workflows/sync-alpha-from-main.yml
New workflow that detects whether main is ahead of alpha, sets outputs (needs_sync, main_sha, alpha_sha, commit_count), checks for existing PRs, attempts rebase/merge workflows, pushes work branch, creates PR, and writes a final step summary.
Local sync script
scripts/rebase-main-to-alpha.sh
New executable Bash script that fetches remote main/alpha, computes merge-base and commit count, creates a timestamped work branch, tries git rebase --onto with merge fallback on conflicts, stages conflict markers when present, force-pushes the work branch, and opens a PR via gh pr create.

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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: a new workflow that automatically syncs the alpha branch from main on every push.
Description check ✅ Passed The description is directly related to the changeset, outlining the new script and workflow with clear behavioral expectations and test plan.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/sync-alpha-from-main

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8ac0f85 and 0062615.

📒 Files selected for processing (2)
  • .github/workflows/sync-alpha-from-main.yml
  • scripts/rebase-main-to-alpha.sh

# 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=$?
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

cat -n scripts/rebase-main-to-alpha.sh

Repository: 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:


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.

Suggested change
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.

@ambient-code ambient-code bot added this to the Review Queue milestone Mar 30, 2026
- 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>
@Gkrumbach07 Gkrumbach07 merged commit f81b269 into main Mar 30, 2026
12 of 13 checks passed
@Gkrumbach07 Gkrumbach07 deleted the feat/sync-alpha-from-main branch March 30, 2026 14:04
@ambient-code ambient-code bot removed this from the Review Queue milestone Mar 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants