Skip to content

Commit

Permalink
Merge pull request #744 from epage/versionless
Browse files Browse the repository at this point in the history
feat: Don't release packages without a version
  • Loading branch information
epage authored Jan 10, 2024
2 parents d99d528 + 5fedab8 commit 21af8ce
Showing 1 changed file with 22 additions and 6 deletions.
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

0 comments on commit 21af8ce

Please sign in to comment.