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

@@ -20,6 +20,8 @@ import java.io.File;
import java.nio.file.Files;
import java.util.List;
import java.util.Set;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.spring.concourse.releasescripts.ReleaseInfo;
@@ -40,6 +42,7 @@ import org.springframework.util.Assert;
* Command used to deploy builds from Artifactory to Bintray.
*
* @author Madhura Bhave
* @author Phillip Webb
*/
@Component
public class DistributeCommand implements Command {
@@ -50,9 +53,14 @@ public class DistributeCommand implements Command {
private final ObjectMapper objectMapper;
public DistributeCommand(ArtifactoryService artifactoryService, ObjectMapper objectMapper) {
private final List<Pattern> optionalDeployments;
public DistributeCommand(ArtifactoryService artifactoryService, ObjectMapper objectMapper,
DistributeProperties distributeProperties) {
this.artifactoryService = artifactoryService;
this.objectMapper = objectMapper;
this.optionalDeployments = distributeProperties.getOptionalDeployments().stream().map(Pattern::compile)
.collect(Collectors.toList());
}
@Override
@@ -80,8 +88,18 @@ public class DistributeCommand implements Command {
}
}
ReleaseInfo releaseInfo = ReleaseInfo.from(buildInfo);
Set<String> artifactDigests = buildInfo.getArtifactDigests((artifact) -> !artifact.getName().endsWith(".zip"));
Set<String> artifactDigests = buildInfo.getArtifactDigests(this::isIncluded);
this.artifactoryService.distribute(type.getRepo(), releaseInfo, artifactDigests);
}
private boolean isIncluded(Artifact artifact) {
String path = artifact.getName();
for (Pattern optionalDeployment : this.optionalDeployments) {
if (optionalDeployment.matcher(path).matches()) {
return false;
}
}
return true;
}
}

View File

@@ -0,0 +1,42 @@
/*
* Copyright 2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.spring.concourse.releasescripts.command;
import java.util.ArrayList;
import java.util.List;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
* Distribution properties.
*
* @author Phillip Webb
*/
@ConfigurationProperties(prefix = "distribute")
public class DistributeProperties {
private List<String> optionalDeployments = new ArrayList<>();
public List<String> getOptionalDeployments() {
return this.optionalDeployments;
}
public void setOptionalDeployments(List<String> optionalDeployments) {
this.optionalDeployments = optionalDeployments;
}
}