Skip to content

fix(ci): build api-gate detector from base tip when merge base predates it - #3193

Merged
Aleksei Sviridkin (lexfrei) merged 1 commit into
mainfrom
fix/api-gate-build-from-base-tip
Jul 3, 2026
Merged

Aleksei Sviridkin (lexfrei) merged 1 commit into
mainfrom
fix/api-gate-build-from-base-tip

Conversation

@lexfrei

@lexfrei Aleksei Sviridkin (lexfrei) commented Jul 3, 2026 •

Copy link
Copy Markdown
Contributor

What this PR does

The API Review Gate required check builds the cmd/api-gate detector from the PR's merge-base checkout so a PR cannot neuter the detector by editing its own code. When a PR's merge base predates the commit that introduced the gate (fa871249c), cmd/api-gate is absent from both the merge base and the equally old head, so the head fallback also fails to build and the check errors out before evaluating any API content. This red-blocks every open PR whose merge base is older than the gate, and neither a re-run nor an approving review clears it.

This adds the base branch tip (origin/<base>) as an intermediate build source: prefer the merge-base checkout, fall back to the base tip when the merge base lacks the tool, and bootstrap from the head only while the tool exists nowhere on the base branch yet. The base tip is a protected, non-PR-authored branch, so it preserves the "analyze the head as data, not code" property. The API surface is still diffed against the merge base; only where the detector binary is compiled changes. This unblocks the pre-gate backlog without forcing every affected PR to rebase.

The selection is kept inline in the workflow rather than in a helper script: a helper would be read from the untrusted PR head, which both reintroduces the failure for heads that predate the helper and lets a PR steer the selection away from the trusted build.

Closes #3192

Screenshots

N/A — CI-only change, no user-facing UI.

Release note

fix(ci): API Review Gate now builds its detector from the base branch tip when the PR merge base predates the gate, so pre-gate PRs stop failing the check without needing a rebase.

Summary by CodeRabbit

  • Chores
    • Improved build selection logic for the API review gate to use the most appropriate trusted source when compiling checks.
    • Updated fallback behavior so the build process is more reliable when the target tool is missing in some branches.
    • Clarified status messages during the build process to better reflect which source is being used.

…es it

The API Review Gate builds cmd/api-gate from the PR's merge-base checkout
so a PR cannot neuter the detector by editing its own code. When the merge
base predates the commit that introduced the gate, cmd/api-gate is absent
from both the merge base and the equally old head, so the head fallback
also fails to build and the required check errors out before evaluating
any API content. This blocks every open PR whose merge base is older than
the gate, and neither a re-run nor an approving review clears it.

Add the base branch tip as an intermediate build source: prefer the
merge-base checkout, fall back to the base tip when the merge base lacks
the tool, and bootstrap from head only while the tool exists nowhere on
the base branch yet. The base tip is a protected branch, not PR-authored,
so it preserves the "analyze head as data, not code" property. The API
surface is still diffed against the merge base; only where the detector
binary is compiled changes. This unblocks the backlog without forcing
every affected PR to rebase.

The selection stays inline in the workflow rather than in a helper script:
a helper would be read from the untrusted PR head, which both reintroduces
the failure for heads that predate the helper and lets a PR steer the
selection away from the trusted build.

Assisted-By: Claude <[email protected]>
Signed-off-by: Aleksei Sviridkin <[email protected]>
@coderabbitai

coderabbitai Bot commented Jul 3, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 5da9bbde-45cf-4b18-8cfe-f3b092f2099f

📥 Commits

Reviewing files that changed from the base of the PR and between 1baf126 and 361748e.

📒 Files selected for processing (1)
  • .github/workflows/api-review-gate.yaml

📝 Walkthrough

Walkthrough

The "Build api-gate" step in the CI workflow was updated to add an intermediate fallback: when cmd/api-gate is absent from the merge-base worktree, it now checks a detached "base-tip" worktree from origin/${BASE_REF} before falling back to bootstrapping from the PR head workspace.

Changes

API Review Gate build fallback

Layer / File(s) Summary
Three-way build source precedence
.github/workflows/api-review-gate.yaml
Build logic now tries merge-base worktree, then a new detached base-tip worktree from origin/${BASE_REF}, then head bootstrap, with updated log messages reflecting each fallback stage.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
    participant Workflow as CI Workflow
    participant MergeBase as Merge-base Worktree
    participant BaseTip as Base-tip Worktree
    participant Head as PR Head Workspace

    Workflow->>MergeBase: Check for cmd/api-gate
    alt exists in merge-base
        MergeBase-->>Workflow: Build api-gate here
    else absent in merge-base
        Workflow->>BaseTip: Create detached worktree, check for cmd/api-gate
        alt exists on origin/BASE_REF
            BaseTip-->>Workflow: Build api-gate here
        else absent on origin/BASE_REF
            Workflow->>Head: Bootstrap build from head
            Head-->>Workflow: Build api-gate here
        end
    end
Loading

Suggested labels: ci, github-actions

Suggested reviewers: cozystack maintainers familiar with CI workflows

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/api-gate-build-from-base-tip

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.

@github-actions github-actions Bot added area/ci Issues or PRs related to CI workflows, GitHub Actions, automation kind/bug Categorizes issue or PR as related to a bug size/M This PR changes 30-99 lines, ignoring generated files labels Jul 3, 2026
@lexfrei
Aleksei Sviridkin (lexfrei) marked this pull request as ready for review July 3, 2026 15:49
@lexfrei
Aleksei Sviridkin (lexfrei) merged commit 58d61d5 into main Jul 3, 2026
12 checks passed
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Note

Gemini is unable to generate a summary for this pull request due to the file types involved not being currently supported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/ci Issues or PRs related to CI workflows, GitHub Actions, automation kind/bug Categorizes issue or PR as related to a bug size/M This PR changes 30-99 lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

API Review Gate blocks every open PR whose merge-base predates cmd/api-gate

1 participant