Skip to content

Commit

Permalink
[release] finer control on which assets get released. Resolves #321
Browse files Browse the repository at this point in the history
  • Loading branch information
aalmiray committed Jul 29, 2021
1 parent 78a052f commit 061e34e
Show file tree
Hide file tree
Showing 7 changed files with 219 additions and 55 deletions.
121 changes: 92 additions & 29 deletions core/jreleaser-model/src/main/java/org/jreleaser/model/GitService.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
* @since 0.1.0
*/
public abstract class GitService implements Releaser, CommitAuthorAware, OwnerAware, TimeoutAware {
public static final String KEY_SKIP_RELEASE = "skipRelease";
public static final String KEY_SKIP_RELEASE_SIGNATURES = "skipReleaseSignatures";

public static final String TAG_NAME = "TAG_NAME";
public static final String RELEASE_NAME = "RELEASE_NAME";
public static final String OVERWRITE = "OVERWRITE";
Expand Down Expand Up @@ -79,6 +82,10 @@ public abstract class GitService implements Releaser, CommitAuthorAware, OwnerAw
private String apiEndpoint;
private int connectTimeout;
private int readTimeout;
private Boolean artifacts;
private Boolean files;
private Boolean checksums;
private Boolean signatures;

private String cachedTagName;
private String cachedReleaseName;
Expand Down Expand Up @@ -122,6 +129,10 @@ void setAll(GitService service) {
this.apiEndpoint = service.apiEndpoint;
this.connectTimeout = service.connectTimeout;
this.readTimeout = service.readTimeout;
this.artifacts = service.artifacts;
this.files = service.files;
this.checksums = service.checksums;
this.signatures = service.signatures;
setCommitAuthor(service.commitAuthor);
setChangelog(service.changelog);
setMilestone(service.milestone);
Expand Down Expand Up @@ -571,45 +582,97 @@ public void setReadTimeout(int readTimeout) {
this.readTimeout = readTimeout;
}

public boolean isArtifactsSet() {
return artifacts != null;
}

public Boolean isArtifacts() {
return artifacts == null || artifacts;
}

public void setArtifacts(Boolean artifacts) {
this.artifacts = artifacts;
}

public Boolean isFiles() {
return files == null || files;
}

public boolean isFilesSet() {
return files != null;
}

public void setFiles(Boolean files) {
this.files = files;
}

public boolean isChecksumsSet() {
return checksums != null;
}

public Boolean isChecksums() {
return checksums == null || checksums;
}

public void setChecksums(Boolean checksums) {
this.checksums = checksums;
}

public boolean isSignaturesSet() {
return signatures != null;
}

public Boolean isSignatures() {
return signatures == null || signatures;
}

public void setSignatures(Boolean signatures) {
this.signatures = signatures;
}

@Override
public Map<String, Object> asMap(boolean full) {
Map<String, Object> map = new LinkedHashMap<>();
map.put("enabled", isEnabled());
map.put("host", host);
map.put("owner", owner);
map.put("name", name);
map.put("username", username);
map.put("token", isNotBlank(getResolvedToken()) ? Constants.HIDE : Constants.UNSET);
Map<String, Object> props = new LinkedHashMap<>();
props.put("enabled", isEnabled());
props.put("host", host);
props.put("owner", owner);
props.put("name", name);
props.put("username", username);
props.put("token", isNotBlank(getResolvedToken()) ? Constants.HIDE : Constants.UNSET);
if (releaseSupported) {
map.put("repoUrl", repoUrl);
map.put("repoCloneUrl", repoCloneUrl);
map.put("commitUrl", commitUrl);
map.put("downloadUrl", downloadUrl);
map.put("releaseNotesUrl", releaseNotesUrl);
map.put("latestReleaseUrl", latestReleaseUrl);
map.put("issueTrackerUrl", issueTrackerUrl);
props.put("artifacts", isArtifacts());
props.put("files", isFiles());
props.put("checksums", isChecksums());
props.put("signatures", isSignatures());
props.put("repoUrl", repoUrl);
props.put("repoCloneUrl", repoCloneUrl);
props.put("commitUrl", commitUrl);
props.put("downloadUrl", downloadUrl);
props.put("releaseNotesUrl", releaseNotesUrl);
props.put("latestReleaseUrl", latestReleaseUrl);
props.put("issueTrackerUrl", issueTrackerUrl);
}
map.put("tagName", tagName);
props.put("tagName", tagName);
if (releaseSupported) {
map.put("releaseName", releaseName);
props.put("releaseName", releaseName);
}
map.put("branch", branch);
map.put("commitAuthor", commitAuthor.asMap(full));
map.put("sign", sign);
map.put("skipTag", isSkipTag());
map.put("overwrite", isOverwrite());
props.put("branch", branch);
props.put("commitAuthor", commitAuthor.asMap(full));
props.put("sign", sign);
props.put("skipTag", isSkipTag());
props.put("overwrite", isOverwrite());
if (releaseSupported) {
map.put("update", isUpdate());
map.put("updateSections", updateSections);
map.put("apiEndpoint", apiEndpoint);
map.put("connectTimeout", connectTimeout);
map.put("readTimeout", readTimeout);
props.put("update", isUpdate());
props.put("updateSections", updateSections);
props.put("apiEndpoint", apiEndpoint);
props.put("connectTimeout", connectTimeout);
props.put("readTimeout", readTimeout);
}
map.put("changelog", changelog.asMap(full));
props.put("changelog", changelog.asMap(full));
if (releaseSupported) {
map.put("milestone", milestone.asMap(full));
props.put("milestone", milestone.asMap(full));
}
return map;
return props;
}

public Map<String, Object> props(JReleaserModel model) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import org.jreleaser.model.Artifact;
import org.jreleaser.model.Distribution;
import org.jreleaser.model.GitService;
import org.jreleaser.model.JReleaserContext;
import org.jreleaser.model.util.Artifacts;
import org.jreleaser.util.Algorithm;
Expand All @@ -31,6 +32,8 @@

import static java.util.Objects.requireNonNull;
import static org.jreleaser.model.Checksum.INDIVIDUAL_CHECKSUM;
import static org.jreleaser.model.GitService.KEY_SKIP_RELEASE;
import static org.jreleaser.model.GitService.KEY_SKIP_RELEASE_SIGNATURES;
import static org.jreleaser.model.Signing.KEY_SKIP_SIGNING;
import static org.jreleaser.util.StringUtils.isTrue;

Expand Down Expand Up @@ -76,48 +79,56 @@ protected void validate() {
@Override
public ReleaserBuilder<R> configureWith(JReleaserContext context) {
this.context = context;
GitService service = context.getModel().getRelease().getGitService();

List<Artifact> artifacts = new ArrayList<>();

for (Artifact artifact : Artifacts.resolveFiles(context)) {
if (!artifact.isActive()) continue;
Path path = artifact.getEffectivePath(context);
artifacts.add(Artifact.of(path, artifact.getExtraProperties()));
if (isIndividual(context, artifact)) {
for (Algorithm algorithm : context.getModel().getChecksum().getAlgorithms()) {
artifacts.add(Artifact.of(context.getChecksumsDirectory()
.resolve(path.getFileName() + "." + algorithm.formatted())));
}
}
}

for (Distribution distribution : context.getModel().getActiveDistributions()) {
for (Artifact artifact : distribution.getArtifacts()) {
if (!artifact.isActive()) continue;
Path path = artifact.getEffectivePath(context, distribution);
if (service.isFiles()) {
for (Artifact artifact : Artifacts.resolveFiles(context)) {
if (!artifact.isActive() || artifact.extraPropertyIsTrue(KEY_SKIP_RELEASE)) continue;
Path path = artifact.getEffectivePath(context);
artifacts.add(Artifact.of(path, artifact.getExtraProperties()));
if (isIndividual(context, distribution, artifact)) {
if (service.isChecksums() && isIndividual(context, artifact)) {
for (Algorithm algorithm : context.getModel().getChecksum().getAlgorithms()) {
artifacts.add(Artifact.of(context.getChecksumsDirectory()
.resolve(distribution.getName())
.resolve(path.getFileName() + "." + algorithm.formatted())));
}
}
}
}

for (Algorithm algorithm : context.getModel().getChecksum().getAlgorithms()) {
Path checksums = context.getChecksumsDirectory()
.resolve(context.getModel().getChecksum().getResolvedName(context, algorithm));
if (Files.exists(checksums)) {
artifacts.add(Artifact.of(checksums));
if (service.isArtifacts()) {
for (Distribution distribution : context.getModel().getActiveDistributions()) {
if (distribution.extraPropertyIsTrue(KEY_SKIP_RELEASE)) continue;
for (Artifact artifact : distribution.getArtifacts()) {
if (!artifact.isActive() || artifact.extraPropertyIsTrue(KEY_SKIP_RELEASE)) continue;
Path path = artifact.getEffectivePath(context, distribution);
artifacts.add(Artifact.of(path, artifact.getExtraProperties()));
if (service.isChecksums() && isIndividual(context, distribution, artifact)) {
for (Algorithm algorithm : context.getModel().getChecksum().getAlgorithms()) {
artifacts.add(Artifact.of(context.getChecksumsDirectory()
.resolve(distribution.getName())
.resolve(path.getFileName() + "." + algorithm.formatted())));
}
}
}
}
}

if (service.isChecksums()) {
for (Algorithm algorithm : context.getModel().getChecksum().getAlgorithms()) {
Path checksums = context.getChecksumsDirectory()
.resolve(context.getModel().getChecksum().getResolvedName(context, algorithm));
if (Files.exists(checksums)) {
artifacts.add(Artifact.of(checksums));
}
}
}

if (context.getModel().getSigning().isEnabled()) {
if (context.getModel().getSigning().isEnabled() && service.isSignatures()) {
List<Artifact> artifactsCopy = new ArrayList<>(artifacts);
for (Artifact artifact : artifactsCopy) {
if (artifact.extraPropertyIsTrue(KEY_SKIP_SIGNING)) continue;
if (artifact.extraPropertyIsTrue(KEY_SKIP_SIGNING) ||
artifact.extraPropertyIsTrue(KEY_SKIP_RELEASE_SIGNATURES)) continue;
Path signature = context.getSignaturesDirectory()
.resolve(artifact.getResolvedPath().getFileName().toString() + (context.getModel().getSigning().isArmored() ? ".asc" : ".sig"));
if (Files.exists(signature)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.util.stream.Collectors;

import static java.util.stream.Collectors.groupingBy;
import static org.jreleaser.model.GitService.KEY_SKIP_RELEASE_SIGNATURES;
import static org.jreleaser.model.validation.BrewValidator.postValidateBrew;
import static org.jreleaser.model.validation.BrewValidator.validateBrew;
import static org.jreleaser.model.validation.ChocolateyValidator.validateChocolatey;
Expand Down Expand Up @@ -127,6 +128,11 @@ private static void validateDistribution(JReleaserContext context, Distribution
for (Artifact artifact : distribution.getArtifacts()) {
if (artifact.isActive()) {
validateArtifact(context, distribution, artifact, i++, errors);
if (distribution.getExtraProperties().containsKey(KEY_SKIP_RELEASE_SIGNATURES) &&
!artifact.getExtraProperties().containsKey(KEY_SKIP_RELEASE_SIGNATURES)) {
artifact.getExtraProperties().put(KEY_SKIP_RELEASE_SIGNATURES,
distribution.getExtraProperties().get(KEY_SKIP_RELEASE_SIGNATURES));
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ interface GitService extends Releaser {

Property<Integer> getReadTimeout()

Property<Boolean> getArtifacts()

Property<Boolean> getFiles()

Property<Boolean> getChecksums()

Property<Boolean> getSignatures()

Property<Boolean> getOverwrite()

Property<Boolean> getUpdate()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ abstract class AbstractGitService implements GitService {
final Property<String> apiEndpoint
final Property<Integer> connectTimeout
final Property<Integer> readTimeout
final Property<Boolean> artifacts
final Property<Boolean> files
final Property<Boolean> checksums
final Property<Boolean> signatures
final Property<Boolean> overwrite
final Property<Boolean> update
final SetProperty<UpdateSection> updateSections
Expand Down Expand Up @@ -91,6 +95,10 @@ abstract class AbstractGitService implements GitService {
apiEndpoint = objects.property(String).convention(Providers.notDefined())
connectTimeout = objects.property(Integer).convention(Providers.notDefined())
readTimeout = objects.property(Integer).convention(Providers.notDefined())
artifacts = objects.property(Boolean).convention(Providers.notDefined())
files = objects.property(Boolean).convention(Providers.notDefined())
checksums = objects.property(Boolean).convention(Providers.notDefined())
signatures = objects.property(Boolean).convention(Providers.notDefined())
overwrite = objects.property(Boolean).convention(Providers.notDefined())
update = objects.property(Boolean).convention(Providers.notDefined())
updateSections = objects.setProperty(UpdateSection).convention(Providers.notDefined())
Expand Down Expand Up @@ -168,6 +176,10 @@ abstract class AbstractGitService implements GitService {
apiEndpoint.present ||
connectTimeout.present ||
readTimeout.present ||
artifacts.present ||
files.present ||
checksums.present ||
signatures.present ||
overwrite.present ||
update.present ||
updateSections.present
Expand Down Expand Up @@ -230,6 +242,10 @@ abstract class AbstractGitService implements GitService {
if (apiEndpoint.present) service.apiEndpoint = apiEndpoint.get()
if (connectTimeout.present) service.connectTimeout = connectTimeout.get()
if (readTimeout.present) service.readTimeout = readTimeout.get()
if (artifacts.present) service.artifacts = artifacts.get()
if (files.present) service.files = files.get()
if (checksums.present) service.checksums = checksums.get()
if (signatures.present) service.signatures = signatures.get()
service.sign = sign.getOrElse(false)
service.skipTag = skipTag.getOrElse(false)
service.overwrite = overwrite.getOrElse(false)
Expand Down

0 comments on commit 061e34e

Please sign in to comment.