diff --git a/.github/workflows/update-spring-cloud-azure-support-file.yml b/.github/workflows/update-spring-cloud-azure-support-file.yml index 458f42a..82a5b7a 100644 --- a/.github/workflows/update-spring-cloud-azure-support-file.yml +++ b/.github/workflows/update-spring-cloud-azure-support-file.yml @@ -23,36 +23,82 @@ jobs: ref: main token: ${{ secrets.ACCESS_TOKEN }} fetch-depth: 0 - - name: Make Decision Based on Git Diff and Branch Status + - name: Set Branch Name with Timestamp run: | - if [[ $(git ls-remote --heads ${{ secrets.BRANCH_REPO }} update-spring-cloud-azure-support-file | wc -l) -eq 0 ]]; then - cd azure-sdk-for-java - git checkout -b update-spring-cloud-azure-support-file - cp -f ../spring-cloud-azure-supported-spring.json sdk/spring/pipeline - if [[ -n "$(git status -s)" ]]; then - echo "need_update_file=true" >> $GITHUB_ENV - else - echo "No file changes, no commits." - fi + TIMESTAMP=$(date +%Y%m%d-%H%M%S) + PR_TITLE="Update Spring Boot and Spring Cloud versions for the Spring compatibility tests" + GITHUB_ACTION_URL="https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}" + + echo "BRANCH_NAME=update-spring-cloud-azure-support-file-${TIMESTAMP}" >> $GITHUB_ENV + echo "PR_TITLE=${PR_TITLE}" >> $GITHUB_ENV + + echo "COMMIT_MESSAGE<> $GITHUB_ENV + echo "${PR_TITLE}." >> $GITHUB_ENV + echo "This commit is created by GitHub Action: ${GITHUB_ACTION_URL}" >> $GITHUB_ENV + echo "EOF" >> $GITHUB_ENV + + echo "PULL_REQUEST_BODY<> $GITHUB_ENV + echo "${PR_TITLE}." >> $GITHUB_ENV + echo "This commit is created by GitHub Action: ${GITHUB_ACTION_URL}" >> $GITHUB_ENV + echo "If you merged this PR, please update [Spring Cloud Azure Timeline](https://github.com/Azure/azure-sdk-for-java/wiki/Spring-Cloud-Azure-Timeline)." >> $GITHUB_ENV + echo "EOF" >> $GITHUB_ENV + - name: Make Decision Based on Git Diff + run: | + cd azure-sdk-for-java + git checkout -b ${{ env.BRANCH_NAME }} + cp -f ../spring-cloud-azure-supported-spring.json sdk/spring/pipeline + if [[ -n "$(git status -s)" ]]; then + echo "NEED_UPDATE_FILE=true" >> $GITHUB_ENV else - echo "Branch exists, cancel commit" + echo "No file changes, no commits." fi - name: Push Commit - if: ${{ env.need_update_file == 'true' }} + if: ${{ env.NEED_UPDATE_FILE == 'true' }} run: | cd azure-sdk-for-java git config --global user.email github-actions@github.com git config --global user.name github-actions git add sdk/spring/pipeline/spring-cloud-azure-supported-spring.json - git commit -m "Update Spring Boot and Spring Cloud versions for the compatibility test. This commit is created by GitHub Action: https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}" + git commit -m "${{ env.COMMIT_MESSAGE }}" 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_FILE == '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_file == 'true' }} + if: ${{ env.NEED_UPDATE_FILE == '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: "Update Spring Boot and Spring Cloud versions for the Spring compatibility tests" - PULL_REQUEST_FROM_BRANCH: "${{ secrets.USER }}:update-spring-cloud-azure-support-file" + PULL_REQUEST_TITLE: "${{ env.PR_TITLE }}" + PULL_REQUEST_FROM_BRANCH: "${{ secrets.USER }}:${{ env.BRANCH_NAME }}" PULL_REQUEST_BRANCH: "main" - PULL_REQUEST_BODY: "Update Spring Boot and Spring Cloud versions for the compatibility test.\n\nIf you merged this PR, please update [Spring Cloud Azure Timeline](https://github.com/Azure/azure-sdk-for-java/wiki/Spring-Cloud-Azure-Timeline).\n\nThis PR is created by GitHub Actions: https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}" + PULL_REQUEST_BODY: "${{ env.PULL_REQUEST_BODY }}" diff --git a/src/main/java/com/azure/spring/dev/tools/actions/UpdateSpringCloudAzureSupportFileRunner.java b/src/main/java/com/azure/spring/dev/tools/actions/UpdateSpringCloudAzureSupportFileRunner.java index 482a8b6..983a9ae 100644 --- a/src/main/java/com/azure/spring/dev/tools/actions/UpdateSpringCloudAzureSupportFileRunner.java +++ b/src/main/java/com/azure/spring/dev/tools/actions/UpdateSpringCloudAzureSupportFileRunner.java @@ -35,13 +35,12 @@ /** * This Runner is used to generate the newest spring-cloud-azure-supported-spring.json file for * spring compatibility tests, which contains information about Spring Boot and Spring Cloud supported by Azure, - * such as: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/spring/pipeline/spring-cloud-azure-supported-spring.json + * such as: ... */ @ConditionalOnProperty("update-spring-cloud-azure-support-file") @Component public class UpdateSpringCloudAzureSupportFileRunner implements CommandLineRunner { private static final Logger LOGGER = LoggerFactory.getLogger(UpdateSpringCloudAzureSupportFileRunner.class); - static final List SUPPORTED_VERSIONS = Stream.of("2.5.15", "2.6.15", "2.7.18", "3.0.13", "3.1.12", "3.2.12", "3.3.13").collect(Collectors.toList()); static final String NONE_SUPPORTED_VERSION = "NONE_SUPPORTED_SPRING_CLOUD_VERSION"; private final SpringProjectMetadataReader springProjectMetadataReader; private final Map springCloudCompatibleSpringBootVersionRanges; @@ -81,13 +80,14 @@ public void run(String... args) throws Exception { .values() .stream() .filter(s -> !activeSpringBootVersions.contains(s.getSpringBootVersion())) - .filter(s -> !SUPPORTED_VERSIONS.contains(s.getSpringBootVersion())) .peek(s -> s.setCurrent(false)) - .peek(s -> s.setSupportStatus(SupportStatus.END_OF_LIFE)) + .peek(s -> { + if (!Objects.equals(s.getSpringBootVersion(), "2.7.18")) { // Special case for 2.7.18 + s.setSupportStatus(SupportStatus.END_OF_LIFE); + } + }) .collect(Collectors.toList()); - maintainVersions(snapshot, azureSupportMetadataMap); - List result = Stream .concat(current.stream(), snapshot.stream()) .sorted((o1, o2) -> { @@ -101,10 +101,6 @@ public void run(String... args) throws Exception { writeToFile(result); } - void maintainVersions(List snapshot, Map map) { - SUPPORTED_VERSIONS.forEach(v -> snapshot.add(map.get(v))); - } - void setNewStatus(List result) { for (SpringCloudAzureSupportMetadata metadata : result) { if (metadata.getSupportStatus() == null) { @@ -156,8 +152,8 @@ String findCompatibleSpringCloudVersion(String springBootVersion) { */ boolean isVersionSupported(String springBootVersion) { Version version = Version.parse(springBootVersion); - Version minVersion = Version.parse("3.5.0"); - return version.compareTo(minVersion) >= 0; + return version.compareTo(Version.parse("3.5.0")) >= 0 + && version.compareTo(Version.parse("4.0.0")) < 0; } }