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

feat: Don't release packages without a version #744

Merged
merged 2 commits into from
Jan 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,22 @@ pub fn resolve_config(workspace_root: &Path, manifest_path: &Path) -> CargoResul
pub fn resolve_overrides(workspace_root: &Path, manifest_path: &Path) -> CargoResult<Config> {
let mut release_config = Config::default();

let mut workspace_cache = None;
fn load_workspace<'m, 'c: 'm>(
workspace_root: &Path,
workspace_cache: &'c mut Option<CargoManifest>,
) -> CargoResult<&'m CargoManifest> {
if workspace_cache.is_none() {
let workspace_path = workspace_root.join("Cargo.toml");
let toml = std::fs::read_to_string(&workspace_path)?;
let manifest: CargoManifest = toml::from_str(&toml)
.with_context(|| format!("Failed to parse `{}`", workspace_path.display()))?;

*workspace_cache = Some(manifest);
}
Ok(workspace_cache.as_ref().unwrap())
}

// the publish flag in cargo file
let manifest = std::fs::read_to_string(manifest_path)?;
let manifest: CargoManifest = toml::from_str(&manifest)
Expand All @@ -831,12 +847,7 @@ pub fn resolve_overrides(workspace_root: &Path, manifest_path: &Path) -> CargoRe
Some(MaybeWorkspace::Defined(publish)) => publish.publishable(),
Some(MaybeWorkspace::Workspace(workspace)) => {
if workspace.workspace {
let workspace_path = workspace_root.join("Cargo.toml");
let workspace = std::fs::read_to_string(&workspace_path)?;
let workspace: CargoManifest =
toml::from_str(&workspace).with_context(|| {
format!("Failed to parse `{}`", workspace_path.display())
})?;
let workspace = load_workspace(workspace_root, &mut workspace_cache)?;
workspace
.workspace
.as_ref()
Expand All @@ -853,6 +864,11 @@ pub fn resolve_overrides(workspace_root: &Path, manifest_path: &Path) -> CargoRe
if !publish {
release_config.publish = Some(false);
}

if package.version.is_none() {
// No point releasing if it can't be published and doesn't have a version to update
release_config.release = Some(false);
}
if package
.version
.as_ref()
Expand Down
Loading