Repository navigation
ci: avoid duplicate Kruize version sync PRs against mvp_demo - #170
shreyabiradar07 wants to merge 2 commits into
Conversation
Signed-off-by: Shreya Biradar <shbirada@ibm.com> Assisted-by: Bob
Reviewer's GuideConfigurationSerialize version-sync runs per base branch and check out that branch so version comparisons use the intended target.
Detect matching open update PRs and skip duplicate work, while recording target versions in new PRs and the workflow summary.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
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
Signed-off-by: Shreya Biradar <shbirada@ibm.com> Assisted-by: Bob
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
inputs.base_branch || 'mvp_demo') so current image tags are read from that branch, not the default branch.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:
Enhancements: