Skip to content

Commit

Permalink
feat(cli): add verify-conditions subcommand
Browse files Browse the repository at this point in the history
The verify-conditions subcommand implements the verifyConditions step
for sementic release for a Cargo-based rust workspace. It checks the
following conditions:

1. CARGO_REGISTRY_TOKEN is set and non-empty.
2. It can construct the dependencies graph for the workspace.
3. The dependencies graph in the workspace does not contain and links
that would inhibit the publication of the packages in the workspace.
  • Loading branch information
sbosnick committed Jul 18, 2020
1 parent efdcc53 commit 1c55939
Show file tree
Hide file tree
Showing 5 changed files with 314 additions and 6 deletions.
99 changes: 99 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ structopt = "0.3.15"
anyhow = "1.0.31"
thiserror = "1.0.20"
guppy = "0.5.0"
itertools = "0.9.0"
toml_edit = "0.2.0"
40 changes: 40 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
use std::io;
use std::path::PathBuf;

use guppy::graph::PackageLink;
use guppy::errors::Error as GuppyError;
use thiserror::Error;

use super::DependencyType;

/// The error type for operations `sementic-release-rust` operations.
#[derive(Debug, Error)]
pub enum Error {
Expand All @@ -22,6 +25,28 @@ pub enum Error {
/// Error while writing to the output.
#[error("Unable to write to the output")]
OutputError(#[source] io::Error),

/// Error while verifying the conditions for a release.
#[error("Conditions for a release are not satisfied: {reason}")]
VerifyError{
/// The reason the conditions are not satisfied.
reason: String,
},

/// Error while verifying that dependencies allow publication.
///
/// This is a specific part of verifying the conditions for a release.
#[error("{typ} of {from} on {to} prevents publication of {from}")]
BadDependancy{
/// The name of the package whose dependency prevents publication.
from: String,

/// The depended on package that prevents publication.
to: String,

/// The type of dependency that prevents publication.
typ: DependencyType,
}
}

/// A specialized `Result` type for `semantic-release-rust` operations.
Expand All @@ -47,4 +72,19 @@ impl Error {
pub(crate) fn output_error(inner: io::Error) -> Error {
Error::OutputError(inner)
}

pub(crate) fn verify_error(reason: impl Into<String>) -> Error {
Error::VerifyError {
reason: reason.into(),
}
}

pub(crate) fn bad_dependency(link: &PackageLink, typ: DependencyType) -> Error {
Error::BadDependancy {
from: link.from().name().to_string(),
to: link.to().name().to_string(),
typ,
}
}
}

Loading

0 comments on commit 1c55939

Please sign in to comment.