cargo-promote 0.1.2

Publish crates to minibox registry and promote to crates.io
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
use anyhow::{Context, Result};
use clap::{Parser, Subcommand};
use std::path::PathBuf;

use cargo_promote::Api;

#[derive(Parser)]
#[command(
    name = "cargo-promote",
    about = "Publish crates through configurable promotion pipelines"
)]
struct Cli {
    #[command(subcommand)]
    cmd: Cmd,
}

#[derive(Subcommand)]
enum Cmd {
    /// Publish a crate to the first stage of a pipeline
    Publish {
        #[arg(short, long)]
        path: Option<PathBuf>,
        #[arg(short = 'p', long)]
        package: Option<String>,
        #[arg(long)]
        allow_dirty: bool,
        #[arg(long)]
        pipeline: Option<String>,
        #[arg(long)]
        registry: Option<String>,
        /// Publish even if the version already exists in the registry
        #[arg(long)]
        force: bool,
    },

    /// Promote a crate from one pipeline stage to the next
    Promote {
        #[arg(short = 'p', long)]
        package: Option<String>,
        #[arg(short, long)]
        path: Option<PathBuf>,
        #[arg(short = 'y', long)]
        yes: bool,
        #[arg(long)]
        dry_run: bool,
        #[arg(long)]
        pipeline: Option<String>,
        #[arg(long)]
        from: Option<String>,
    },

    /// Run all stages of a pipeline
    Ship {
        #[arg(short = 'p', long)]
        package: Option<String>,
        #[arg(short, long)]
        path: Option<PathBuf>,
        #[arg(long)]
        allow_dirty: bool,
        #[arg(short = 'y', long)]
        yes: bool,
        #[arg(long)]
        pipeline: Option<String>,
        /// Publish even if versions already exist in registries
        #[arg(long)]
        force: bool,
    },

    /// List crates in a registry
    List {
        #[arg(long)]
        registry: Option<String>,
    },

    /// Show local crate versions
    Status {
        #[arg(short, long)]
        path: Option<PathBuf>,
    },

    /// Publish all crates under a directory in dependency order
    PublishAll {
        /// Root directory to scan (defaults to ~/dev)
        #[arg(short, long)]
        path: Option<PathBuf>,

        /// Allow dirty working directories
        #[arg(long)]
        allow_dirty: bool,

        /// Dry run -- show publish order without publishing
        #[arg(long)]
        dry_run: bool,

        /// Registry to publish to (defaults to pipeline first stage)
        #[arg(long)]
        registry: Option<String>,

        /// Repos to skip (comma-separated)
        #[arg(
            long,
            default_value = "maestro,maestro-feat-minibox-provider,maestro-slides,seaography,langchainx,prusti-dev,hyperdocker-main,sandbox"
        )]
        skip: String,

        /// Publish even if versions already exist in registries
        #[arg(long)]
        force: bool,
    },

    /// Bump version and create promote.lock
    Bump {
        #[arg(short, long)]
        path: Option<PathBuf>,
        #[arg(short = 'p', long)]
        package: Option<String>,
    },

    /// Branch from one stage to the next
    Branch {
        #[arg(short, long)]
        path: Option<PathBuf>,
        #[arg(long)]
        from: String,
        #[arg(long)]
        to: Option<String>,
    },

    /// Defer promotion to the next stage (provisional, pending confirmation)
    Defer {
        #[arg(long)]
        package: Option<String>,
        #[arg(long)]
        path: Option<PathBuf>,
        #[arg(long)]
        from: String,
        #[arg(long)]
        pipeline: Option<String>,
        /// Defer a branch pipeline merge instead of a registry publish
        #[arg(long)]
        branch: bool,
        /// Notification command to fire (non-blocking)
        #[arg(long, num_args = 1..)]
        command: Vec<String>,
    },

    /// Confirm a pending deferral
    Confirm {
        /// Deferral ticket ID
        ticket: String,
        #[arg(short, long)]
        path: Option<PathBuf>,
        #[arg(long, default_value = "")]
        reason: String,
    },

    /// Reject a pending deferral
    Reject {
        /// Deferral ticket ID
        ticket: String,
        #[arg(short, long)]
        path: Option<PathBuf>,
        #[arg(long, default_value = "")]
        reason: String,
    },

    /// List deferrals
    Deferrals {
        #[arg(short, long)]
        path: Option<PathBuf>,
        /// Show only pending deferrals
        #[arg(long)]
        pending: bool,
    },
}

fn main() -> Result<()> {
    let cli = Cli::parse();
    let cwd = std::env::current_dir().context("cannot determine current directory")?;

    let interactive_confirmer = |prompt: &str| -> bool {
        eprintln!("=> {prompt} [y/N]");
        let mut input = String::new();
        std::io::stdin().read_line(&mut input).ok();
        input.trim().eq_ignore_ascii_case("y")
    };

    match cli.cmd {
        Cmd::Publish {
            path,
            package,
            allow_dirty,
            pipeline,
            registry,
            force,
        } => {
            let dir = path.as_deref().unwrap_or(&cwd);
            let api = Api::with_confirmer(dir, interactive_confirmer)?;
            api.publish(
                path.as_deref(),
                package.as_deref(),
                allow_dirty,
                force,
                pipeline.as_deref(),
                registry.as_deref(),
            )
        }

        Cmd::Promote {
            package,
            path,
            yes,
            dry_run,
            pipeline,
            from,
        } => {
            let dir = path.as_deref().unwrap_or(&cwd);
            let api = Api::with_confirmer(dir, interactive_confirmer)?;
            api.promote(
                path.as_deref(),
                package.as_deref(),
                yes,
                dry_run,
                pipeline.as_deref(),
                from.as_deref(),
            )
        }

        Cmd::Ship {
            package,
            path,
            allow_dirty,
            yes,
            pipeline,
            force,
        } => {
            let dir = path.as_deref().unwrap_or(&cwd);
            let api = Api::with_confirmer(dir, interactive_confirmer)?;
            api.ship(
                path.as_deref(),
                package.as_deref(),
                allow_dirty,
                yes,
                force,
                pipeline.as_deref(),
            )
        }

        Cmd::List { registry } => {
            let api = Api::with_confirmer(&cwd, interactive_confirmer)?;
            let crates = api.list(registry.as_deref())?;
            if crates.is_empty() {
                println!("  (no crates published)");
            } else {
                for c in &crates {
                    println!("  {} v{}", c.name, c.max_version);
                }
                println!("\n  {} crate(s) total", crates.len());
            }
            Ok(())
        }

        Cmd::PublishAll {
            path,
            allow_dirty,
            dry_run,
            registry,
            skip,
            force,
        } => {
            let api = Api::with_confirmer(&cwd, interactive_confirmer)?;
            let root = path.unwrap_or_else(|| {
                PathBuf::from(std::env::var("HOME").unwrap_or_default()).join("dev")
            });
            let skip_list: Vec<&str> = skip.split(',').map(|s| s.trim()).collect();

            let result = api.publish_all(
                &root,
                allow_dirty,
                dry_run,
                force,
                registry.as_deref(),
                &skip_list,
            )?;

            eprintln!(
                "=== PUBLISH ORDER ({} crates) ===",
                result.publish_order.len()
            );
            for (i, name) in result.publish_order.iter().enumerate() {
                eprintln!("  {:3}. {}", i + 1, name);
            }

            if dry_run {
                eprintln!("\n(dry run -- nothing published)");
            } else {
                eprintln!("\n=== SUMMARY ===");
                eprintln!("  Published: {}", result.ok);
                eprintln!("  Failed: {}", result.failed.len());
                eprintln!("  Blocked (path-only): {}", result.blocked.len());
                if !result.failed.is_empty() {
                    eprintln!("  Failed crates: {}", result.failed.join(", "));
                }
            }

            if !result.blocked.is_empty() {
                eprintln!(
                    "=== BLOCKED (path-only deps) ===\n  {}",
                    result.blocked.join(", ")
                );
            }

            Ok(())
        }

        Cmd::Status { path } => {
            let desc = Api::status(path.as_deref())?;
            match desc {
                cargo_promote::domain::manifest::ManifestDescription::Workspace(members) => {
                    eprintln!("Workspace with {} members:", members.len());
                    for m in &members {
                        println!("  {} v{}", m.name, m.version);
                    }
                }
                cargo_promote::domain::manifest::ManifestDescription::Single(info) => {
                    println!("  {} v{}", info.name, info.version);
                }
            }
            Ok(())
        }

        Cmd::Bump { path, package } => {
            let dir = path.as_deref().unwrap_or(&cwd);
            let api = Api::with_confirmer(dir, interactive_confirmer)?;
            api.bump(path.as_deref(), package.as_deref(), &cwd)
        }

        Cmd::Branch { path, from, to: _ } => {
            let dir = path.as_deref().unwrap_or(&cwd);
            let api = Api::with_confirmer(dir, interactive_confirmer)?;
            api.branch(path.as_deref(), &from, &cwd)
        }

        Cmd::Defer {
            package,
            path,
            from,
            pipeline,
            branch,
            command,
        } => {
            let dir = path.as_deref().unwrap_or(&cwd);
            let api = Api::with_notifier(dir, interactive_confirmer, command)?;
            let repo_root = path.as_deref().unwrap_or(&cwd);
            let deferral = if branch {
                api.defer_branch(path.as_deref(), package.as_deref(), &from, repo_root)?
            } else {
                api.defer_to(
                    path.as_deref(),
                    package.as_deref(),
                    &from,
                    pipeline.as_deref(),
                    repo_root,
                )?
            };
            eprintln!(
                "=> deferred {} v{} from '{}' to '{}' [ticket: {}]",
                deferral.crate_name,
                deferral.version,
                deferral.from_stage,
                deferral.to_stage,
                deferral.ticket,
            );
            Ok(())
        }

        Cmd::Confirm {
            ticket,
            path,
            reason,
        } => {
            let repo_root = path.as_deref().unwrap_or(&cwd);
            let api = Api::with_confirmer(repo_root, interactive_confirmer)?;
            let d = api.confirm_deferral(repo_root, &ticket, &reason)?;
            eprintln!(
                "=> confirmed {} v{} -> '{}'",
                d.crate_name, d.version, d.to_stage,
            );
            Ok(())
        }

        Cmd::Reject {
            ticket,
            path,
            reason,
        } => {
            let repo_root = path.as_deref().unwrap_or(&cwd);
            let d = Api::reject_deferral(repo_root, &ticket, &reason)?;
            eprintln!(
                "=> rejected {} v{} (was heading to '{}')",
                d.crate_name, d.version, d.to_stage,
            );
            Ok(())
        }

        Cmd::Deferrals { path, pending } => {
            let repo_root = path.as_deref().unwrap_or(&cwd);
            let deferrals = Api::deferrals(repo_root, pending)?;
            if deferrals.is_empty() {
                println!("  (no deferrals)");
            } else {
                for d in &deferrals {
                    println!(
                        "  [{}] {} v{} {} -> {} ({})",
                        d.ticket,
                        d.crate_name,
                        d.version,
                        d.from_stage,
                        d.to_stage,
                        match d.status {
                            cargo_promote::domain::deferral::DeferralStatus::Pending => "pending",
                            cargo_promote::domain::deferral::DeferralStatus::Confirmed =>
                                "confirmed",
                            cargo_promote::domain::deferral::DeferralStatus::Rejected => "rejected",
                        },
                    );
                }
            }
            Ok(())
        }
    }
}