Skip to content

Fix single-commit check for stable branch PRs#1167

Merged
chris1984 merged 1 commit intotheforeman:developfrom
zjhuntin:fix-single-commit-workflow
Mar 4, 2026
Merged

Fix single-commit check for stable branch PRs#1167
chris1984 merged 1 commit intotheforeman:developfrom
zjhuntin:fix-single-commit-workflow

Conversation

@zjhuntin
Copy link
Contributor

@zjhuntin zjhuntin commented Mar 4, 2026

Summary

The single-commit workflow added in #1032 enforces one commit per PR to ensure squashed commits before merging. However, it was hardcoded to compare against develop, which breaks for PRs targeting stable branches like foreman_3_18.

This change uses github.base_ref to dynamically compare against the PR's actual target branch.

Problem

PRs like #1166 (Release 13.2.3) targeting foreman_3_18 fail the commit count check because the stable branch has diverged from develop.

Solution

Replace hardcoded develop with ${{ github.base_ref }} so the check works for PRs targeting any branch.

Summary by Sourcery

CI:

  • Adjust the single-commit check workflow to fetch and create a local branch from github.base_ref and use it as the reference for the commit count check.

@sourcery-ai
Copy link

sourcery-ai bot commented Mar 4, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Updates the single-commit GitHub Actions workflow to compare commits against the PR’s actual base branch instead of hardcoding the develop branch, so the single-commit check works for PRs to any branch, including stable branches.

Sequence diagram for updated single-commit GitHub Actions workflow

sequenceDiagram
    actor Developer
    participant GitHub
    participant SingleCommitWorkflow
    participant ActionsCheckout
    participant GitCLI

    Developer->>GitHub: Open pull_request (head -> base_branch)
    GitHub-->>SingleCommitWorkflow: Trigger workflow on pull_request

    SingleCommitWorkflow->>ActionsCheckout: Checkout current HEAD (PR branch)
    ActionsCheckout-->>SingleCommitWorkflow: Working copy at HEAD

    SingleCommitWorkflow->>GitCLI: git fetch origin github.base_ref
    GitCLI-->>SingleCommitWorkflow: Fetched base branch refs

    SingleCommitWorkflow->>GitCLI: git branch base_branch origin/github.base_ref
    GitCLI-->>SingleCommitWorkflow: Local base_branch created

    SingleCommitWorkflow->>GitCLI: git log --oneline --no-merges HEAD ^base_branch
    GitCLI-->>SingleCommitWorkflow: Commit list between HEAD and base_branch

    SingleCommitWorkflow->>SingleCommitWorkflow: Count commits and compare to 1
    SingleCommitWorkflow-->>GitHub: Report success or failure
    GitHub-->>Developer: Show status of single-commit check
Loading

Flow diagram for updated single-commit job steps

flowchart TD
    A[Start single-commit job] --> B[Checkout PR HEAD with actions/checkout]
    B --> C[Fetch origin github.base_ref]
    C --> D[Create local base_branch from origin/github.base_ref]
    D --> E[Run git log --oneline --no-merges HEAD ^base_branch]
    E --> F[Count commits between HEAD and base_branch]
    F --> G{Commit count == 1}
    G -- Yes --> H[Job succeeds]
    G -- No --> I[Job fails]
    H --> J[End]
    I --> J[End]
Loading

File-Level Changes

Change Details Files
Make the single-commit workflow dynamically use the PR’s base branch rather than the hardcoded develop branch.
  • Change the fetch step to fetch the remote base branch referenced by github.base_ref instead of develop.
  • Create a local branch named base_branch that tracks origin/${{ github.base_ref }} instead of a local develop branch.
  • Update the commit count logic to compare HEAD against the new base branch rather than the develop branch (note that the final run command in the diff appears truncated and should be verified in the PR).
.github/workflows/single-commit.yml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • The commit count check still references develop; it should be updated to compare against the newly created base_branch (e.g., git log --oneline --no-merges HEAD ^base_branch).
  • Consider quoting ${{ github.base_ref }} in the git fetch command to avoid issues if the branch name ever contains characters interpreted by the shell (e.g., git fetch origin "${{ github.base_ref }}").
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The commit count check still references `develop`; it should be updated to compare against the newly created `base_branch` (e.g., `git log --oneline --no-merges HEAD ^base_branch`).
- Consider quoting `${{ github.base_ref }}` in the `git fetch` command to avoid issues if the branch name ever contains characters interpreted by the shell (e.g., `git fetch origin "${{ github.base_ref }}"`).

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@zjhuntin zjhuntin force-pushed the fix-single-commit-workflow branch from c1790ac to 9511ee2 Compare March 4, 2026 17:37
@zjhuntin zjhuntin changed the title Refs #39127 - Fix single-commit check for stable branch PRs Fix single-commit check for stable branch PRs Mar 4, 2026
@chris1984 chris1984 merged commit 3065d09 into theforeman:develop Mar 4, 2026
14 checks passed
@jeremylenz
Copy link
Collaborator

Awesome, thanks @zjhuntin!

Seems https://github.com/Katello/katello/blob/master/.github/workflows/pull_request.yml will need the same fix.

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.

3 participants