Skip to content
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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

obi1kenobi
Copy link
Owner

@obi1kenobi obi1kenobi commented Dec 7, 2023

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:

This 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.

@obi1kenobi
Copy link
Owner Author

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.

@obi1kenobi obi1kenobi added the C-enhancement Category: raise the bar on expectations label Dec 7, 2023
Comment on lines +178 to +190
#[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,
}
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: raise the bar on expectations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants