mirror of
https://github.com/jlengrand/jreleaser.git
synced 2026-03-10 08:31:24 +00:00
[core] dryrun should not cause validation errors for secrets. Fixes #172
This commit is contained in:
@@ -66,7 +66,8 @@ public abstract class ArtifactoryValidator extends Validator {
|
||||
"ARTIFACTORY_" + Env.toVar(artifactory.getName()) + "_PASSWORD",
|
||||
"artifactory.password",
|
||||
artifactory.getPassword(),
|
||||
errors));
|
||||
errors,
|
||||
context.isDryrun()));
|
||||
break;
|
||||
case BASIC:
|
||||
artifactory.setUsername(
|
||||
@@ -74,14 +75,16 @@ public abstract class ArtifactoryValidator extends Validator {
|
||||
"ARTIFACTORY_" + Env.toVar(artifactory.getName()) + "_USERNAME",
|
||||
"artifactory.username",
|
||||
artifactory.getUsername(),
|
||||
new Errors()));
|
||||
errors,
|
||||
context.isDryrun()));
|
||||
|
||||
artifactory.setPassword(
|
||||
checkProperty(context.getModel().getEnvironment(),
|
||||
"ARTIFACTORY_" + Env.toVar(artifactory.getName()) + "_PASSWORD",
|
||||
"artifactory.password",
|
||||
artifactory.getPassword(),
|
||||
errors));
|
||||
errors,
|
||||
context.isDryrun()));
|
||||
break;
|
||||
case NONE:
|
||||
errors.configuration("artifactory." + artifactory.getName() + ".authorization can not be NONE");
|
||||
|
||||
@@ -43,7 +43,8 @@ public abstract class DiscordValidator extends Validator {
|
||||
DISCORD_WEBHOOK,
|
||||
"discord.webhook",
|
||||
discord.getWebhook(),
|
||||
errors));
|
||||
errors,
|
||||
context.isDryrun()));
|
||||
|
||||
if (isBlank(discord.getMessage()) && isBlank(discord.getMessageTemplate())) {
|
||||
if (Files.exists(context.getBasedir().resolve(DEFAULT_DISCORD_TPL))) {
|
||||
|
||||
@@ -278,7 +278,8 @@ public abstract class DockerValidator extends Validator {
|
||||
"DOCKER_" + Env.toVar(registry.getServerName()) + "_PASSWORD",
|
||||
"registry." + Env.toVar(registry.getServerName()) + ".password",
|
||||
registry.getPassword(),
|
||||
errors));
|
||||
errors,
|
||||
context.isDryrun()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,8 @@ public abstract class GitterValidator extends Validator {
|
||||
GITTER_WEBHOOK,
|
||||
"gitter.webhook",
|
||||
gitter.getWebhook(),
|
||||
errors));
|
||||
errors,
|
||||
context.isDryrun()));
|
||||
|
||||
if (isBlank(gitter.getMessage()) && isBlank(gitter.getMessageTemplate())) {
|
||||
if (Files.exists(context.getBasedir().resolve(DEFAULT_GITTER_TPL))) {
|
||||
|
||||
@@ -74,7 +74,8 @@ public abstract class HttpUploaderValidator extends Validator {
|
||||
"HTTP_" + Env.toVar(http.getName()) + "_PASSWORD",
|
||||
"http.password",
|
||||
http.getPassword(),
|
||||
errors));
|
||||
errors,
|
||||
context.isDryrun()));
|
||||
break;
|
||||
case BASIC:
|
||||
http.setUsername(
|
||||
@@ -82,14 +83,16 @@ public abstract class HttpUploaderValidator extends Validator {
|
||||
"HTTP_" + Env.toVar(http.getName()) + "_USERNAME",
|
||||
"http.username",
|
||||
http.getUsername(),
|
||||
new Errors()));
|
||||
errors,
|
||||
context.isDryrun()));
|
||||
|
||||
http.setPassword(
|
||||
checkProperty(context.getModel().getEnvironment(),
|
||||
"HTTP_" + Env.toVar(http.getName()) + "_PASSWORD",
|
||||
"http.password",
|
||||
http.getPassword(),
|
||||
errors));
|
||||
errors,
|
||||
context.isDryrun()));
|
||||
break;
|
||||
case NONE:
|
||||
break;
|
||||
|
||||
@@ -61,7 +61,8 @@ public abstract class MailValidator extends Validator {
|
||||
MAIL_PASSWORD,
|
||||
"mail.password",
|
||||
mail.getPassword(),
|
||||
errors));
|
||||
errors,
|
||||
context.isDryrun()));
|
||||
|
||||
if (isBlank(mail.getFrom())) {
|
||||
errors.configuration("mail.from must not be blank.");
|
||||
|
||||
@@ -42,7 +42,8 @@ public abstract class MastodonValidator extends Validator {
|
||||
MASTODON_ACCESS_TOKEN,
|
||||
"mastodon.accessToken",
|
||||
mastodon.getAccessToken(),
|
||||
errors));
|
||||
errors,
|
||||
context.isDryrun()));
|
||||
|
||||
if (isBlank(mastodon.getStatus())) {
|
||||
mastodon.setStatus("\uD83D\uDE80 {{projectNameCapitalized}} {{projectVersion}} has been released! {{releaseNotesUrl}}");
|
||||
|
||||
@@ -43,7 +43,8 @@ public abstract class MattermostValidator extends Validator {
|
||||
MATTERMOST_WEBHOOK,
|
||||
"mattermost.webhook",
|
||||
mattermost.getWebhook(),
|
||||
errors));
|
||||
errors,
|
||||
context.isDryrun()));
|
||||
|
||||
if (isBlank(mattermost.getMessage()) && isBlank(mattermost.getMessageTemplate())) {
|
||||
if (Files.exists(context.getBasedir().resolve(DEFAULT_MATTERMOST_TPL))) {
|
||||
|
||||
@@ -51,17 +51,16 @@ public abstract class ScoopValidator extends Validator {
|
||||
validateCommitAuthor(tool, parentTool);
|
||||
validateOwner(tool.getBucket(), parentTool.getBucket());
|
||||
validateTemplate(context, distribution, tool, parentTool, errors);
|
||||
Scoop commonScoop = parentTool;
|
||||
mergeExtraProperties(tool, parentTool);
|
||||
|
||||
if (isBlank(tool.getCheckverUrl())) {
|
||||
tool.setCheckverUrl(commonScoop.getCheckverUrl());
|
||||
tool.setCheckverUrl(parentTool.getCheckverUrl());
|
||||
if (isBlank(tool.getCheckverUrl())) {
|
||||
tool.setCheckverUrl(model.getRelease().getGitService().getLatestReleaseUrlFormat());
|
||||
}
|
||||
}
|
||||
if (isBlank(tool.getAutoupdateUrl())) {
|
||||
tool.setAutoupdateUrl(commonScoop.getAutoupdateUrl());
|
||||
tool.setAutoupdateUrl(parentTool.getAutoupdateUrl());
|
||||
if (isBlank(tool.getAutoupdateUrl())) {
|
||||
tool.setAutoupdateUrl(model.getRelease().getGitService().getDownloadUrlFormat());
|
||||
}
|
||||
|
||||
@@ -43,14 +43,16 @@ public abstract class SdkmanValidator extends Validator {
|
||||
SDKMAN_CONSUMER_KEY,
|
||||
"sdkman.consumerKey",
|
||||
sdkman.getConsumerKey(),
|
||||
errors));
|
||||
errors,
|
||||
context.isDryrun()));
|
||||
|
||||
sdkman.setConsumerToken(
|
||||
checkProperty(context.getModel().getEnvironment(),
|
||||
SDKMAN_CONSUMER_TOKEN,
|
||||
"sdkman.consumerToken",
|
||||
sdkman.getConsumerToken(),
|
||||
errors));
|
||||
errors,
|
||||
context.isDryrun()));
|
||||
|
||||
if (context.getModel().getActiveDistributions().isEmpty()) {
|
||||
context.getLogger().warn("There are no active distributions. Disabling Sdkman announcer");
|
||||
|
||||
@@ -49,20 +49,23 @@ public abstract class SigningValidator extends Validator {
|
||||
GPG_PASSPHRASE,
|
||||
"signing.passphrase",
|
||||
signing.getPassphrase(),
|
||||
errors));
|
||||
errors,
|
||||
context.isDryrun()));
|
||||
|
||||
signing.setPublicKey(
|
||||
checkProperty(context.getModel().getEnvironment(),
|
||||
GPG_PUBLIC_KEY,
|
||||
"signing.publicKey",
|
||||
signing.getPublicKey(),
|
||||
errors));
|
||||
errors,
|
||||
context.isDryrun()));
|
||||
|
||||
signing.setSecretKey(
|
||||
checkProperty(context.getModel().getEnvironment(),
|
||||
GPG_SECRET_KEY,
|
||||
"signing.secretKey",
|
||||
signing.getSecretKey(),
|
||||
errors));
|
||||
errors,
|
||||
context.isDryrun()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,19 +45,21 @@ public abstract class SlackValidator extends Validator {
|
||||
SLACK_TOKEN,
|
||||
"slack.token",
|
||||
slack.getToken(),
|
||||
ignored));
|
||||
ignored,
|
||||
context.isDryrun()));
|
||||
|
||||
slack.setWebhook(
|
||||
checkProperty(context.getModel().getEnvironment(),
|
||||
SLACK_WEBHOOK,
|
||||
"slack.webhook",
|
||||
slack.getWebhook(),
|
||||
ignored));
|
||||
ignored,
|
||||
context.isDryrun()));
|
||||
|
||||
String token = slack.getResolvedToken();
|
||||
String webhook = slack.getResolvedWebhook();
|
||||
|
||||
if (isBlank(token) && isBlank(webhook)) {
|
||||
if (!context.isDryrun() && isBlank(token) && isBlank(webhook)) {
|
||||
errors.configuration("slack.token or slack.webhook must be provided");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -59,25 +59,24 @@ public abstract class SnapValidator extends Validator {
|
||||
validateCommitAuthor(tool, parentTool);
|
||||
validateOwner(tool.getSnap(), parentTool.getSnap());
|
||||
validateTemplate(context, distribution, tool, parentTool, errors);
|
||||
Snap commonSnap = parentTool;
|
||||
mergeExtraProperties(tool, parentTool);
|
||||
mergeSnapPlugs(tool, parentTool);
|
||||
mergeSnapSlots(tool, parentTool);
|
||||
|
||||
if (isBlank(tool.getBase())) {
|
||||
tool.setBase(commonSnap.getBase());
|
||||
tool.setBase(parentTool.getBase());
|
||||
if (isBlank(tool.getBase())) {
|
||||
errors.configuration("distribution." + distribution.getName() + ".snap.base must not be blank");
|
||||
}
|
||||
}
|
||||
if (isBlank(tool.getGrade())) {
|
||||
tool.setGrade(commonSnap.getGrade());
|
||||
tool.setGrade(parentTool.getGrade());
|
||||
if (isBlank(tool.getGrade())) {
|
||||
errors.configuration("distribution." + distribution.getName() + ".snap.grade must not be blank");
|
||||
}
|
||||
}
|
||||
if (isBlank(tool.getConfinement())) {
|
||||
tool.setConfinement(commonSnap.getConfinement());
|
||||
tool.setConfinement(parentTool.getConfinement());
|
||||
if (isBlank(tool.getConfinement())) {
|
||||
errors.configuration("distribution." + distribution.getName() + ".snap.confinement must not be blank");
|
||||
}
|
||||
@@ -86,7 +85,7 @@ public abstract class SnapValidator extends Validator {
|
||||
tool.setRemoteBuild(parentTool.isRemoteBuild());
|
||||
}
|
||||
if (!tool.isRemoteBuild() && isBlank(tool.getExportedLogin())) {
|
||||
tool.setExportedLogin(commonSnap.getExportedLogin());
|
||||
tool.setExportedLogin(parentTool.getExportedLogin());
|
||||
if (isBlank(tool.getExportedLogin())) {
|
||||
errors.configuration("distribution." + distribution.getName() + ".snap.exportedLogin must not be empty");
|
||||
} else if (!context.getBasedir().resolve(tool.getExportedLogin()).toFile().exists()) {
|
||||
|
||||
@@ -43,7 +43,8 @@ public abstract class TeamsValidator extends Validator {
|
||||
TEAMS_WEBHOOK,
|
||||
"teams.webhook",
|
||||
teams.getWebhook(),
|
||||
errors));
|
||||
errors,
|
||||
context.isDryrun()));
|
||||
|
||||
if (isBlank(teams.getMessageTemplate())) {
|
||||
teams.setMessageTemplate(DEFAULT_TEAMS_TPL);
|
||||
|
||||
@@ -41,28 +41,32 @@ public abstract class TwitterValidator extends Validator {
|
||||
TWITTER_CONSUMER_KEY,
|
||||
"twitter.consumerKey",
|
||||
twitter.getConsumerKey(),
|
||||
errors));
|
||||
errors,
|
||||
context.isDryrun()));
|
||||
|
||||
twitter.setConsumerSecret(
|
||||
checkProperty(context.getModel().getEnvironment(),
|
||||
TWITTER_CONSUMER_SECRET,
|
||||
"twitter.consumerSecret",
|
||||
twitter.getConsumerSecret(),
|
||||
errors));
|
||||
errors,
|
||||
context.isDryrun()));
|
||||
|
||||
twitter.setAccessToken(
|
||||
checkProperty(context.getModel().getEnvironment(),
|
||||
TWITTER_ACCESS_TOKEN,
|
||||
"twitter.accessToken",
|
||||
twitter.getAccessToken(),
|
||||
errors));
|
||||
errors,
|
||||
context.isDryrun()));
|
||||
|
||||
twitter.setAccessTokenSecret(
|
||||
checkProperty(context.getModel().getEnvironment(),
|
||||
TWITTER_ACCESS_TOKEN_SECRET,
|
||||
"twitter.accessTokenSecret",
|
||||
twitter.getAccessTokenSecret(),
|
||||
errors));
|
||||
errors,
|
||||
context.isDryrun()));
|
||||
|
||||
if (isBlank(twitter.getStatus())) {
|
||||
twitter.setStatus("\uD83D\uDE80 {{projectNameCapitalized}} {{projectVersion}} has been released! {{releaseNotesUrl}}");
|
||||
|
||||
@@ -37,6 +37,11 @@ class Validator {
|
||||
return Env.check(key, environment.getVariable(key), property, errors);
|
||||
}
|
||||
|
||||
static String checkProperty(Environment environment, String key, String property, String value, Errors errors, boolean dryrun) {
|
||||
if (isNotBlank(value)) return value;
|
||||
return Env.check(key, environment.getVariable(key), property, dryrun ? new Errors() : errors);
|
||||
}
|
||||
|
||||
static String checkProperty(Environment environment, String key, String property, String value, String defaultValue) {
|
||||
if (isNotBlank(value)) return value;
|
||||
Errors errors = new Errors();
|
||||
|
||||
@@ -47,7 +47,8 @@ public abstract class ZulipValidator extends Validator {
|
||||
ZULIP_API_KEY,
|
||||
"zulip.apiKey",
|
||||
zulip.getApiKey(),
|
||||
errors));
|
||||
errors,
|
||||
context.isDryrun()));
|
||||
|
||||
if (isBlank(zulip.getApiHost())) {
|
||||
errors.configuration("zulip.apiHost must not be blank.");
|
||||
|
||||
@@ -76,7 +76,7 @@ public class MailAnnouncer implements Announcer {
|
||||
.port(mail.getPort())
|
||||
.auth(mail.isAuth())
|
||||
.username(mail.getUsername())
|
||||
.password(mail.getResolvedPassword())
|
||||
.password(context.isDryrun() ? "**UNDEFINED**" :mail.getResolvedPassword())
|
||||
.from(mail.getFrom())
|
||||
.to(mail.getTo())
|
||||
.cc(mail.getCc())
|
||||
|
||||
@@ -93,6 +93,9 @@ public class MessageMailCommand implements MailCommand {
|
||||
|
||||
@Override
|
||||
public void execute() throws MailException {
|
||||
logger.info("Sending e-mail announcement");
|
||||
if (dryrun) return;
|
||||
|
||||
Properties props = new Properties();
|
||||
props.putAll(properties);
|
||||
|
||||
@@ -146,16 +149,13 @@ public class MessageMailCommand implements MailCommand {
|
||||
message.setHeader("X-Mailer", "JReleaser " + JReleaserVersion.getPlainVersion());
|
||||
message.setSentDate(new Date());
|
||||
|
||||
logger.info("Sending e-mail announcement");
|
||||
if (!dryrun) {
|
||||
Transport t = session.getTransport(transport.name().toLowerCase());
|
||||
if (auth) {
|
||||
t.connect(host, username, password);
|
||||
} else {
|
||||
t.connect();
|
||||
}
|
||||
t.sendMessage(message, message.getAllRecipients());
|
||||
Transport t = session.getTransport(transport.name().toLowerCase());
|
||||
if (auth) {
|
||||
t.connect(host, username, password);
|
||||
} else {
|
||||
t.connect();
|
||||
}
|
||||
t.sendMessage(message, message.getAllRecipients());
|
||||
} catch (Exception e) {
|
||||
throw new MailException(e);
|
||||
}
|
||||
|
||||
@@ -91,8 +91,8 @@ public class SdkmanAnnouncer implements Announcer {
|
||||
MajorReleaseSdkmanCommand.builder(context.getLogger())
|
||||
.connectTimeout(sdkman.getConnectTimeout())
|
||||
.readTimeout(sdkman.getReadTimeout())
|
||||
.consumerKey(sdkman.getResolvedConsumerKey())
|
||||
.consumerToken(sdkman.getResolvedConsumerToken())
|
||||
.consumerKey(context.isDryrun() ? "**UNDEFINED**" :sdkman.getResolvedConsumerKey())
|
||||
.consumerToken(context.isDryrun() ? "**UNDEFINED**" :sdkman.getResolvedConsumerToken())
|
||||
.candidate(candidate)
|
||||
.version(context.getModel().getProject().getVersion())
|
||||
.platforms(platforms)
|
||||
@@ -105,8 +105,8 @@ public class SdkmanAnnouncer implements Announcer {
|
||||
MinorReleaseSdkmanCommand.builder(context.getLogger())
|
||||
.connectTimeout(sdkman.getConnectTimeout())
|
||||
.readTimeout(sdkman.getReadTimeout())
|
||||
.consumerKey(sdkman.getResolvedConsumerKey())
|
||||
.consumerToken(sdkman.getResolvedConsumerToken())
|
||||
.consumerKey(context.isDryrun() ? "**UNDEFINED**" :sdkman.getResolvedConsumerKey())
|
||||
.consumerToken(context.isDryrun() ? "**UNDEFINED**" :sdkman.getResolvedConsumerToken())
|
||||
.candidate(candidate)
|
||||
.version(context.getModel().getProject().getVersion())
|
||||
.platforms(platforms)
|
||||
|
||||
@@ -77,7 +77,7 @@ public class SlackAnnouncer implements Announcer {
|
||||
SlackSdk sdk = SlackSdk.builder(context.getLogger())
|
||||
.connectTimeout(slack.getConnectTimeout())
|
||||
.readTimeout(slack.getReadTimeout())
|
||||
.token(slack.getResolvedToken())
|
||||
.token(context.isDryrun() ? "**UNDEFINED**" :slack.getResolvedToken())
|
||||
.dryrun(context.isDryrun())
|
||||
.build();
|
||||
|
||||
|
||||
@@ -55,10 +55,10 @@ public class TwitterAnnouncer implements Announcer {
|
||||
UpdateStatusTwitterCommand.builder(context.getLogger())
|
||||
.connectTimeout(twitter.getConnectTimeout())
|
||||
.readTimeout(twitter.getReadTimeout())
|
||||
.consumerKey(twitter.getResolvedConsumerKey())
|
||||
.consumerToken(twitter.getResolvedConsumerSecret())
|
||||
.accessToken(twitter.getResolvedAccessToken())
|
||||
.accessTokenSecret(twitter.getResolvedAccessTokenSecret())
|
||||
.consumerKey(context.isDryrun() ? "**UNDEFINED**" :twitter.getResolvedConsumerKey())
|
||||
.consumerToken(context.isDryrun() ? "**UNDEFINED**" :twitter.getResolvedConsumerSecret())
|
||||
.accessToken(context.isDryrun() ? "**UNDEFINED**" :twitter.getResolvedAccessToken())
|
||||
.accessTokenSecret(context.isDryrun() ? "**UNDEFINED**" :twitter.getResolvedAccessTokenSecret())
|
||||
.status(status)
|
||||
.dryrun(context.isDryrun())
|
||||
.build()
|
||||
|
||||
@@ -73,7 +73,7 @@ public class ZulipAnnouncer implements Announcer {
|
||||
ZulipSdk sdk = ZulipSdk.builder(context.getLogger())
|
||||
.apiHost(zulip.getApiHost())
|
||||
.account(zulip.getAccount())
|
||||
.apiKey(zulip.getResolvedApiKey())
|
||||
.apiKey(context.isDryrun() ? "**UNDEFINED**" : zulip.getResolvedApiKey())
|
||||
.connectTimeout(zulip.getConnectTimeout())
|
||||
.readTimeout(zulip.getReadTimeout())
|
||||
.dryrun(context.isDryrun())
|
||||
|
||||
Reference in New Issue
Block a user