-
-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add draft of proposed new library API. #600
base: main
Are you sure you want to change the base?
Conversation
Note that the file name at the time this PR was opened is arbitrary and will not be merged as such. I added it so we get syntax highlighting and a proper review environment, without worrying about compile errors / imports / what is in which file. |
#[non_exhaustive] | ||
#[derive(Debug, Clone, PartialEq, Eq)] | ||
pub enum OnUnexpectedOutcome { | ||
/// Stop running checks and return an error. | ||
FailStop, | ||
|
||
/// Log an error but continue with other checks. | ||
LogAndContinue, | ||
|
||
/// Continue with other checks as if nothing happened. | ||
/// Do not print anything to stderr. | ||
ContinueSilently, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An alternative to this design would be to model the internals of cargo semver-checks
as a state machine that a binary or other consumer needs to manually advance. That is a bit more work to integrate but gives you greater flexibility. In other words, the library part would only offer building blocks that you can compose together with your own policy.
For example, if said state machine yields an event like:
struct WorkspaceCrateDiscovered {
pub publish: bool,
pub name: String
// ...
}
We would also need APIs like:
pub fn load_crate_from_registry(name: &str) -> Result<...> { }
pub fn check_semver(base: &CrateData, new: &CrateData) -> Result<impl Iterator<Item = SemverViolation>, ...> {}
Upon encountering a WorkspaceCrateDiscovered
event a user could then e.g. decide whether or not to continue checking the crate for semver-violations based on the publish
field.
As
cargo-semver-checks
is getting adopted by more and more projects, we're seeing more and more cases where our current APIs and config flags give users insufficient control over various edge cases that happen in the real world.To address such edge cases, we'll need to expose a richer API in our lib target, which can then be used both as a dependency of other tools (e.g.
release-plz
) and directly via the CLI. I'm adding a draft for such a new API, and I'm looking for feedback!Here are the issues we've seen so far, lightly grouped:
cargo semver-check
on diesel #108RUSTFLAGS
env var sets-Dwarnings
#589--workspace
runs #163Cargo.toml
version is already published on the registry #356publish = false
crates in a workspace #424This PR contains the code for discussion #599.
If you have general feedback about the idea, please post it in the discussion: #599
If you have feedback related to specific lines of code, please post it attached to those lines in this PR.