From d00739fd760600cc775ec8ab2dab049a34189631 Mon Sep 17 00:00:00 2001 From: Rujun Chen Date: Fri, 27 Feb 2026 13:49:38 +0800 Subject: [PATCH 1/6] Delete existing branch and PR in update-spring-dependencies.yml --- .../workflows/update-spring-dependencies.yml | 37 ++++++++++++------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/.github/workflows/update-spring-dependencies.yml b/.github/workflows/update-spring-dependencies.yml index f69e864..6ad730d 100644 --- a/.github/workflows/update-spring-dependencies.yml +++ b/.github/workflows/update-spring-dependencies.yml @@ -26,21 +26,32 @@ jobs: run: | if [[ $(git ls-remote --heads ${{ secrets.BRANCH_REPO }} update-spring-dependencies | wc -l) -eq 0 ]]; then echo "Remote branch doesn't exist" - if [[ ! -f 'spring-versions.txt' ]]; then - echo "No new Spring Boot version, No updates!" - elif grep -q - 'spring-versions.txt'; then - echo "Has non-GA version, cancel update!" - else - echo "need_update_version=true" >> $GITHUB_ENV - echo "spring_boot_version=$(sed -n '1p' spring-versions.txt)" >> $GITHUB_ENV - echo "spring_cloud_version=$(sed -n '2p' spring-versions.txt)" >> $GITHUB_ENV - echo "last_spring_boot_version=$(sed -n '3p' spring-versions.txt)" >> $GITHUB_ENV - echo "last_spring_cloud_version=$(sed -n '4p' spring-versions.txt)" >> $GITHUB_ENV - echo "pr_descriptions=$(cat pr-descriptions.txt)" >> $GITHUB_ENV - fi else - echo "Remote branch exists, cancel commit" + echo "Remote branch exists, deleting original branch and closing original PR" + # Close existing PR from the branch + gh pr list --repo Azure/azure-sdk-for-java --head "${{ secrets.USER }}:update-spring-dependencies" --json number --jq '.[].number' | while read pr_number; do + echo "Closing PR #$pr_number" + gh pr close "$pr_number" --repo Azure/azure-sdk-for-java + done + # Delete the remote branch + git push "https://${{ secrets.USER }}:${{ secrets.ACCESS_TOKEN }}@github.com/${{ secrets.USER }}/azure-sdk-for-java.git" --delete update-spring-dependencies + echo "Original branch and PR deleted" fi + # Check if update is needed + if [[ ! -f 'spring-versions.txt' ]]; then + echo "No new Spring Boot version, No updates!" + elif grep -q - 'spring-versions.txt'; then + echo "Has non-GA version, cancel update!" + else + echo "need_update_version=true" >> $GITHUB_ENV + echo "spring_boot_version=$(sed -n '1p' spring-versions.txt)" >> $GITHUB_ENV + echo "spring_cloud_version=$(sed -n '2p' spring-versions.txt)" >> $GITHUB_ENV + echo "last_spring_boot_version=$(sed -n '3p' spring-versions.txt)" >> $GITHUB_ENV + echo "last_spring_cloud_version=$(sed -n '4p' spring-versions.txt)" >> $GITHUB_ENV + echo "pr_descriptions=$(cat pr-descriptions.txt)" >> $GITHUB_ENV + fi + env: + GH_TOKEN: ${{ secrets.ACCESS_TOKEN }} - uses: actions/checkout@v3 if: ${{ env.need_update_version == 'true' }} with: From 2c1d7b276675e756d1fdd903ee1c0c511bfb5973 Mon Sep 17 00:00:00 2001 From: Rujun Chen Date: Fri, 27 Feb 2026 13:58:00 +0800 Subject: [PATCH 2/6] Add comment when closing PR --- .github/workflows/update-spring-dependencies.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/update-spring-dependencies.yml b/.github/workflows/update-spring-dependencies.yml index 6ad730d..421d874 100644 --- a/.github/workflows/update-spring-dependencies.yml +++ b/.github/workflows/update-spring-dependencies.yml @@ -31,7 +31,7 @@ jobs: # Close existing PR from the branch gh pr list --repo Azure/azure-sdk-for-java --head "${{ secrets.USER }}:update-spring-dependencies" --json number --jq '.[].number' | while read pr_number; do echo "Closing PR #$pr_number" - gh pr close "$pr_number" --repo Azure/azure-sdk-for-java + gh pr close "$pr_number" --repo Azure/azure-sdk-for-java --comment "Closing superseded automated Spring dependency update PR in favor of a new one created by the update-spring-dependencies workflow." done # Delete the remote branch git push "https://${{ secrets.USER }}:${{ secrets.ACCESS_TOKEN }}@github.com/${{ secrets.USER }}/azure-sdk-for-java.git" --delete update-spring-dependencies From fdb8d9fb8b27ea0e3c1a8990c109715afd0995b3 Mon Sep 17 00:00:00 2001 From: Rujun Chen Date: Fri, 27 Feb 2026 14:06:47 +0800 Subject: [PATCH 3/6] Avoid use gh command because it will have 403 error --- .../workflows/update-spring-dependencies.yml | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/.github/workflows/update-spring-dependencies.yml b/.github/workflows/update-spring-dependencies.yml index 421d874..16cfc86 100644 --- a/.github/workflows/update-spring-dependencies.yml +++ b/.github/workflows/update-spring-dependencies.yml @@ -28,10 +28,21 @@ jobs: echo "Remote branch doesn't exist" else echo "Remote branch exists, deleting original branch and closing original PR" - # Close existing PR from the branch - gh pr list --repo Azure/azure-sdk-for-java --head "${{ secrets.USER }}:update-spring-dependencies" --json number --jq '.[].number' | while read pr_number; do + # Close existing PR from the branch using GitHub API + pr_numbers=$(curl -s -H "Authorization: token ${{ secrets.ACCESS_TOKEN }}" \ + "https://api.github.com/repos/Azure/azure-sdk-for-java/pulls?head=${{ secrets.USER }}:update-spring-dependencies&state=open" \ + | jq -r '.[].number') + for pr_number in $pr_numbers; do echo "Closing PR #$pr_number" - gh pr close "$pr_number" --repo Azure/azure-sdk-for-java --comment "Closing superseded automated Spring dependency update PR in favor of a new one created by the update-spring-dependencies workflow." + curl -s -X PATCH -H "Authorization: token ${{ secrets.ACCESS_TOKEN }}" \ + -H "Accept: application/vnd.github.v3+json" \ + -d '{"state":"closed"}' \ + "https://api.github.com/repos/Azure/azure-sdk-for-java/pulls/$pr_number" + # Add a comment explaining the closure + curl -s -X POST -H "Authorization: token ${{ secrets.ACCESS_TOKEN }}" \ + -H "Accept: application/vnd.github.v3+json" \ + -d '{"body":"Closing superseded automated Spring dependency update PR in favor of a new one created by the update-spring-dependencies workflow."}' \ + "https://api.github.com/repos/Azure/azure-sdk-for-java/issues/$pr_number/comments" done # Delete the remote branch git push "https://${{ secrets.USER }}:${{ secrets.ACCESS_TOKEN }}@github.com/${{ secrets.USER }}/azure-sdk-for-java.git" --delete update-spring-dependencies @@ -50,8 +61,6 @@ jobs: echo "last_spring_cloud_version=$(sed -n '4p' spring-versions.txt)" >> $GITHUB_ENV echo "pr_descriptions=$(cat pr-descriptions.txt)" >> $GITHUB_ENV fi - env: - GH_TOKEN: ${{ secrets.ACCESS_TOKEN }} - uses: actions/checkout@v3 if: ${{ env.need_update_version == 'true' }} with: From 7f39345e6f62fd6298f1fb16a5ee2cf4d054691f Mon Sep 17 00:00:00 2001 From: Rujun Chen Date: Fri, 27 Feb 2026 14:11:11 +0800 Subject: [PATCH 4/6] Fix error about closing existing PR --- .../workflows/update-spring-dependencies.yml | 59 +++++++++++-------- 1 file changed, 33 insertions(+), 26 deletions(-) diff --git a/.github/workflows/update-spring-dependencies.yml b/.github/workflows/update-spring-dependencies.yml index 16cfc86..f8b91e3 100644 --- a/.github/workflows/update-spring-dependencies.yml +++ b/.github/workflows/update-spring-dependencies.yml @@ -24,31 +24,6 @@ jobs: mvn exec:java -P github-actions -ntp -Dupdate-spring-dependencies=true - name: Confirm Whether to Update run: | - if [[ $(git ls-remote --heads ${{ secrets.BRANCH_REPO }} update-spring-dependencies | wc -l) -eq 0 ]]; then - echo "Remote branch doesn't exist" - else - echo "Remote branch exists, deleting original branch and closing original PR" - # Close existing PR from the branch using GitHub API - pr_numbers=$(curl -s -H "Authorization: token ${{ secrets.ACCESS_TOKEN }}" \ - "https://api.github.com/repos/Azure/azure-sdk-for-java/pulls?head=${{ secrets.USER }}:update-spring-dependencies&state=open" \ - | jq -r '.[].number') - for pr_number in $pr_numbers; do - echo "Closing PR #$pr_number" - curl -s -X PATCH -H "Authorization: token ${{ secrets.ACCESS_TOKEN }}" \ - -H "Accept: application/vnd.github.v3+json" \ - -d '{"state":"closed"}' \ - "https://api.github.com/repos/Azure/azure-sdk-for-java/pulls/$pr_number" - # Add a comment explaining the closure - curl -s -X POST -H "Authorization: token ${{ secrets.ACCESS_TOKEN }}" \ - -H "Accept: application/vnd.github.v3+json" \ - -d '{"body":"Closing superseded automated Spring dependency update PR in favor of a new one created by the update-spring-dependencies workflow."}' \ - "https://api.github.com/repos/Azure/azure-sdk-for-java/issues/$pr_number/comments" - done - # Delete the remote branch - git push "https://${{ secrets.USER }}:${{ secrets.ACCESS_TOKEN }}@github.com/${{ secrets.USER }}/azure-sdk-for-java.git" --delete update-spring-dependencies - echo "Original branch and PR deleted" - fi - # Check if update is needed if [[ ! -f 'spring-versions.txt' ]]; then echo "No new Spring Boot version, No updates!" elif grep -q - 'spring-versions.txt'; then @@ -60,6 +35,7 @@ jobs: echo "last_spring_boot_version=$(sed -n '3p' spring-versions.txt)" >> $GITHUB_ENV echo "last_spring_cloud_version=$(sed -n '4p' spring-versions.txt)" >> $GITHUB_ENV echo "pr_descriptions=$(cat pr-descriptions.txt)" >> $GITHUB_ENV + echo "PR_TITLE=External dependencies upgrade - Spring Boot $(sed -n '1p' spring-versions.txt) and Spring Cloud $(sed -n '2p' spring-versions.txt)" >> $GITHUB_ENV fi - uses: actions/checkout@v3 if: ${{ env.need_update_version == 'true' }} @@ -105,13 +81,44 @@ jobs: git add -A git commit -m "Upgrade external dependencies to align with Spring Boot ${{ env.spring_boot_version }}" git push "https://${{ secrets.USER }}:${{ secrets.ACCESS_TOKEN }}@github.com/${{ secrets.USER }}/azure-sdk-for-java.git" + - name: Close Old Pull Requests + if: ${{ env.need_update_version == 'true' }} + uses: actions/github-script@v7 + with: + github-token: ${{ secrets.ACCESS_TOKEN }} + script: | + const prTitle = process.env.PR_TITLE; + const { data: pullRequests } = await github.rest.pulls.list({ + owner: 'Azure', + repo: 'azure-sdk-for-java', + state: 'open' + }); + + const oldPRs = pullRequests.filter(pr => pr.title === prTitle); + + for (const pr of oldPRs) { + console.log(`Closing PR #${pr.number} with comment`); + await github.rest.issues.createComment({ + owner: 'Azure', + repo: 'azure-sdk-for-java', + issue_number: pr.number, + body: 'This PR has been superseded by a newer update. Closing automatically.' + }); + + await github.rest.pulls.update({ + owner: 'Azure', + repo: 'azure-sdk-for-java', + pull_number: pr.number, + state: 'closed' + }); + } - name: Create Pull Request if: ${{ env.need_update_version == 'true' }} uses: vsoch/pull-request-action@master env: PULL_REQUEST_TOKEN: ${{ secrets.ACCESS_TOKEN }} PULL_REQUEST_REPOSITORY: Azure/azure-sdk-for-java - PULL_REQUEST_TITLE: "External dependencies upgrade - Spring Boot ${{ env.spring_boot_version }} and Spring Cloud ${{ env.spring_cloud_version }}" + PULL_REQUEST_TITLE: "${{ env.PR_TITLE }}" PULL_REQUEST_FROM_BRANCH: "${{ secrets.USER }}:update-spring-dependencies" PULL_REQUEST_BRANCH: "main" PULL_REQUEST_BODY: "Updates external dependencies to align with Spring Boot version [${{ env.spring_boot_version }}](https://repo1.maven.org/maven2/org/springframework/boot/spring-boot-dependencies/${{ env.spring_boot_version }}/spring-boot-dependencies-${{ env.spring_boot_version }}.pom) from [${{ env.last_spring_boot_version }}](https://repo1.maven.org/maven2/org/springframework/boot/spring-boot-dependencies/${{ env.last_spring_boot_version }}/spring-boot-dependencies-${{ env.last_spring_boot_version }}.pom) and Spring Cloud version [${{ env.spring_cloud_version }}](https://repo1.maven.org/maven2/org/springframework/cloud/spring-cloud-dependencies/${{ env.spring_cloud_version }}/spring-cloud-dependencies-${{ env.spring_cloud_version }}.pom) from [${{ env.last_spring_cloud_version }}](https://repo1.maven.org/maven2/org/springframework/cloud/spring-cloud-dependencies/${{ env.last_spring_cloud_version }}/spring-cloud-dependencies-${{ env.last_spring_cloud_version }}.pom).\n${{ env.pr_descriptions }}\n\nThis PR is created by GitHub Actions: https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}" From 3e7977a23a07eda52c492aa032e80a848cb85742 Mon Sep 17 00:00:00 2001 From: Rujun Chen Date: Fri, 27 Feb 2026 14:17:12 +0800 Subject: [PATCH 5/6] Delete original branch before push --- .../workflows/update-spring-dependencies.yml | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/.github/workflows/update-spring-dependencies.yml b/.github/workflows/update-spring-dependencies.yml index f8b91e3..87d580a 100644 --- a/.github/workflows/update-spring-dependencies.yml +++ b/.github/workflows/update-spring-dependencies.yml @@ -71,16 +71,6 @@ jobs: run: | cd azure-sdk-for-java python ./sdk/spring/scripts/update_changelog.py -b ${{ env.spring_boot_version }} -c ${{ env.spring_cloud_version }} - - name: Push Commit - if: ${{ env.need_update_version == 'true' }} - run: | - cd azure-sdk-for-java - git config --global user.email github-actions@github.com - git config --global user.name github-actions - git rm ./sdk/spring/scripts/spring_boot_${{ env.last_spring_boot_version }}_managed_external_dependencies.txt - git add -A - git commit -m "Upgrade external dependencies to align with Spring Boot ${{ env.spring_boot_version }}" - git push "https://${{ secrets.USER }}:${{ secrets.ACCESS_TOKEN }}@github.com/${{ secrets.USER }}/azure-sdk-for-java.git" - name: Close Old Pull Requests if: ${{ env.need_update_version == 'true' }} uses: actions/github-script@v7 @@ -112,6 +102,18 @@ jobs: state: 'closed' }); } + - name: Push Commit + if: ${{ env.need_update_version == 'true' }} + run: | + cd azure-sdk-for-java + git config --global user.email github-actions@github.com + git config --global user.name github-actions + git rm ./sdk/spring/scripts/spring_boot_${{ env.last_spring_boot_version }}_managed_external_dependencies.txt + git add -A + git commit -m "Upgrade external dependencies to align with Spring Boot ${{ env.spring_boot_version }}" + # Delete remote branch if it exists + git push "https://${{ secrets.USER }}:${{ secrets.ACCESS_TOKEN }}@github.com/${{ secrets.USER }}/azure-sdk-for-java.git" --delete update-spring-dependencies || true + git push "https://${{ secrets.USER }}:${{ secrets.ACCESS_TOKEN }}@github.com/${{ secrets.USER }}/azure-sdk-for-java.git" - name: Create Pull Request if: ${{ env.need_update_version == 'true' }} uses: vsoch/pull-request-action@master From 30b3f4b29ce67ec7f55421c7852f37710b884327 Mon Sep 17 00:00:00 2001 From: Rujun Chen Date: Fri, 27 Feb 2026 14:21:40 +0800 Subject: [PATCH 6/6] Simplify script --- .github/workflows/update-spring-dependencies.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/update-spring-dependencies.yml b/.github/workflows/update-spring-dependencies.yml index 87d580a..4e033d2 100644 --- a/.github/workflows/update-spring-dependencies.yml +++ b/.github/workflows/update-spring-dependencies.yml @@ -44,7 +44,7 @@ jobs: path: 'azure-sdk-for-java' ref: main token: ${{ secrets.ACCESS_TOKEN }} - fetch-depth: 0 + fetch-depth: 1 - name: Generate spring_boot_managed_external_dependencies.txt if: ${{ env.need_update_version == 'true' }} run: | @@ -111,9 +111,7 @@ jobs: git rm ./sdk/spring/scripts/spring_boot_${{ env.last_spring_boot_version }}_managed_external_dependencies.txt git add -A git commit -m "Upgrade external dependencies to align with Spring Boot ${{ env.spring_boot_version }}" - # Delete remote branch if it exists - git push "https://${{ secrets.USER }}:${{ secrets.ACCESS_TOKEN }}@github.com/${{ secrets.USER }}/azure-sdk-for-java.git" --delete update-spring-dependencies || true - git push "https://${{ secrets.USER }}:${{ secrets.ACCESS_TOKEN }}@github.com/${{ secrets.USER }}/azure-sdk-for-java.git" + git push --force "https://${{ secrets.USER }}:${{ secrets.ACCESS_TOKEN }}@github.com/${{ secrets.USER }}/azure-sdk-for-java.git" - name: Create Pull Request if: ${{ env.need_update_version == 'true' }} uses: vsoch/pull-request-action@master