Skip to content

create-pull-request (signed commits) creates the head branch at the base SHA #76888

Done

Description

@pickypg

This can trigger CI on the base commit and overwrite its commit status in external CI systems.

Summary

With signed-commits: true (the default), pushSignedCommits creates a new remote branch with git.createRef pointing at the base commit (e.g. main's HEAD), then adds the agent's commit(s) with GraphQL createCommitOnBranch (actions/setup/js/push_signed_commits.cjs ~L758–L783 @ v0.89.21).

This produces two push webhooks for one action. The first announces a new branch whose head is the base commit. External CI systems that build on branch pushes (Buildkite in our case) start a build for the base commit, then skip or cancel it as "intermediate" when the real commit arrives a second later. Commit statuses are keyed by SHA + context, not by branch, so that skipped or cancelled status replaces the base branch's real status in the GitHub UI. In our repo, main's HEAD goes from ✅ passed to ❌ "Build #N skipped" every time the workflow opens a PR.

Reproduction

  1. A workflow with safe-outputs.create-pull-request (default signed-commits: true) targeting main.
  2. A CI provider that builds every branch push, reports a commit status, and skips intermediate builds on non-default branches.
  3. Run the workflow so that it opens a PR.
  4. gh api repos/<owner>/<repo>/commits/<main HEAD>/statuses: the newest status for the CI context is error: Build #N skipped, created seconds after the workflow's createRef, and it replaces main's real build result.

Example sequence on main HEAD 073df28:

09:40:25Z success | Build #16527 passed      <- real main build at 073df28
09:45:30Z pending | Build #16531 scheduled   <- bot branch created at 073df28 (same hash)
09:45:31Z error   | Build #16531 skipped     <- overwrites main's status

Expected

Creating a PR branch should never make a ref point at the base commit, so CI never sees a "new" branch at a commit that already belongs to the base branch. Even better if it never reports a meaningless intermediate commit.

Proposed fix

When the branch does not exist yet, create the first commit before the ref:

  1. Build the tree with git.createTree (base_tree = base commit's tree) and create the commit with git.createCommit (parent = base OID). With no custom author or signature, GitHub signs API-created commits made by an app or GITHUB_TOKEN.
  2. git.createRef at that commit's SHA.
  3. Continue with createCommitOnBranch for any remaining commits, as today.

As an alternative, an opt-in setting could pre-create the ref at a placeholder commit, or let create-pull-request reuse an existing branch without recreate-ref deleting it (today handleRemoteBranchCollision renames, fails, or deletes and recreates the branch at the base SHA, so pre-creating the branch upstream of the safe-outputs job cannot work around this).

Environment

  • gh-aw v0.89.21 (create-pull-request, defaults; allowed-branches: ["changelog-bot/*"])
  • CI: Buildkite GitHub integration, with intermediate builds skipped or cancelled on non-default branches
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions