Skip to content

Commit

Permalink
Merge pull request #340 from epage/default
Browse files Browse the repository at this point in the history
fix(config)!: Disable dev-version by default
  • Loading branch information
epage committed Oct 8, 2021
2 parents 8838b5d + 5a0aeaf commit a6b1efa
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 98 deletions.
12 changes: 6 additions & 6 deletions docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ Configuration is read from the following (in precedence order)
| `sign-tag` | `--sign-tag` | bool | Use GPG to sign git tag generated by cargo-release. |
| `push-remote` | `--push-remote` | string | Default git remote to push |
| `registry` | `--registry` | string | Cargo registry name to publish to (default uses Rust's default, which goes to `crates.io`) |
| `disable-release` | `--exclude` | bool | Skip the entire release process (usually for internal crates in a workspace) |
| `disable-push` | `--skip-push` | bool | Don't do git push |
| `release` | `--exclude` | bool | Skip the entire release process (usually for internal crates in a workspace) |
| `push` | `--no-push` | bool | Don't do git push |
| `push-options` | \- | list of strings | Flags to send to the server when doing a `git push` |
| `disable-tag` | `--skip-tag` | bool | Don't do git tag |
| `disable-publish` | `--skip-publish` | bool | Don't do cargo publish right now, see [manifest `publish` field](https://doc.rust-lang.org/cargo/reference/manifest.html#the-publish--field-optional) to permanently disable publish. |
| `no-verify` | `--no-verify` | bool | Don't verify the contents by building them |
| `tag` | `--no-tag` | bool | Don't do git tag |
| `publish` | `--no-publish` | bool | Don't do cargo publish right now, see [manifest `publish` field](https://doc.rust-lang.org/cargo/reference/manifest.html#the-publish--field-optional) to permanently disable publish. |
| `verify` | `--no-verify` | bool | Don't verify the contents by building them |
| `shared-version` | \- | bool | Ensure all crates with `shared_version` are the same version |
| `consolidate-commits` | \- | bool | When releasing a workspace, use a single commit for the pre-release version bump and a single commit for the post-release version bump. |
| `consolidate-pushes` | \- | bool | When releasing a workspace, use do a single push across all crates in a workspace. |
Expand All @@ -67,7 +67,7 @@ Configuration is read from the following (in precedence order)
| `tag-prefix` | `--tag-prefix` | string | Prefix of git tag, note that this will override default prefix based on crate name. |
| `tag-name` | `--tag-name` | string | The name of the git tag. The placeholder `{{prefix}}` (the tag prefix) is supported in addition to the global placeholders mentioned below. |
| `dev-version-ext` | `--dev-version-ext` | string | Pre-release extension to use on the next development version. |
| `no-dev-version` | `--no-dev-version` | bool | Disable version bump after release. |
| `dev-version` | `--no-dev-version` | bool | Disable version bump after release. |
| `pre-release-replacements` | \- | array of tables (see below) | Specify files that cargo-release will search and replace with new version for the release commit |
| `post-release-replacements` | \- | array of tables (see below) | Specify files that cargo-release will search and replace with new version for the post-release commit (the one starting development) |
| `pre-release-hook` | \- | list of arguments | Provide a command to run before `cargo-release` commits version change. If the return code of hook command is greater than 0, the release process will be aborted. |
Expand Down
132 changes: 78 additions & 54 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,35 @@ pub struct ReleaseOpt {
#[structopt(default_value)]
pub level_or_version: crate::version::TargetVersion,

#[structopt(short = "m")]
/// Semver metadata
#[structopt(short = "m")]
pub metadata: Option<String>,

#[structopt(short = "c", long = "config")]
/// Custom config file
#[structopt(short = "c", long = "config")]
pub custom_config: Option<String>,

#[structopt(long)]
/// Ignore implicit configuration files.
#[structopt(long)]
pub isolated: bool,

#[structopt(flatten)]
pub config: ConfigArgs,

/// Token to use when uploading
#[structopt(long)]
pub token: Option<String>,

/// Actually perform a release. Dry-run mode is the default
#[structopt(short = "x", long)]
pub execute: bool,

#[structopt(long)]
/// Skip release confirmation and version preview
#[structopt(long)]
pub no_confirm: bool,

#[structopt(long)]
/// The name of tag for the previous release.
#[structopt(long)]
pub prev_tag_name: Option<String>,

#[structopt(flatten)]
Expand All @@ -68,106 +72,117 @@ impl ReleaseOpt {

#[derive(Debug, StructOpt)]
pub struct ConfigArgs {
#[structopt(long)]
/// Sign both git commit and tag,
pub sign: bool,
#[structopt(long, overrides_with("no-sign"))]
sign: bool,
#[structopt(long, overrides_with("sign"), hidden(true))]
no_sign: bool,

#[structopt(long)]
/// Sign git commit
pub sign_commit: bool,
#[structopt(long, overrides_with("no-sign-commit"))]
sign_commit: bool,
#[structopt(long, overrides_with("sign-commit"), hidden(true))]
no_sign_commit: bool,

#[structopt(long)]
/// Sign git tag
pub sign_tag: bool,
#[structopt(long, overrides_with("no-sign-tag"))]
sign_tag: bool,
#[structopt(long, overrides_with("sign-tag"), hidden(true))]
no_sign_tag: bool,

#[structopt(long)]
/// Git remote to push
pub push_remote: Option<String>,

#[structopt(long)]
/// Cargo registry to upload to
pub registry: Option<String>,
push_remote: Option<String>,

/// Cargo registry to upload to
#[structopt(long)]
registry: Option<String>,

#[structopt(long, overrides_with("no-publish"), hidden(true))]
publish: bool,
/// Do not run cargo publish on release
pub skip_publish: bool,
#[structopt(long, overrides_with("publish"), visible_alias = "skip-publish")]
no_publish: bool,

#[structopt(long)]
#[structopt(long, overrides_with("no-push"), hidden(true))]
push: bool,
/// Do not run git push in the last step
pub skip_push: bool,
#[structopt(long, overrides_with("push"), visible_alias = "skip-push")]
no_push: bool,

#[structopt(long)]
#[structopt(long, overrides_with("no-tag"), hidden(true))]
tag: bool,
/// Do not create git tag
pub skip_tag: bool,
#[structopt(long, overrides_with("tag"), visible_alias = "skip-tag")]
no_tag: bool,

#[structopt(long)]
#[structopt(long, overrides_with("no-verify"), hidden(true))]
verify: bool,
/// Don't verify the contents by building them
pub no_verify: bool,
#[structopt(long, overrides_with("verify"))]
no_verify: bool,

/// Specify how workspace dependencies on this crate should be handed.
#[structopt(
long,
possible_values(&crate::config::DependentVersion::variants()),
case_insensitive(true),
)]
/// Specify how workspace dependencies on this crate should be handed.
pub dependent_version: Option<crate::config::DependentVersion>,
dependent_version: Option<crate::config::DependentVersion>,

#[structopt(long)]
/// Prefix of git tag, note that this will override default prefix based on sub-directory
pub tag_prefix: Option<String>,

#[structopt(long)]
/// The name of the git tag.
pub tag_name: Option<String>,
tag_prefix: Option<String>,

/// The name of the git tag.
#[structopt(long)]
/// Pre-release identifier(s) to append to the next development version after release
pub dev_version_ext: Option<String>,
tag_name: Option<String>,

/// Pre-release identifier(s) to append to the next development version after release
#[structopt(long)]
/// Do not create dev version after release
pub no_dev_version: bool,
dev_version_ext: Option<String>,

#[structopt(long)]
/// Provide a set of features that need to be enabled
pub features: Vec<String>,
/// Create dev version after release
#[structopt(long, overrides_with("no-dev-version"))]
dev_version: bool,
#[structopt(long, overrides_with("dev-version"), hidden(true))]
no_dev_version: bool,

/// Provide a set of features that need to be enabled
#[structopt(long)]
/// Enable all features via `all-features`. Overrides `features`
pub all_features: bool,
features: Vec<String>,

/// Enable all features via `all-features`. Overrides `features`
#[structopt(long)]
/// Token to use when uploading
pub token: Option<String>,
all_features: bool,
}

impl ConfigArgs {
pub fn to_config(&self) -> crate::config::Config {
crate::config::Config {
sign_commit: self
.sign
.then(|| true)
.or_else(|| self.sign_commit.then(|| true)),
sign_tag: self
.sign
.then(|| true)
.or_else(|| self.sign_tag.then(|| true)),
sign_commit: resolve_bool_arg(self.sign_commit, self.no_sign_commit)
.or_else(|| self.sign()),
sign_tag: resolve_bool_arg(self.sign_tag, self.no_sign_tag).or_else(|| self.sign()),
push_remote: self.push_remote.clone(),
registry: self.registry.clone(),
disable_publish: self.skip_publish.then(|| true),
no_verify: self.no_verify.then(|| true),
disable_push: self.skip_push.then(|| true),
publish: resolve_bool_arg(self.publish, self.no_publish),
verify: resolve_bool_arg(self.verify, self.no_verify),
push: resolve_bool_arg(self.push, self.no_push),
dev_version_ext: self.dev_version_ext.clone(),
no_dev_version: self.no_dev_version.then(|| true),
dev_version: resolve_bool_arg(self.dev_version, self.no_dev_version),
tag_prefix: self.tag_prefix.clone(),
tag_name: self.tag_name.clone(),
disable_tag: self.skip_tag.then(|| true),
tag: resolve_bool_arg(self.tag, self.no_tag),
enable_features: (!self.features.is_empty()).then(|| self.features.clone()),
enable_all_features: self.all_features.then(|| true),
dependent_version: self.dependent_version,
..Default::default()
}
}

fn sign(&self) -> Option<bool> {
resolve_bool_arg(self.sign, self.no_sign)
}
}

#[derive(StructOpt, Debug, Clone)]
Expand Down Expand Up @@ -198,3 +213,12 @@ impl Verbosity {
}
}
}

fn resolve_bool_arg(yes: bool, no: bool) -> Option<bool> {
match (yes, no) {
(true, false) => Some(true),
(false, true) => Some(false),
(false, false) => None,
(_, _) => unreachable!("StructOpt should make this impossible"),
}
}
4 changes: 2 additions & 2 deletions src/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub fn package_content(manifest_path: &Path) -> Result<Vec<std::path::PathBuf>,

pub fn publish(
dry_run: bool,
no_verify: bool,
verify: bool,
manifest_path: &Path,
features: &Features,
registry: Option<&str>,
Expand Down Expand Up @@ -82,7 +82,7 @@ pub fn publish(
command.push("--allow-dirty");
}

if no_verify {
if !verify {
command.push("--no-verify");
}

Expand Down
Loading

0 comments on commit a6b1efa

Please sign in to comment.