Skip to main content

deploy/
deploy.rs

1//! A live step list: declare the plan, run each step, close with a card.
2//!
3//!   cargo run --example deploy
4//!   cargo run --example deploy -- --fail
5
6use std::thread::sleep;
7use std::time::Duration;
8
9use tinsel::prelude::*;
10
11fn main() {
12    let fail = std::env::args().any(|a| a == "--fail");
13
14    // declaring every step up front shows the whole plan from the first frame
15    let live = Live::new("deploy", "my-app → production");
16    let build = live.step("Build");
17    let upload = live.step("Upload");
18    let release = live.step("Release");
19
20    build.start();
21    for file in ["main.rs", "config.rs", "assets"] {
22        build.detail(format!("compiling {file}"));
23        sleep(Duration::from_millis(400));
24    }
25    build.done();
26
27    upload.start();
28    for i in 1..=40 {
29        let f = i as f32 / 40.0;
30        upload.progress(f, format!("{:.1} / 12.0 MB", f * 12.0));
31        sleep(Duration::from_millis(40));
32    }
33    upload.done();
34
35    release.start();
36    sleep(Duration::from_millis(800));
37    if fail {
38        release.fail("the health check timed out after 30s");
39        live.finish_with_card(Card::failure("release failed").kv("logs", "my-app logs --since 5m"));
40        std::process::exit(1);
41    }
42    release.done();
43
44    let took = format!("in {:.1}s", live.elapsed().as_secs_f32());
45    live.finish_with_card(
46        Card::success("deployed")
47            .aside(&took)
48            .kv("url", "https://my-app.example.com"),
49    );
50}