Skip to content

Commit c150a91

Browse files
committed
Merge branch '2.4.x' into 2.5.x
Closes gh-27082
2 parents 5a9fa3c + 2ea8367 commit c150a91

File tree

3 files changed

+30
-33
lines changed

3 files changed

+30
-33
lines changed

ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/command/PublishToCentralCommand.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,9 @@ public void run(ApplicationArguments args) throws Exception {
7272
byte[] content = Files.readAllBytes(new File(buildInfoLocation).toPath());
7373
BuildInfoResponse buildInfoResponse = this.objectMapper.readValue(content, BuildInfoResponse.class);
7474
BuildInfo buildInfo = buildInfoResponse.getBuildInfo();
75+
ReleaseInfo releaseInfo = ReleaseInfo.from(buildInfo);
7576
String artifactsLocation = nonOptionArgs.get(3);
76-
this.sonatype.publish(ReleaseInfo.from(buildInfo), new File(artifactsLocation).toPath());
77+
this.sonatype.publish(releaseInfo, new File(artifactsLocation).toPath());
7778
}
7879

7980
}

ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/sonatype/SonatypeService.java

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -88,27 +88,6 @@ public SonatypeService(RestTemplateBuilder builder, SonatypeProperties sonatypeP
8888
this.artifactCollector = new ArtifactCollector(sonatypeProperties.getExclude());
8989
}
9090

91-
/**
92-
* Checks if artifacts are already published to Maven Central.
93-
* @return true if artifacts are published
94-
* @param releaseInfo the release information
95-
*/
96-
public boolean artifactsPublished(ReleaseInfo releaseInfo) {
97-
try {
98-
ResponseEntity<?> entity = this.restTemplate
99-
.getForEntity(String.format(NEXUS_REPOSITORY_PATH + "%s/spring-boot-%s.jar.sha1",
100-
releaseInfo.getVersion(), releaseInfo.getVersion()), byte[].class);
101-
if (HttpStatus.OK.equals(entity.getStatusCode())) {
102-
logger.info("Already published to Sonatype.");
103-
return true;
104-
}
105-
}
106-
catch (HttpClientErrorException ex) {
107-
108-
}
109-
return false;
110-
}
111-
11291
/**
11392
* Publishes the release by creating a staging repository and deploying to it the
11493
* artifacts at the given {@code artifactsRoot}. The repository is then closed and,
@@ -117,6 +96,9 @@ public boolean artifactsPublished(ReleaseInfo releaseInfo) {
11796
* @param artifactsRoot the root directory of the artifacts to stage
11897
*/
11998
public void publish(ReleaseInfo releaseInfo, Path artifactsRoot) {
99+
if (artifactsPublished(releaseInfo)) {
100+
return;
101+
}
120102
logger.info("Creating staging repository");
121103
String buildId = releaseInfo.getBuildNumber();
122104
String repositoryId = createStagingRepository(buildId);
@@ -130,6 +112,22 @@ public void publish(ReleaseInfo releaseInfo, Path artifactsRoot) {
130112
logger.info("Staging repository released");
131113
}
132114

115+
private boolean artifactsPublished(ReleaseInfo releaseInfo) {
116+
try {
117+
ResponseEntity<?> entity = this.restTemplate
118+
.getForEntity(String.format(NEXUS_REPOSITORY_PATH + "%s/spring-boot-%s.jar.sha1",
119+
releaseInfo.getVersion(), releaseInfo.getVersion()), byte[].class);
120+
if (HttpStatus.OK.equals(entity.getStatusCode())) {
121+
logger.info("Already published to Sonatype.");
122+
return true;
123+
}
124+
}
125+
catch (HttpClientErrorException ex) {
126+
127+
}
128+
return false;
129+
}
130+
133131
private String createStagingRepository(String buildId) {
134132
Map<String, Object> body = new HashMap<>();
135133
body.put("data", Collections.singletonMap("description", buildId));

ci/images/releasescripts/src/test/java/io/spring/concourse/releasescripts/sonatype/SonatypeServiceTests.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,29 +74,23 @@ void tearDown() {
7474
}
7575

7676
@Test
77-
void artifactsPublishedWhenPublishedShouldReturnTrue() {
77+
void publishWhenAlreadyPublishedShouldNotPublish() {
7878
this.server.expect(requestTo(String.format(
7979
"/service/local/repositories/releases/content/org/springframework/boot/spring-boot/%s/spring-boot-%s.jar.sha1",
8080
"1.1.0.RELEASE", "1.1.0.RELEASE"))).andExpect(method(HttpMethod.GET))
8181
.andRespond(withSuccess().body("ce8d8b6838ecceb68962b9150b18682f4237ccf71".getBytes()));
82-
boolean published = this.service.artifactsPublished(getReleaseInfo());
83-
assertThat(published).isTrue();
82+
Path artifactsRoot = new File("src/test/resources/io/spring/concourse/releasescripts/sonatype/artifactory-repo")
83+
.toPath();
84+
this.service.publish(getReleaseInfo(), artifactsRoot);
8485
this.server.verify();
8586
}
8687

8788
@Test
88-
void artifactsPublishedWhenNotPublishedShouldReturnFalse() {
89+
void publishWithSuccessfulClose() throws IOException {
8990
this.server.expect(requestTo(String.format(
9091
"/service/local/repositories/releases/content/org/springframework/boot/spring-boot/%s/spring-boot-%s.jar.sha1",
9192
"1.1.0.RELEASE", "1.1.0.RELEASE"))).andExpect(method(HttpMethod.GET))
9293
.andRespond(withStatus(HttpStatus.NOT_FOUND));
93-
boolean published = this.service.artifactsPublished(getReleaseInfo());
94-
assertThat(published).isFalse();
95-
this.server.verify();
96-
}
97-
98-
@Test
99-
void publishWithSuccessfulClose() throws IOException {
10094
this.server.expect(requestTo("/service/local/staging/profiles/1a2b3c4d/start"))
10195
.andExpect(method(HttpMethod.POST)).andExpect(header("Content-Type", "application/json"))
10296
.andExpect(header("Accept", "application/json, application/*+json"))
@@ -145,6 +139,10 @@ void publishWithSuccessfulClose() throws IOException {
145139

146140
@Test
147141
void publishWithCloseFailureDueToRuleViolations() throws IOException {
142+
this.server.expect(requestTo(String.format(
143+
"/service/local/repositories/releases/content/org/springframework/boot/spring-boot/%s/spring-boot-%s.jar.sha1",
144+
"1.1.0.RELEASE", "1.1.0.RELEASE"))).andExpect(method(HttpMethod.GET))
145+
.andRespond(withStatus(HttpStatus.NOT_FOUND));
148146
this.server.expect(requestTo("/service/local/staging/profiles/1a2b3c4d/start"))
149147
.andExpect(method(HttpMethod.POST)).andExpect(header("Content-Type", "application/json"))
150148
.andExpect(header("Accept", "application/json, application/*+json"))

0 commit comments

Comments
 (0)