Skip to content

ci: avoid duplicate Kruize version sync PRs against mvp_demo - #170

Open
shreyabiradar07 wants to merge 2 commits into
kruize:mvp_demofrom
shreyabiradar07:check_duplicate_version_sync_prs
Open

shreyabiradar07 wants to merge 2 commits into
kruize:mvp_demofrom
shreyabiradar07:check_duplicate_version_sync_prs

Conversation

@shreyabiradar07

@shreyabiradar07 shreyabiradar07 commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Description

The Sync Kruize Versions workflow now checks mvp_demo and doesn't raise a PR when an open one already covers the same updates.

Changes

  • Check out mvp_demo (inputs.base_branch || 'mvp_demo') so current image tags are read from that branch, not the default branch.
  • Add an "existing open PR" check. It looks for open PRs against mvp_demo that carry a hidden marker with the target Autotune and UI versions.
  • If a match is found, skip the file update, branch, commit and PR steps. The existing PR URL is logged and shown in the job summary.
  • Add the marker to the body of new PRs so later runs can detect them.

Summary by Sourcery

Prevent duplicate Kruize version synchronization pull requests by targeting the correct base branch, coordinating workflow runs, and reusing matching open requests.

New Features:

  • Prevent duplicate Kruize version update pull requests by detecting matching open requests targeting the configured base branch.

Enhancements:

  • Run version synchronization against the configured base branch and serialize concurrent runs per branch.
  • Skip update and pull request creation when an equivalent open request exists, while reporting the existing request in workflow results.
  • Build new updates from the exact checked-out commit and tag pull requests with their target versions for reliable deduplication.

Signed-off-by: Shreya Biradar <shbirada@ibm.com>
Assisted-by: Bob
@sourcery-ai

sourcery-ai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Configuration

Serialize version-sync runs per base branch and check out that branch so version comparisons use the intended target.

  • .github/workflows/sync-kruize-versions.yml L24-28, L43

Detect matching open update PRs and skip duplicate work, while recording target versions in new PRs and the workflow summary.

  • .github/workflows/sync-kruize-versions.yml L180-225, L422-427 (+5 small edits)

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

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've found 8 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path=".github/workflows/sync-kruize-versions.yml" line_range="38" />
<code_context>
       - name: Checkout kruize-operator repository
         uses: actions/checkout@v4
         with:
+          ref: ${{ inputs.base_branch || 'mvp_demo' }}
           token: ${{ steps.generate-token.outputs.token }}
           fetch-depth: 0
</code_context>
<issue_to_address>
**Concurrent edits get overwritten**

When the base branch changes either updated file after checkout but before the workflow reads its base SHA, the workflow builds complete file contents from its checkout, then creates a branch from a later base-branch SHA; if either file changed in between, the new tree replaces that file with stale contents, and merging the PR can discard the concurrent edits.

Build the update against the exact base commit used for the branch, or re-read and preserve the latest file contents before creating the replacement blobs.
</issue_to_address>

### Comment 2
<location path=".github/workflows/sync-kruize-versions.yml" line_range="203" />
<code_context>
+          # Look for open PRs targeting the base branch that carry the same marker
+          EXISTING_PR=$(curl -s -H "Authorization: token $GH_TOKEN" \
+            "https://api.github.com/repos/${{ github.repository }}/pulls?state=open&base=${BASE_BRANCH}&per_page=100" \
+            | jq -r --arg marker "$MARKER" '[.[] | select((.body // "") | contains($marker))][0].html_url // empty')
+
+          if [ -n "$EXISTING_PR" ]; then
</code_context>
<issue_to_address>
**Unrelated PR suppresses version update**

When an open PR targeting the base branch contains the exact marker but does not contain the version update, the marker-only lookup treats that PR as the matching sync PR, so the workflow skips creating the required update PR.

Verify that a matching PR is an actual version-sync PR for the target versions, not merely a PR whose body contains the marker.

Also at `.github/workflows/sync-kruize-versions.yml:216`.
</issue_to_address>

### Comment 3
<location path=".github/workflows/sync-kruize-versions.yml" line_range="216" />
<code_context>
+          fi
+
+      - name: Update kruize_images.go and sample YAML
+        if: steps.update-check.outputs.needs_update == 'true' && steps.existing-pr.outputs.pr_exists != 'true'
         id: update-files
         run: |
</code_context>
<issue_to_address>
**Closed PR delays the version update**

When a reviewer closes the matching PR without merging it after the existing-PR query but before the workflow finishes, the workflow skips its update steps based on that earlier result, leaving no open PR for the required versions; the update waits until another workflow run, normally the next weekly schedule.

Recheck the matching PR before skipping the update, and retry or create a replacement if it was closed without merging.
</issue_to_address>

### Comment 4
<location path=".github/workflows/sync-kruize-versions.yml" line_range="175-203" />
<code_context>
+      - name: Check for existing open PR with the same updates
</code_context>
<issue_to_address>
**Overlapping runs create duplicate PRs**

When two workflow runs for the same base branch and target versions overlap before either opens a PR, both runs can finish the `EXISTING_PR` lookup before either creates a PR, so both pass the creation guard and open separate PRs for the same updates.

Serialize runs for the same base branch and target versions so each completes the lookup and PR creation before another begins.

Also at `.github/workflows/sync-kruize-versions.yml:400`.
</issue_to_address>

### Comment 5
<location path=".github/workflows/sync-kruize-versions.yml" line_range="200-203" />
<code_context>
+          echo "target_autotune=$TARGET_AUTOTUNE" >> $GITHUB_OUTPUT
+          echo "target_ui=$TARGET_UI" >> $GITHUB_OUTPUT
+
+          # Look for open PRs targeting the base branch that carry the same marker
+          EXISTING_PR=$(curl -s -H "Authorization: token $GH_TOKEN" \
+            "https://api.github.com/repos/${{ github.repository }}/pulls?state=open&base=${BASE_BRANCH}&per_page=100" \
+            | jq -r --arg marker "$MARKER" '[.[] | select((.body // "") | contains($marker))][0].html_url // empty')
+
+          if [ -n "$EXISTING_PR" ]; then
</code_context>
<issue_to_address>
**Existing sync PR is duplicated**

When an equivalent version-sync PR created before the marker was added is still open, the marker-only lookup treats that PR as absent, so the workflow creates another PR for the same updates.

Recognize equivalent open version-sync PRs using identifying information that also matches PRs created before the marker was added.

Also at `.github/workflows/sync-kruize-versions.yml:418`.
</issue_to_address>

### Comment 6
<location path=".github/workflows/sync-kruize-versions.yml" line_range="202" />
<code_context>
+
+          # Look for open PRs targeting the base branch that carry the same marker
+          EXISTING_PR=$(curl -s -H "Authorization: token $GH_TOKEN" \
+            "https://api.github.com/repos/${{ github.repository }}/pulls?state=open&base=${BASE_BRANCH}&per_page=100" \
+            | jq -r --arg marker "$MARKER" '[.[] | select((.body // "") | contains($marker))][0].html_url // empty')
+
</code_context>
<issue_to_address>
**Matching PR on later page is missed**

When more than 100 open PRs target the base branch and the matching PR is not on the first page, the lookup searches only the first 100 results, so it reports no match and the workflow creates another PR for the same updates.

Follow the API pagination links and search all pages of open PRs before deciding that no matching PR exists.

Also at `.github/workflows/sync-kruize-versions.yml:203`.
</issue_to_address>

### Comment 7
<location path=".github/workflows/sync-kruize-versions.yml" line_range="202-203" />
<code_context>
+
+          # Look for open PRs targeting the base branch that carry the same marker
+          EXISTING_PR=$(curl -s -H "Authorization: token $GH_TOKEN" \
+            "https://api.github.com/repos/${{ github.repository }}/pulls?state=open&base=${BASE_BRANCH}&per_page=100" \
+            | jq -r --arg marker "$MARKER" '[.[] | select((.body // "") | contains($marker))][0].html_url // empty')
+
+          if [ -n "$EXISTING_PR" ]; then
</code_context>
<issue_to_address>
**API errors trigger duplicate PR creation**

When the open-PR request returns a JSON HTTP error response while PR creation can still succeed, `curl -s` accepts the error response and `jq` treats it as no matching PR, so the workflow proceeds to create a PR without completing the lookup.

Fail the lookup on unsuccessful HTTP responses and stop the workflow rather than treating an API error as an empty PR list.
</issue_to_address>

### Comment 8
<location path=".github/workflows/sync-kruize-versions.yml" line_range="202" />
<code_context>
+
+          # Look for open PRs targeting the base branch that carry the same marker
+          EXISTING_PR=$(curl -s -H "Authorization: token $GH_TOKEN" \
+            "https://api.github.com/repos/${{ github.repository }}/pulls?state=open&base=${BASE_BRANCH}&per_page=100" \
+            | jq -r --arg marker "$MARKER" '[.[] | select((.body // "") | contains($marker))][0].html_url // empty')
+
</code_context>
<issue_to_address>
**Branch name changes API filter**

When a manually selected valid base branch contains a query delimiter such as `&`, the unescaped `BASE_BRANCH` changes how the API parses the query string, so the lookup can search the wrong base branch and miss an equivalent open PR.

URL-encode `BASE_BRANCH` before placing it in the API query string.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 8 findings to address first, and if the duplicate check or selected base branch is wrong, the workflow could leave a needed update without a PR or create a PR against the wrong branch. Any PR it creates remains after reverting this workflow, but it can be closed or corrected; the workflow does not merge changes.

Blocking findings: .github/workflows/sync-kruize-versions.yml:38, .github/workflows/sync-kruize-versions.yml:203, .github/workflows/sync-kruize-versions.yml:216, .github/workflows/sync-kruize-versions.yml:203, .github/workflows/sync-kruize-versions.yml:203, and 3 more


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Signed-off-by: Shreya Biradar <shbirada@ibm.com>
Assisted-by: Bob
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant