Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 42 additions & 32 deletions .github/workflows/update-spring-dependencies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,40 @@ 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" "HEAD:${{ env.update_branch }}"
- name: Close Old Pull Requests
if: ${{ env.need_update_version == 'true' }}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

it will close the working PR: Azure/azure-sdk-for-java#49501

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Updated.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Not it will skip other steps if there is any PR with specific title prefix. Here are test pipelines:

  1. https://github.com/Azure/spring-cloud-azure-tools/actions/runs/27528316282
    image
  2. https://github.com/Azure/spring-cloud-azure-tools/actions/runs/27528329850
    image

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can remove this step now?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Removed

uses: actions/github-script@v7
with:
github-token: ${{ secrets.ACCESS_TOKEN }}
script: |
const prTitlePrefix = 'External dependencies upgrade - Spring Boot';
const { data: pullRequests } = await github.rest.pulls.list({
owner: 'Azure',
repo: 'azure-sdk-for-java',
state: 'open',
per_page: 100
});

const oldPRs = pullRequests.filter(pr => pr.title.startsWith(prTitlePrefix));

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
id: create_pr
if: ${{ env.need_update_version == 'true' }}
uses: vsoch/pull-request-action@master
env:
Expand All @@ -99,42 +132,19 @@ jobs:
with:
github-token: ${{ secrets.ACCESS_TOKEN }}
script: |
const { data: pullRequests } = await github.rest.pulls.list({
owner: 'Azure',
repo: 'azure-sdk-for-java',
state: 'open',
per_page: 100
});
const prNumber = '${{ steps.create_pr.outputs.pull_request_number }}';

const prTitlePrefix = 'External dependencies upgrade - Spring Boot';
const matchingPRs = pullRequests
.filter(pr => pr.title.startsWith(prTitlePrefix))
.sort((a, b) => new Date(b.created_at) - new Date(a.created_at));

if (matchingPRs.length <= 1) {
console.log('No old pull requests found to comment on.');
if (!prNumber) {
console.log('No pull request was created, nothing to comment on.');
return;
}

const latestPR = matchingPRs[0];
const comment1 = `/azp run java - spring - tests`;
console.log(`Commenting on latest PR #${latestPR.number}`);

console.log(`Commenting on PR #${prNumber}`);
await github.rest.issues.createComment({
owner: 'Azure',
repo: 'azure-sdk-for-java',
issue_number: latestPR.number,
body: comment1
owner: 'Azure',
repo: 'azure-sdk-for-java',
issue_number: prNumber,
body: comment1

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

As the comment said, it's caused by adding new commits after adding this comment, it's not caused by the error of current file, we can ignore it.

});

const comment2 = `A newer update PR has been created: #${latestPR.number} (${latestPR.html_url}). Please track updates there.`;

for (const pr of matchingPRs.slice(1)) {
console.log(`Commenting on old PR #${pr.number}`);
await github.rest.issues.createComment({
owner: 'Azure',
repo: 'azure-sdk-for-java',
issue_number: pr.number,
body: comment2
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,17 @@ public UpdateSpringDependenciesRunner(SpringProjectMetadataReader metadataReader
@Override
public void run(String... args) throws Exception {
LOGGER.info("---------- starting {} ----------", UpdateSpringDependenciesRunner.class.getSimpleName());
String latestSpringBootVersion = metadataReader.getCurrentVersion(ReleaseStatus.GENERAL_AVAILABILITY);
String RCSpringBootVersion = metadataReader.getCurrentVersion(ReleaseStatus.PRERELEASE);
String latestSpringBootVersion = metadataReader.getCurrentVersion(ReleaseStatus.GENERAL_AVAILABILITY).orElse(null);
String RCSpringBootVersion = metadataReader.getCurrentVersion(ReleaseStatus.PRERELEASE).orElse(null);
String azureSupportedSpringBootVersion = azureCurrentVersionReader.getCurrentSupportedSpringBootVersion();
String azureSupportedSpringCloudVersion = azureCurrentVersionReader.getCurrentSupportedSpringCloudVersion();
String releaseNotesContents;
String latestSpringBootMatchedSpringCloudVersion;
if (!azureSupportedSpringBootVersion.equals(latestSpringBootVersion) || !azureSupportedSpringBootVersion.equals(RCSpringBootVersion)) {
boolean isNewGaVersionAvailable = latestSpringBootVersion != null
&& !azureSupportedSpringBootVersion.equals(latestSpringBootVersion);
boolean isNewRcVersionAvailable = RCSpringBootVersion != null
&& !azureSupportedSpringBootVersion.equals(RCSpringBootVersion);
if (isNewGaVersionAvailable || isNewRcVersionAvailable) {
try (BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter("spring-versions.txt"))) {
latestSpringBootMatchedSpringCloudVersion = springCloudCompatibleSpringBootVersionRanges
.entrySet()
Expand All @@ -62,7 +66,7 @@ public void run(String... args) throws Exception {
.map(Map.Entry::getKey)
.findFirst()
.get();
if (!azureSupportedSpringBootVersion.equals(latestSpringBootVersion)) {
if (isNewGaVersionAvailable) {
releaseNotesContents = springBootReleaseNotesReader.getReleaseNotes(latestSpringBootVersion);
bufferedWriter.write(latestSpringBootVersion);
bufferedWriter.newLine();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.azure.spring.dev.tools.dependency.support;

import com.azure.spring.dev.tools.dependency.configuration.DependencyProperties;
import com.azure.spring.dev.tools.dependency.metadata.maven.Version;
import com.azure.spring.dev.tools.dependency.metadata.maven.VersionParser;
import com.azure.spring.dev.tools.dependency.metadata.spring.ProjectRelease;
import com.azure.spring.dev.tools.dependency.metadata.spring.ReleaseStatus;
Expand All @@ -10,6 +11,7 @@
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

/**
* Read a Spring project's metadata from https://spring.io/project_metadata endpoint.
Expand Down Expand Up @@ -39,17 +41,16 @@ public List<ProjectRelease> getProjectReleases() {
return metadata.getProjectReleases();
}

public String getCurrentVersion(ReleaseStatus releaseStatus) {
public Optional<String> getCurrentVersion(ReleaseStatus releaseStatus) {
return getProjectReleases()
.stream()
.filter(p -> p.getReleaseStatus().equals(releaseStatus))
.filter(p -> p.getVersion().startsWith("4"))
.map(ProjectRelease::getVersion)
.map(VersionParser.DEFAULT::parse)
.sorted(Comparator.reverseOrder())
.filter(Objects::nonNull)
.sorted(Comparator.reverseOrder())
.findFirst()
.get()
.toString();
.map(Version::toString);
}
}
Loading