This is an automated email from the ASF dual-hosted git repository.

gnodet pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new 581b0b5f9e8d chore(ci): prevent duplicate container upgrade PRs 
(#21901)
581b0b5f9e8d is described below

commit 581b0b5f9e8df58e0ba93a88769599a5cfb84bf6
Author: Guillaume Nodet <[email protected]>
AuthorDate: Tue Mar 10 11:00:41 2026 +0100

    chore(ci): prevent duplicate container upgrade PRs (#21901)
    
    * chore(ci): prevent duplicate container upgrade PRs
    
    The check-container-versions workflow was creating duplicate PRs for the
    same container upgrade because:
    1. The branch name included the workflow run number, making each run unique
    2. There was no check for existing open PRs before creating a new one
    
    Fix by:
    - Removing the run number from branch names so the same upgrade always
      maps to the same branch
    - Checking for existing open PRs (by branch name and by property name)
      before creating a new one
    
    * chore(ci): close stale container PRs when a newer version is available
    
    Instead of skipping when an open PR exists for the same property,
    close the stale PR (with a comment) and create a new one for the
    newer version.
---
 .github/workflows/check-container-versions.yml | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/.github/workflows/check-container-versions.yml 
b/.github/workflows/check-container-versions.yml
index a2cebd46466d..73747dc84eb2 100644
--- a/.github/workflows/check-container-versions.yml
+++ b/.github/workflows/check-container-versions.yml
@@ -276,12 +276,28 @@ jobs:
           EOF
           )
 
-            # Generate unique branch name
-            BRANCH_NAME="automated/upgrade-$(echo "$PROPERTY_NAME" | tr '.' 
'-' | tr '_' '-')-${NEW_VERSION}-${{ github.run_number }}"
+            # Generate branch name (deterministic per property+version, no run 
number)
+            BRANCH_NAME="automated/upgrade-$(echo "$PROPERTY_NAME" | tr '.' 
'-' | tr '_' '-')-${NEW_VERSION}"
 
             echo "Creating PR: $PR_TITLE"
             echo "Branch: $BRANCH_NAME"
 
+            # Check for existing open PR for the exact same property+version 
upgrade
+            EXISTING_PR=$(gh pr list --state open --head "$BRANCH_NAME" --json 
number --jq '.[0].number' 2>/dev/null || echo "")
+            if [[ -n "$EXISTING_PR" ]]; then
+              echo "⏭️  Skipping $PROPERTY_NAME $NEW_VERSION — open PR 
#$EXISTING_PR already exists"
+              continue
+            fi
+
+            # Check if there is an open PR for the same property but an older 
version — close it
+            STALE_PR=$(gh pr list --state open --label "container-images" 
--search "upgrade $PROPERTY_NAME" --json number,headRefName --jq '.[0]' 
2>/dev/null || echo "")
+            if [[ -n "$STALE_PR" && "$STALE_PR" != "null" ]]; then
+              STALE_PR_NUMBER=$(echo "$STALE_PR" | jq -r '.number')
+              STALE_BRANCH=$(echo "$STALE_PR" | jq -r '.headRefName')
+              echo "🔄 Closing stale PR #$STALE_PR_NUMBER for $PROPERTY_NAME 
(superseded by $NEW_VERSION)"
+              gh pr close "$STALE_PR_NUMBER" --comment "Superseded by a newer 
version ($NEW_VERSION)." --delete-branch 2>/dev/null || true
+            fi
+
             # Configure git
             git config user.name "github-actions[bot]"
             git config user.email 
"github-actions[bot]@users.noreply.github.com"

Reply via email to