Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
7617f0df
Commit
7617f0df
authored
Jun 24, 2021
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Do not publish to Sonatype when already published
Closes gh-27080
parent
0b2c86d1
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
33 deletions
+30
-33
PublishToCentralCommand.java
...ourse/releasescripts/command/PublishToCentralCommand.java
+2
-1
SonatypeService.java
...ng/concourse/releasescripts/sonatype/SonatypeService.java
+19
-21
SonatypeServiceTests.java
...ncourse/releasescripts/sonatype/SonatypeServiceTests.java
+9
-11
No files found.
ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/command/PublishToCentralCommand.java
View file @
7617f0df
...
...
@@ -72,8 +72,9 @@ public class PublishToCentralCommand implements Command {
byte
[]
content
=
Files
.
readAllBytes
(
new
File
(
buildInfoLocation
).
toPath
());
BuildInfoResponse
buildInfoResponse
=
this
.
objectMapper
.
readValue
(
content
,
BuildInfoResponse
.
class
);
BuildInfo
buildInfo
=
buildInfoResponse
.
getBuildInfo
();
ReleaseInfo
releaseInfo
=
ReleaseInfo
.
from
(
buildInfo
);
String
artifactsLocation
=
nonOptionArgs
.
get
(
3
);
this
.
sonatype
.
publish
(
ReleaseInfo
.
from
(
buildInfo
)
,
new
File
(
artifactsLocation
).
toPath
());
this
.
sonatype
.
publish
(
releaseInfo
,
new
File
(
artifactsLocation
).
toPath
());
}
}
ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/sonatype/SonatypeService.java
View file @
7617f0df
...
...
@@ -88,27 +88,6 @@ public class SonatypeService {
this
.
artifactCollector
=
new
ArtifactCollector
(
sonatypeProperties
.
getExclude
());
}
/**
* Checks if artifacts are already published to Maven Central.
* @return true if artifacts are published
* @param releaseInfo the release information
*/
public
boolean
artifactsPublished
(
ReleaseInfo
releaseInfo
)
{
try
{
ResponseEntity
<?>
entity
=
this
.
restTemplate
.
getForEntity
(
String
.
format
(
NEXUS_REPOSITORY_PATH
+
"%s/spring-boot-%s.jar.sha1"
,
releaseInfo
.
getVersion
(),
releaseInfo
.
getVersion
()),
byte
[].
class
);
if
(
HttpStatus
.
OK
.
equals
(
entity
.
getStatusCode
()))
{
logger
.
info
(
"Already published to Sonatype."
);
return
true
;
}
}
catch
(
HttpClientErrorException
ex
)
{
}
return
false
;
}
/**
* Publishes the release by creating a staging repository and deploying to it the
* artifacts at the given {@code artifactsRoot}. The repository is then closed and,
...
...
@@ -117,6 +96,9 @@ public class SonatypeService {
* @param artifactsRoot the root directory of the artifacts to stage
*/
public
void
publish
(
ReleaseInfo
releaseInfo
,
Path
artifactsRoot
)
{
if
(
artifactsPublished
(
releaseInfo
))
{
return
;
}
logger
.
info
(
"Creating staging repository"
);
String
buildId
=
releaseInfo
.
getBuildNumber
();
String
repositoryId
=
createStagingRepository
(
buildId
);
...
...
@@ -130,6 +112,22 @@ public class SonatypeService {
logger
.
info
(
"Staging repository released"
);
}
private
boolean
artifactsPublished
(
ReleaseInfo
releaseInfo
)
{
try
{
ResponseEntity
<?>
entity
=
this
.
restTemplate
.
getForEntity
(
String
.
format
(
NEXUS_REPOSITORY_PATH
+
"%s/spring-boot-%s.jar.sha1"
,
releaseInfo
.
getVersion
(),
releaseInfo
.
getVersion
()),
byte
[].
class
);
if
(
HttpStatus
.
OK
.
equals
(
entity
.
getStatusCode
()))
{
logger
.
info
(
"Already published to Sonatype."
);
return
true
;
}
}
catch
(
HttpClientErrorException
ex
)
{
}
return
false
;
}
private
String
createStagingRepository
(
String
buildId
)
{
Map
<
String
,
Object
>
body
=
new
HashMap
<>();
body
.
put
(
"data"
,
Collections
.
singletonMap
(
"description"
,
buildId
));
...
...
ci/images/releasescripts/src/test/java/io/spring/concourse/releasescripts/sonatype/SonatypeServiceTests.java
View file @
7617f0df
...
...
@@ -74,29 +74,23 @@ class SonatypeServiceTests {
}
@Test
void
artifactsPublishedWhenPublishedShouldReturnTrue
()
{
void
publishWhenAlreadyPublishedShouldNotPublish
()
{
this
.
server
.
expect
(
requestTo
(
String
.
format
(
"/service/local/repositories/releases/content/org/springframework/boot/spring-boot/%s/spring-boot-%s.jar.sha1"
,
"1.1.0.RELEASE"
,
"1.1.0.RELEASE"
))).
andExpect
(
method
(
HttpMethod
.
GET
))
.
andRespond
(
withSuccess
().
body
(
"ce8d8b6838ecceb68962b9150b18682f4237ccf71"
.
getBytes
()));
boolean
published
=
this
.
service
.
artifactsPublished
(
getReleaseInfo
());
assertThat
(
published
).
isTrue
();
Path
artifactsRoot
=
new
File
(
"src/test/resources/io/spring/concourse/releasescripts/sonatype/artifactory-repo"
)
.
toPath
();
this
.
service
.
publish
(
getReleaseInfo
(),
artifactsRoot
);
this
.
server
.
verify
();
}
@Test
void
artifactsPublishedWhenNotPublishedShouldReturnFalse
()
{
void
publishWithSuccessfulClose
()
throws
IOException
{
this
.
server
.
expect
(
requestTo
(
String
.
format
(
"/service/local/repositories/releases/content/org/springframework/boot/spring-boot/%s/spring-boot-%s.jar.sha1"
,
"1.1.0.RELEASE"
,
"1.1.0.RELEASE"
))).
andExpect
(
method
(
HttpMethod
.
GET
))
.
andRespond
(
withStatus
(
HttpStatus
.
NOT_FOUND
));
boolean
published
=
this
.
service
.
artifactsPublished
(
getReleaseInfo
());
assertThat
(
published
).
isFalse
();
this
.
server
.
verify
();
}
@Test
void
publishWithSuccessfulClose
()
throws
IOException
{
this
.
server
.
expect
(
requestTo
(
"/service/local/staging/profiles/1a2b3c4d/start"
))
.
andExpect
(
method
(
HttpMethod
.
POST
)).
andExpect
(
header
(
"Content-Type"
,
"application/json"
))
.
andExpect
(
header
(
"Accept"
,
"application/json, application/*+json"
))
...
...
@@ -145,6 +139,10 @@ class SonatypeServiceTests {
@Test
void
publishWithCloseFailureDueToRuleViolations
()
throws
IOException
{
this
.
server
.
expect
(
requestTo
(
String
.
format
(
"/service/local/repositories/releases/content/org/springframework/boot/spring-boot/%s/spring-boot-%s.jar.sha1"
,
"1.1.0.RELEASE"
,
"1.1.0.RELEASE"
))).
andExpect
(
method
(
HttpMethod
.
GET
))
.
andRespond
(
withStatus
(
HttpStatus
.
NOT_FOUND
));
this
.
server
.
expect
(
requestTo
(
"/service/local/staging/profiles/1a2b3c4d/start"
))
.
andExpect
(
method
(
HttpMethod
.
POST
)).
andExpect
(
header
(
"Content-Type"
,
"application/json"
))
.
andExpect
(
header
(
"Accept"
,
"application/json, application/*+json"
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment