Allow certain artifacts to be optionally deployed

Update `DistributeCommand` so that regex patterns can be used to mark
artifacts that are optional and need not fail the release.

Closes gh-22543
This commit is contained in:
Phillip Webb
2020-07-23 20:45:25 -07:00
parent d69c35a1db
commit b77dbcd06f
5 changed files with 153 additions and 4 deletions

View File

@@ -16,6 +16,7 @@
package io.spring.concourse.releasescripts.command;
import java.util.Arrays;
import java.util.Set;
import com.fasterxml.jackson.databind.DeserializationFeature;
@@ -42,6 +43,7 @@ import static org.mockito.Mockito.verifyNoInteractions;
* Tests for {@link DistributeCommand}.
*
* @author Madhura Bhave
* @author Phillip Webb
*/
class DistributeCommandTests {
@@ -55,8 +57,10 @@ class DistributeCommandTests {
@BeforeEach
void setup() {
MockitoAnnotations.initMocks(this);
DistributeProperties distributeProperties = new DistributeProperties();
distributeProperties.setOptionalDeployments(Arrays.asList(".*\\.zip", "demo-\\d\\.\\d\\.\\d\\.doc"));
this.objectMapper = new ObjectMapper().disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
this.command = new DistributeCommand(this.service, this.objectMapper);
this.command = new DistributeCommand(this.service, this.objectMapper, distributeProperties);
}
@Test
@@ -94,8 +98,30 @@ class DistributeCommandTests {
assertThat(artifactDigests).containsExactly("aaaaaaaaa85f5c5093721f3ed0edda8ff8290yyyyyyyyyy");
}
@Test
@SuppressWarnings("unchecked")
void distributeWhenReleaseTypeReleaseAndFilteredShouldCallService() throws Exception {
ArgumentCaptor<ReleaseInfo> releaseInfoCaptor = ArgumentCaptor.forClass(ReleaseInfo.class);
ArgumentCaptor<Set<String>> artifactDigestCaptor = ArgumentCaptor.forClass(Set.class);
this.command.run(new DefaultApplicationArguments("distribute", "RELEASE",
getBuildInfoLocation("filtered-build-info-response.json")));
verify(this.service).distribute(eq(ReleaseType.RELEASE.getRepo()), releaseInfoCaptor.capture(),
artifactDigestCaptor.capture());
ReleaseInfo releaseInfo = releaseInfoCaptor.getValue();
assertThat(releaseInfo.getBuildName()).isEqualTo("example");
assertThat(releaseInfo.getBuildNumber()).isEqualTo("example-build-1");
assertThat(releaseInfo.getGroupId()).isEqualTo("org.example.demo");
assertThat(releaseInfo.getVersion()).isEqualTo("2.2.0");
Set<String> artifactDigests = artifactDigestCaptor.getValue();
assertThat(artifactDigests).containsExactly("aaaaaaaaa85f5c5093721f3ed0edda8ff8290yyyyyyyyyy");
}
private String getBuildInfoLocation() throws Exception {
return new ClassPathResource("build-info-response.json", ArtifactoryService.class).getFile().getAbsolutePath();
return getBuildInfoLocation("build-info-response.json");
}
private String getBuildInfoLocation(String file) throws Exception {
return new ClassPathResource(file, ArtifactoryService.class).getFile().getAbsolutePath();
}
}

View File

@@ -9,3 +9,7 @@ bintray:
sonatype:
user-token: sonatype-user
password-token: sonatype-password
distribute:
optional-deployments:
- '.*\.zip'
- 'spring-boot-project-\d\.\d\.\d(?:\.RELEASE)?\.pom'

View File

@@ -0,0 +1,59 @@
{
"buildInfo": {
"version": "1.0.1",
"name": "example",
"number": "example-build-1",
"started": "2019-09-10T12:18:05.430+0000",
"durationMillis": 0,
"artifactoryPrincipal": "user",
"url": "https://my-ci.com",
"modules": [
{
"id": "org.example.demo:demo:2.2.0",
"artifacts": [
{
"type": "jar",
"sha1": "ayyyya9151a22cb3145538e523dbbaaaaaaaa",
"sha256": "aaaaaaaaa85f5c5093721f3ed0edda8ff8290yyyyyyyyyy",
"md5": "aaaaaacddea1724b0b69d8yyyyyyy",
"name": "demo-2.2.0.jar"
}
]
},
{
"id": "org.example.demo:demo:2.2.0:zip",
"artifacts": [
{
"type": "zip",
"sha1": "ayyyya9151a22cb3145538e523dbbaaaaaaab",
"sha256": "aaaaaaaaa85f5c5093721f3ed0edda8ff8290yyyyyyyyyz",
"md5": "aaaaaacddea1724b0b69d8yyyyyyz",
"name": "demo-2.2.0.zip"
}
]
},
{
"id": "org.example.demo:demo:2.2.0:doc",
"artifacts": [
{
"type": "jar",
"sha1": "ayyyya9151a22cb3145538e523dbbaaaaaaba",
"sha256": "aaaaaaaaa85f5c5093721f3ed0edda8ff8290yyyyyyyyzy",
"md5": "aaaaaacddea1724b0b69d8yyyyyzy",
"name": "demo-2.2.0.doc"
}
]
}
],
"statuses": [
{
"status": "staged",
"repository": "libs-release-local",
"timestamp": "2019-09-10T12:42:24.716+0000",
"user": "user",
"timestampDate": 1568119344716
}
]
},
"uri": "https://my-artifactory-repo.com/api/build/example/example-build-1"
}