Skip to content

Commit 95f1e87

Browse files
committed
feat(release): Add publish field for per-crate release control
- Add 'publish' field to SplitConfig (default: true) - Filter release plan based on publish=true crates - Update init command to set publish=true by default - Update rail.toml: test-combined marked publish=false - Works in both monorepo and standalone contexts Tested: - Monorepo with config: Only includes crates where publish=true - Standalone repo (no config): Includes all crates - Fixes Issue #1 (crate filtering)
1 parent 56d612b commit 95f1e87

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed

crates/cargo-rail/src/commands/init.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ pub fn run_init(all: bool) -> RailResult<()> {
100100
branch: "main".to_string(),
101101
mode: SplitMode::Single,
102102
workspace_mode: WorkspaceMode::default(), // Standalone by default
103+
publish: true, // Default to publishable
103104
paths: vec![CratePath { path: package_path }],
104105
include: include_patterns,
105106
exclude: vec![],

crates/cargo-rail/src/commands/release/plan.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ use crate::commands::release::graph::CrateGraph;
1414
use crate::commands::release::semver::BumpType;
1515
use crate::commands::release::semver_check;
1616
use crate::commands::release::tags;
17+
use crate::core::config::RailConfig;
1718
use crate::core::error::RailResult;
1819
use crate::ui::progress::MultiProgress;
1920
use cargo_metadata::MetadataCommand;
2021
use rayon::prelude::*;
2122
use serde::{Deserialize, Serialize};
22-
use std::collections::HashMap;
23+
use std::collections::{HashMap, HashSet};
2324
use std::env;
2425

2526
/// A release plan for a single crate
@@ -101,8 +102,31 @@ pub fn generate_release_plan(show_progress: bool) -> RailResult<ReleasePlan> {
101102
let metadata = load_workspace_metadata()?;
102103
let workspace_root = metadata.workspace_root.as_std_path();
103104

105+
// Try to load rail config to check publish settings (optional - may not exist for standalone repos)
106+
let publishable_crates: HashSet<String> = match RailConfig::load(workspace_root) {
107+
Ok(config) => {
108+
// Build set of crate names that have publish=true (or default true)
109+
config
110+
.splits
111+
.iter()
112+
.filter(|split| split.publish)
113+
.map(|split| split.name.clone())
114+
.collect()
115+
}
116+
Err(_) => {
117+
// No config found - treat all crates as publishable (standalone repo mode)
118+
HashSet::new()
119+
}
120+
};
121+
104122
// Build dependency graph for publish ordering (workspace packages only)
105-
let workspace_pkgs: Vec<_> = metadata.workspace_packages().iter().cloned().cloned().collect();
123+
let mut workspace_pkgs: Vec<_> = metadata.workspace_packages().iter().cloned().cloned().collect();
124+
125+
// Filter to publishable crates if config exists
126+
if !publishable_crates.is_empty() {
127+
workspace_pkgs.retain(|pkg| publishable_crates.contains(&pkg.name.to_string()));
128+
}
129+
106130
let graph = CrateGraph::from_workspace(&workspace_pkgs)?;
107131
let publish_order = graph.topological_order()?;
108132

crates/cargo-rail/src/core/config.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ pub struct SplitConfig {
7373
/// For combined mode: how to structure the split repo
7474
#[serde(default)]
7575
pub workspace_mode: WorkspaceMode,
76+
/// Whether this crate should be included in release plans (default: true)
77+
#[serde(default = "default_publish")]
78+
pub publish: bool,
7679
#[serde(default)]
7780
pub paths: Vec<CratePath>,
7881
#[serde(default)]
@@ -81,6 +84,10 @@ pub struct SplitConfig {
8184
pub exclude: Vec<String>,
8285
}
8386

87+
fn default_publish() -> bool {
88+
true
89+
}
90+
8491
#[derive(Debug, Clone, Serialize, Deserialize)]
8592
pub struct CratePath {
8693
#[serde(rename = "crate")]

rail.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ remote = "[email protected]:loadingalias/cargo-rail-test-combined.git"
4949
branch = "main"
5050
mode = "combined"
5151
workspace_mode = "workspace" # "workspace" (mirror monorepo) or "standalone" (independent crates)
52+
publish = false # Don't include in releases (testing only)
5253
include = [
5354
"src/**",
5455
"tests/**",

0 commit comments

Comments
 (0)