From a69a2944d2ef0d5cc27cd55d1d1e2bc29b7db3ba Mon Sep 17 00:00:00 2001 From: Alex Kladov Date: Tue, 11 Jul 2023 11:47:10 +0100 Subject: [PATCH] polish ci --- examples/ci.rs | 51 +++++++++++++------------------------------------- 1 file changed, 13 insertions(+), 38 deletions(-) diff --git a/examples/ci.rs b/examples/ci.rs index 799b288..8166447 100644 --- a/examples/ci.rs +++ b/examples/ci.rs @@ -1,7 +1,7 @@ //! This CI script for `xshell`. //! //! It also serves as a real-world example, yay bootstrap! -use std::{env, process, thread, time::Duration, time::Instant}; +use std::{env, process, time::Instant}; use xshell::{cmd, Result, Shell}; @@ -22,8 +22,12 @@ fn try_main() -> Result<()> { } fn test(sh: &Shell) -> Result<()> { - // Can't delete oneself on Windows. - if !cfg!(windows) { + // A good setup for CI is to compile & run in two steps, to get separate feedback for compile + // time and run time. However, because we are using the crate itself to run CI, if we are + // running this, we've already compiled a bunch of stuff. Originally we tried to `rm -rf + // .target`, but we also observed weird SIGKILL: 9 errors on mac. Perhaps its our self-removal? + // Let's scope it only to linux (windows won't work, bc one can not remove oneself there). + if cfg!(linux) { sh.remove_path("./target")?; } @@ -41,21 +45,9 @@ fn test(sh: &Shell) -> Result<()> { fn publish(sh: &Shell) -> Result<()> { let _s = Section::new("PUBLISH"); - let manifest = sh.read_file("./Cargo.toml")?; - let version = manifest - .lines() - .find_map(|line| { - let words = line.split_ascii_whitespace().collect::>(); - match words.as_slice() { - [n, "=", v, ..] if n.trim() == "version" => { - assert!(v.starts_with('"') && v.ends_with('"')); - return Some(&v[1..v.len() - 1]); - } - _ => None, - } - }) - .unwrap(); + let pkgid = cmd!(sh, "cargo pkgid").read()?; + let (_path, version) = pkgid.rsplit_once('#').unwrap(); let tag = format!("v{}", version); let tags = cmd!(sh, "git tag --list").read()?; @@ -64,28 +56,11 @@ fn publish(sh: &Shell) -> Result<()> { let current_branch = cmd!(sh, "git branch --show-current").read()?; if current_branch == "master" && !tag_exists { - cmd!(sh, "git tag v{version}").run()?; - + // Could also just use `CARGO_REGISTRY_TOKEN` environmental variable. let token = sh.var("CRATES_IO_TOKEN").unwrap_or("DUMMY_TOKEN".to_string()); - { - let _p = sh.push_dir("xshell-macros"); - cmd!(sh, "cargo publish --token {token}").run()?; - for _ in 0..100 { - thread::sleep(Duration::from_secs(3)); - let err_msg = - cmd!(sh, "cargo install xshell-macros --version {version} --bin non-existing") - .ignore_status() - .read_stderr()?; - - let not_found = err_msg.contains("could not find "); - let tried_installing = err_msg.contains("Installing"); - assert!(not_found ^ tried_installing); - if tried_installing { - break; - } - } - } - cmd!(sh, "cargo publish --token {token}").run()?; + cmd!(sh, "git tag v{version}").run()?; + cmd!(sh, "cargo publish --token {token} --package xshell-macros").run()?; + cmd!(sh, "cargo publish --token {token} --package xshell").run()?; cmd!(sh, "git push --tags").run()?; } Ok(())