From 4c034909fa68850ec9f979ba477a3af2a67af02e Mon Sep 17 00:00:00 2001 From: Eric Rodrigues Pires Date: Thu, 30 Jul 2026 09:12:36 -0300 Subject: [PATCH] Add --timeout and --tracing flags --- Cargo.lock | 583 ++++++++++++++++++++++++++++++++++++++++-- Cargo.toml | 4 + src/builder/local.rs | 14 +- src/builder/mod.rs | 4 +- src/builder/remote.rs | 27 +- src/job.rs | 49 ++-- src/main.rs | 53 +++- src/subscriber.rs | 144 +++++++++++ src/workflow.rs | 51 ++-- 9 files changed, 831 insertions(+), 98 deletions(-) create mode 100644 src/subscriber.rs diff --git a/Cargo.lock b/Cargo.lock index 34dd97c..f405873 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -26,6 +26,21 @@ dependencies = [ "memchr", ] +[[package]] +name = "allocator-api2" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + [[package]] name = "anstream" version = "1.0.0" @@ -62,7 +77,7 @@ version = "1.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc" dependencies = [ - "windows-sys", + "windows-sys 0.61.2", ] [[package]] @@ -73,7 +88,36 @@ checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d" dependencies = [ "anstyle", "once_cell_polyfill", - "windows-sys", + "windows-sys 0.61.2", +] + +[[package]] +name = "approx" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cab112f0a86d568ea0e627cc1d6be74a1e9cd55214684db5561995f6dad897c6" +dependencies = [ + "num-traits", +] + +[[package]] +name = "ar_archive_writer" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4087686b4b0a3427190bae57a1d9a478dbb2d40c5dc1bd6e2b6d797913bdd348" +dependencies = [ + "object", +] + +[[package]] +name = "ariadne" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8454c8a44ce2cb9cc7e7fae67fc6128465b343b92c6631e94beca3c8d1524ea5" +dependencies = [ + "concolor", + "unicode-width", + "yansi", ] [[package]] @@ -128,7 +172,7 @@ dependencies = [ "polling", "rustix", "slab", - "windows-sys", + "windows-sys 0.61.2", ] [[package]] @@ -186,7 +230,7 @@ dependencies = [ "rustix", "signal-hook-registry", "slab", - "windows-sys", + "windows-sys 0.61.2", ] [[package]] @@ -233,6 +277,18 @@ dependencies = [ "windows-link", ] +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + [[package]] name = "bitflags" version = "2.13.1" @@ -271,6 +327,12 @@ dependencies = [ "serde_core", ] +[[package]] +name = "bumpalo" +version = "3.20.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649" + [[package]] name = "cc" version = "1.3.0" @@ -304,6 +366,34 @@ dependencies = [ "rand_core", ] +[[package]] +name = "chrono" +version = "0.4.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1aa79e62e7697b8e29b513a68abacf485adcd1fe8284a4316c5ae868e6633327" +dependencies = [ + "iana-time-zone", + "js-sys", + "num-traits", + "serde", + "wasm-bindgen", + "windows-link", +] + +[[package]] +name = "chumsky" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acc17a6284abccac6e50db35c1cee87f605474a72939b959a3a67d9371800efd" +dependencies = [ + "hashbrown 0.15.5", + "regex-automata 0.3.9", + "serde", + "stacker", + "unicode-ident", + "unicode-segmentation", +] + [[package]] name = "clap" version = "4.6.1" @@ -386,6 +476,26 @@ version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570" +[[package]] +name = "concolor" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b946244a988c390a94667ae0e3958411fa40cc46ea496a929b263d883f5f9c3" +dependencies = [ + "bitflags 1.3.2", + "concolor-query", + "is-terminal", +] + +[[package]] +name = "concolor-query" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88d11d52c3d7ca2e6d0040212be9e4dbbcd78b6447f535b6b561f449427944cf" +dependencies = [ + "windows-sys 0.45.0", +] + [[package]] name = "concurrent-queue" version = "2.5.0" @@ -395,6 +505,12 @@ dependencies = [ "crossbeam-utils", ] +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + [[package]] name = "cpufeatures" version = "0.3.0" @@ -437,7 +553,21 @@ checksum = "e0b1fab2ae45819af2d0731d60f2afe17227ebb1a1538a236da84c93e9a60162" dependencies = [ "dispatch2", "nix", - "windows-sys", + "windows-sys 0.61.2", +] + +[[package]] +name = "decorum" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fcc6bb0c903f3f815b48365bb9182092866f54a132d8ebe906f0b66952936e3" +dependencies = [ + "approx", + "num-traits", + "rustversion", + "serde", + "serde_derive", + "thiserror", ] [[package]] @@ -446,7 +576,7 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e0e367e4e7da84520dedcac1901e4da967309406d1e51017ae1abfb97adbd38" dependencies = [ - "bitflags", + "bitflags 2.13.1", "block2", "libc", "objc2", @@ -458,6 +588,30 @@ version = "0.15.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" +[[package]] +name = "duper" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c70f9649c4d0e0807705d57bc4a60a72a9edfa48da1cb42be4020597bdc69e7d" +dependencies = [ + "ariadne", + "base64", + "chumsky", + "decorum", + "either", + "indexmap", + "owo-colors", + "ryu", + "serde_core", + "unicode-general-category", +] + +[[package]] +name = "either" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e5e8f6c15a24b9a3ee5efec809ccd006d3b30e8b3bb63c39af737c7f87daa1d" + [[package]] name = "equivalent" version = "1.0.2" @@ -471,7 +625,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" dependencies = [ "libc", - "windows-sys", + "windows-sys 0.61.2", ] [[package]] @@ -657,8 +811,8 @@ dependencies = [ "aho-corasick", "bstr", "log", - "regex-automata", - "regex-syntax", + "regex-automata 0.4.16", + "regex-syntax 0.8.11", ] [[package]] @@ -667,6 +821,8 @@ version = "0.15.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" dependencies = [ + "allocator-api2", + "equivalent", "foldhash", ] @@ -688,6 +844,36 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc0fef456e4baa96da950455cd02c081ca953b141298e41db3fc7e36b1da849c" +[[package]] +name = "humantime" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15cdd26707701c53297e2fa6afb323d55fbc1d0810c3aec078ae3ef0424c3c15" + +[[package]] +name = "iana-time-zone" +version = "0.1.65" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e31bc9ad994ba00e440a8aa5c9ef0ec67d5cb5e5cb0cc7f8b744a35b389cc470" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "log", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + [[package]] name = "ignore" version = "0.4.30" @@ -698,7 +884,7 @@ dependencies = [ "globset", "log", "memchr", - "regex-automata", + "regex-automata 0.4.16", "same-file", "walkdir", "winapi-util", @@ -739,6 +925,17 @@ dependencies = [ "hashbrown 0.17.1", ] +[[package]] +name = "is-terminal" +version = "0.4.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3640c1c38b8e4e43584d8df18be5fc6b0aa314ce6ebf51b53313d4306cca8e46" +dependencies = [ + "hermit-abi", + "libc", + "windows-sys 0.61.2", +] + [[package]] name = "is_terminal_polyfill" version = "1.70.2" @@ -751,6 +948,17 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" +[[package]] +name = "js-sys" +version = "0.3.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53b44bfcdb3f8d5837a46dae1ca9660a837176eee74a28b229bc626816589102" +dependencies = [ + "cfg-if", + "futures-util", + "wasm-bindgen", +] + [[package]] name = "lazy_static" version = "1.5.0" @@ -775,6 +983,15 @@ version = "0.4.33" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ceec5bc11778974d1bcb055b18002eba7f4b3518b6a0081b3af5f21666da9ad" +[[package]] +name = "matchers" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1525a2a28c7f4fa0fc98bb91ae755d1e2d1505079e05539e35bc876b5d65ae9" +dependencies = [ + "regex-automata 0.4.16", +] + [[package]] name = "memchr" version = "2.8.3" @@ -796,7 +1013,7 @@ version = "0.31.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf20d2fde8ff38632c426f1165ed7436270b44f199fc55284c38276f9db47c3d" dependencies = [ - "bitflags", + "bitflags 2.13.1", "cfg-if", "cfg_aliases", "libc", @@ -813,6 +1030,7 @@ dependencies = [ "ctrlc", "dotenvy", "futures", + "humantime", "ignore", "include_dir", "owo-colors", @@ -823,6 +1041,27 @@ dependencies = [ "serde_json", "smol", "sys-info", + "tracing", + "tracing-subscriber", + "tracing_duper", +] + +[[package]] +name = "nu-ansi-term" +version = "0.50.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", ] [[package]] @@ -913,7 +1152,7 @@ dependencies = [ "hermit-abi", "pin-project-lite", "rustix", - "windows-sys", + "windows-sys 0.61.2", ] [[package]] @@ -925,6 +1164,16 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "psm" +version = "0.1.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645dbe486e346d9b5de3ef16ede18c26e6c70ad97418f4874b8b1889d6e761ea" +dependencies = [ + "ar_archive_writer", + "cc", +] + [[package]] name = "quote" version = "1.0.46" @@ -965,8 +1214,19 @@ checksum = "f020237b6c8eed93db2e2cb53c00c60a8e1bc73da7d073199a1180401450218d" dependencies = [ "aho-corasick", "memchr", - "regex-automata", - "regex-syntax", + "regex-automata 0.4.16", + "regex-syntax 0.8.11", +] + +[[package]] +name = "regex-automata" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59b23e92ee4318893fa3fe3e6fb365258efbfe6ac6ab30f090cdcbb7aa37efa9" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax 0.7.5", ] [[package]] @@ -977,9 +1237,15 @@ checksum = "8fcfdb36bda0c880c5931cdc7a2bcdc8ba4556847b9d912bca70bc94708711ad" dependencies = [ "aho-corasick", "memchr", - "regex-syntax", + "regex-syntax 0.8.11", ] +[[package]] +name = "regex-syntax" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da" + [[package]] name = "regex-syntax" version = "0.8.11" @@ -998,13 +1264,25 @@ version = "1.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6fe4565b9518b83ef4f91bb47ce29620ca828bd32cb7e408f0062e9930ba190" dependencies = [ - "bitflags", + "bitflags 2.13.1", "errno", "libc", "linux-raw-sys", - "windows-sys", + "windows-sys 0.61.2", ] +[[package]] +name = "rustversion" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f" + +[[package]] +name = "ryu" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f" + [[package]] name = "same-file" version = "1.0.6" @@ -1088,6 +1366,12 @@ version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" +[[package]] +name = "smallvec" +version = "1.15.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ed6a63f02c8539c91a8685a86f4099661ba3da017932f6ebbea6de3f0fa7c90" + [[package]] name = "smol" version = "2.0.2" @@ -1105,6 +1389,19 @@ dependencies = [ "futures-lite", ] +[[package]] +name = "stacker" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "640c8cdd92b6b12f5bcb1803ca3bbf5ab96e5e6b6b96b9ab77dabe9e880b3190" +dependencies = [ + "cc", + "cfg-if", + "libc", + "psm", + "windows-sys 0.61.2", +] + [[package]] name = "strsim" version = "0.11.1" @@ -1143,6 +1440,26 @@ dependencies = [ "libc", ] +[[package]] +name = "thiserror" +version = "2.0.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09a43598840e33d5b0331f38c5e30d13bb11c11210a4b58f0d9b18a5a5eefcd9" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43cbfe0cf76104d42a574802844187e84a305e531ed54455f11fbde0f10541cd" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.2", +] + [[package]] name = "thread_local" version = "1.1.10" @@ -1159,9 +1476,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" dependencies = [ "pin-project-lite", + "tracing-attributes", "tracing-core", ] +[[package]] +name = "tracing-attributes" +version = "0.1.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.118", +] + [[package]] name = "tracing-core" version = "0.1.36" @@ -1182,23 +1511,71 @@ dependencies = [ "tracing-subscriber", ] +[[package]] +name = "tracing-log" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" +dependencies = [ + "log", + "once_cell", + "tracing-core", +] + [[package]] name = "tracing-subscriber" version = "0.3.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb7f578e5945fb242538965c2d0b04418d38ec25c79d160cd279bf0731c8d319" dependencies = [ + "matchers", + "nu-ansi-term", + "once_cell", + "regex-automata 0.4.16", "sharded-slab", + "smallvec", "thread_local", + "tracing", + "tracing-core", + "tracing-log", +] + +[[package]] +name = "tracing_duper" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee9e02b8a88915e10151fc50ae4fc1fc34f7b4bb68e235ae47ba5f4d8c282bb2" +dependencies = [ + "chrono", + "duper", "tracing-core", + "tracing-subscriber", ] +[[package]] +name = "unicode-general-category" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b993bddc193ae5bd0d623b49ec06ac3e9312875fdae725a975c51db1cc1677f" + [[package]] name = "unicode-ident" version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" +[[package]] +name = "unicode-segmentation" +version = "1.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6f5d3c3b1bf09027a88a6bc961fc00497d651009560b5463668dc81b0fa87a8" + +[[package]] +name = "unicode-width" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4ac048d71ede7ee76d585517add45da530660ef4390e49b098733c6e897f254" + [[package]] name = "utf8parse" version = "0.2.2" @@ -1221,13 +1598,93 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "wasm-bindgen" +version = "0.2.126" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b067c0c11094aef6b7a801c1e34a26affafdf3d051dba08456b868789aaf9a4" +dependencies = [ + "cfg-if", + "once_cell", + "rustversion", + "wasm-bindgen-macro", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.126" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "167ce5e579f6bcf889c4f7175a8a5a585de84e8ff93976ce393efa5f2837aab1" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.126" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3997c7839262f4ef12cf90b818d6340c18e80f263f1a94bf157d0ec4420380e" +dependencies = [ + "bumpalo", + "proc-macro2", + "quote", + "syn 2.0.118", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.126" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc1b4cb0cc549fcf58d7dfc081778139b3d283a081644e833e84682ad71cea24" +dependencies = [ + "unicode-ident", +] + [[package]] name = "winapi-util" version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" dependencies = [ - "windows-sys", + "windows-sys 0.61.2", +] + +[[package]] +name = "windows-core" +version = "0.62.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-link", + "windows-result", + "windows-strings", +] + +[[package]] +name = "windows-implement" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.118", +] + +[[package]] +name = "windows-interface" +version = "0.59.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.118", ] [[package]] @@ -1236,6 +1693,33 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" +[[package]] +name = "windows-result" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-strings" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-sys" +version = "0.45.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" +dependencies = [ + "windows-targets", +] + [[package]] name = "windows-sys" version = "0.61.2" @@ -1245,6 +1729,69 @@ dependencies = [ "windows-link", ] +[[package]] +name = "windows-targets" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" + +[[package]] +name = "windows_i686_gnu" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" + +[[package]] +name = "windows_i686_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" + +[[package]] +name = "yansi" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfe53a6657fd280eaa890a3bc59152892ffa3e30101319d168b781ed6529b049" + [[package]] name = "zmij" version = "1.0.21" diff --git a/Cargo.toml b/Cargo.toml index cc928d5..621e6c9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,6 +25,7 @@ color-eyre = "0.6.5" ctrlc = { version = "3.5.2", features = ["termination"] } dotenvy = "0.15.7" futures = "0.3.33" +humantime = "2.4.0" ignore = "0.4.30" include_dir = "0.7.4" owo-colors = "4.3.0" @@ -35,3 +36,6 @@ serde = { version = "1.0.228", features = ["derive"] } serde_json = "1.0.150" smol = "2.0.2" sys-info = "0.9.1" +tracing = "0.1.44" +tracing-subscriber = { version = "0.3.23", features = ["env-filter"] } +tracing_duper = "0.1.1" diff --git a/src/builder/local.rs b/src/builder/local.rs index b935921..4048d21 100644 --- a/src/builder/local.rs +++ b/src/builder/local.rs @@ -24,7 +24,6 @@ use std::{ }; use async_trait::async_trait; -use owo_colors::Style; use smol::{ channel, io::AsyncReadExt, @@ -39,7 +38,7 @@ use crate::{ NowBuilder, remote::RemoteBuilder, }, environment::NowEnvironment, - utils::{get_random_string, pipe_outputs_to_stderr, trim_string}, + utils::{get_random_string, pipe_outputs_to_stderr}, workflow::NowJob, }; @@ -50,7 +49,6 @@ pub(crate) struct LocalBuilder { pub(crate) strategy: CheckoutStrategy, pub(crate) use_cache: bool, pub(crate) hostname: String, - pub(crate) short_name: String, pub(crate) system: String, pub(crate) system_features: HashSet, pub(crate) remote_builders: Vec, @@ -93,7 +91,6 @@ impl LocalBuilder { let (cancellation, cancellation_rx) = channel::bounded(1); let hostname = sys_info::hostname()?; - let short_name = trim_string(hostname.clone(), 40); Ok(Self { cancellation, @@ -102,7 +99,6 @@ impl LocalBuilder { use_cache, strategy, hostname, - short_name, system: config.system.value, system_features: config.system_features.value.into_iter().collect(), remote_builders, @@ -159,12 +155,8 @@ impl NowBuilder for LocalBuilder { self.hostname.clone() } - fn get_short_name(&self) -> String { - self.short_name.clone() - } - - fn get_style(&self) -> owo_colors::Style { - Style::new().blue() + fn is_remote(&self) -> bool { + false } fn checkout(&self) -> color_eyre::Result<(Option>, PathBuf)> { diff --git a/src/builder/mod.rs b/src/builder/mod.rs index c92bd01..a453d95 100644 --- a/src/builder/mod.rs +++ b/src/builder/mod.rs @@ -75,9 +75,7 @@ pub(crate) trait NowBuilder { fn get_name(&self) -> String; - fn get_short_name(&self) -> String; - - fn get_style(&self) -> owo_colors::Style; + fn is_remote(&self) -> bool; fn checkout(&self) -> color_eyre::Result<(Option>, PathBuf)>; diff --git a/src/builder/remote.rs b/src/builder/remote.rs index a81f78b..ecfdd28 100644 --- a/src/builder/remote.rs +++ b/src/builder/remote.rs @@ -17,7 +17,6 @@ use std::{ collections::{HashMap, HashSet}, ffi::{OsStr, OsString}, - hash::{DefaultHasher, Hash, Hasher}, os::unix::ffi::OsStrExt, path::{Path, PathBuf}, pin::Pin, @@ -25,8 +24,6 @@ use std::{ use async_trait::async_trait; use futures::FutureExt; -use owo_colors::Style; -use rand::{SeedableRng, seq::IndexedRandom}; use smol::{ channel, io::{AsyncReadExt, AsyncWriteExt}, @@ -40,7 +37,7 @@ use crate::{ CACHE_PUBLIC_KEY, CACHE_SUBSTITUTER, CheckoutTask, CommandCheckoutTask, NixConfig, NowBuilder, }, - utils::{escape_os_string, get_random_string, pipe_outputs_to_stderr, trim_string}, + utils::{escape_os_string, get_random_string, pipe_outputs_to_stderr}, workflow::NowJob, }; @@ -85,7 +82,6 @@ pub(crate) struct RemoteBuilder { pub(crate) control_path: PathBuf, pub(crate) use_cache: bool, pub(crate) strategy: CheckoutStrategy, - pub(crate) short_name: String, pub(crate) ssh_uri: String, pub(crate) ssh_identity: Option, pub(crate) systems: HashSet, @@ -180,7 +176,6 @@ impl RemoteBuilder { let (cancellation, cancellation_rx) = channel::bounded(1); let control_path = project_source.join(format!("ssh-{}", get_random_string(10))); - let short_name = trim_string(ssh_uri.clone(), 40); vec.push(RemoteBuilder { cancellation, @@ -188,7 +183,6 @@ impl RemoteBuilder { use_cache, strategy, control_path, - short_name, ssh_uri, ssh_identity, systems, @@ -227,23 +221,8 @@ impl NowBuilder for RemoteBuilder { self.ssh_uri.clone() } - fn get_short_name(&self) -> String { - self.short_name.clone() - } - - fn get_style(&self) -> owo_colors::Style { - let mut hasher = DefaultHasher::new(); - self.ssh_uri.hash(&mut hasher); - *[ - Style::new().yellow(), - Style::new().magenta(), - Style::new().green(), - Style::new().cyan(), - Style::new().purple(), - Style::new().red(), - ] - .choose(&mut rand::rngs::SmallRng::seed_from_u64(hasher.finish())) - .expect("not empty") + fn is_remote(&self) -> bool { + true } fn checkout(&self) -> color_eyre::Result<(Option>, PathBuf)> { diff --git a/src/job.rs b/src/job.rs index 78178b7..c725f4f 100644 --- a/src/job.rs +++ b/src/job.rs @@ -17,9 +17,9 @@ use std::{ffi::OsStr, os::unix::ffi::OsStrExt, path::PathBuf, pin::Pin}; use futures::{AsyncReadExt, TryStreamExt, stream::FuturesUnordered}; -use owo_colors::OwoColorize; use petgraph::matrix_graph::NodeIndex; use smol::{channel::TryRecvError, io::AsyncBufReadExt, io::BufReader, stream::StreamExt}; +use tracing::{info, warn}; use crate::{ builder::{NowBuilder, local::LocalBuilder}, @@ -33,15 +33,14 @@ type JobFut<'a> = Pin + 'a>>; impl NowEnvironment { async fn run_job(&self, builder: &dyn NowBuilder, job: NowJob) -> color_eyre::Result<()> { let guard = builder.acquire().await; - let style = builder.get_style(); - let runner = builder.get_short_name(); + let runner = builder.get_name(); + let is_remote = builder.is_remote(); if matches!(guard.try_recv(), Ok(()) | Err(TryRecvError::Closed)) { return Err(color_eyre::eyre::eyre!("Runner aborted")); } - eprintln!( - "{} Running job '{}'...", - format!("{}>", runner).style(style), - &job.name + info!( + builder = runner, + is_remote, "Running job '{}'...", &job.name ); let (mut checkout_child, cwdir) = builder.checkout()?; @@ -100,11 +99,7 @@ impl NowEnvironment { let mut lines = BufReader::new(stderr).lines(); while let Some(line) = lines.next().await { if let Ok(line) = line { - eprintln!( - "{} {}", - format!("{} step[{}]>", runner, step.name).style(style), - line, - ); + info!(builder = runner, is_remote, step = step.name, "{}", line); } else { break; } @@ -117,11 +112,13 @@ impl NowEnvironment { stdout.read_to_end(&mut buf).await?; let upload_path = PathBuf::from(OsStr::from_bytes(buf.trim_ascii())); builder.fetch_derivation(&upload_path, &guard).await?; - eprintln!( - "{} Uploaded '{}' ({})", - format!("{} step[{}]>", runner, step.name).style(style), + info!( + builder = runner, + is_remote, + step = step.name, + "Uploaded '{}', ({})", upload_key, - upload_path.to_string_lossy(), + upload_path.to_string_lossy() ); self.uploads .lock() @@ -160,10 +157,13 @@ impl NowEnvironment { let mut lines = BufReader::new(stderr).lines(); while let Some(line) = lines.next().await { if let Ok(line) = line { - eprintln!( - "{} {}", - format!("{} step[{}]>", runner, step_name).style(style), - line, + info!( + builder = runner, + is_remote, + step = step_name, + teardown = true, + "{}", + line ); } else { break; @@ -172,9 +172,12 @@ impl NowEnvironment { let exit_status = child.status().await?; if !exit_status.success() { - eprintln!( - "{} Teardown failed ({}); continuing", - format!("{} step[{}]>", runner, step_name).style(style), + warn!( + builder = runner, + is_remote, + step = step_name, + teardown = true, + "Teardown failed ({}); continuing", exit_status ); result = result.and(Err(color_eyre::eyre::eyre!( diff --git a/src/main.rs b/src/main.rs index 5afe57d..591720b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,11 +14,17 @@ // You should have received a copy of the GNU Affero General Public License along // with this program. If not, see . -use std::path::PathBuf; +use std::{path::PathBuf, str::FromStr, time::Duration}; use clap::{CommandFactory, Parser, ValueEnum}; +use color_eyre::eyre::Context; +use tracing::level_filters::LevelFilter; +use tracing_duper::DuperLayer; +use tracing_subscriber::{EnvFilter, Layer, layer::SubscriberExt, util::SubscriberInitExt}; -use crate::{environment::NowEnvironment, workflow::NowWorkflowParams}; +use crate::{ + environment::NowEnvironment, subscriber::NowSubscriberLayer, workflow::NowWorkflowParams, +}; mod builder; mod deserialize; @@ -26,6 +32,7 @@ mod environment; mod job; mod project; mod secret; +mod subscriber; mod utils; mod workflow; @@ -98,6 +105,10 @@ enum Command { #[arg(long)] abort: bool, + /// Timeout for the entire workflow, eg. `1h`. + #[arg(long, value_parser = validate_duration, value_name = "DURATION")] + timeout: Option, + /// Evaluate but don't run the workflow. #[arg(long)] eval: bool, @@ -133,6 +144,12 @@ enum Command { /// This avoids having to download and run the compiler toolchain on local and remote builds. #[arg(long)] use_cache: bool, + + /// Whether to emit traces in Duper instead of colored logs. + /// + /// For more information on Duper: + #[arg(long)] + tracing: bool, }, /// Generate shell completions. @@ -142,6 +159,12 @@ enum Command { }, } +fn validate_duration(value: &str) -> color_eyre::Result { + Ok(humantime::Duration::from_str(value) + .with_context(|| "invalid duration")? + .into()) +} + fn main() -> color_eyre::Result<()> { match Command::parse() { Command::Init { workflow } => { @@ -161,23 +184,43 @@ fn main() -> color_eyre::Result<()> { std::fs::create_dir_all(parent)?; } std::fs::write(&path, include_bytes!("init.nix"))?; - eprintln!( + println!( "'{}' has been initialized with a basic workflow", path.to_string_lossy(), ) } + Command::Run { mut workflow, jobs, all_jobs, env_file, abort, + timeout, eval, checkout_strategy, builders, nixpkgs_expr, use_cache, + tracing, } => { + let env_filter = EnvFilter::builder() + .with_default_directive(LevelFilter::INFO.into()) + .from_env_lossy(); + if tracing { + tracing_subscriber::registry() + .with( + DuperLayer::default() + .with_span_timings(true) + .with_filter(env_filter), + ) + .init(); + } else { + tracing_subscriber::registry() + .with(NowSubscriberLayer::default().with_filter(env_filter)) + .init(); + } + if all_jobs && jobs.is_some() { return Err(color_eyre::eyre::eyre!( "Conflicting --all-jobs and --job options" @@ -198,6 +241,7 @@ fn main() -> color_eyre::Result<()> { "Conflicting --abort and --eval options" )); } + if workflow.is_dir() { let now = workflow.join("now.nix"); if now.exists() && !now.is_dir() { @@ -214,6 +258,7 @@ fn main() -> color_eyre::Result<()> { workflow.to_string_lossy() )); } + let mut environment = NowEnvironment::get(&workflow, env_file.as_ref(), &nixpkgs_expr, use_cache)?; environment.run_workflow(NowWorkflowParams { @@ -221,6 +266,7 @@ fn main() -> color_eyre::Result<()> { nixpkgs_expr, use_cache, abort, + timeout, eval, jobs, all_jobs, @@ -228,6 +274,7 @@ fn main() -> color_eyre::Result<()> { builders, })?; } + Command::Completions { shell } => { clap_complete::generate( shell, diff --git a/src/subscriber.rs b/src/subscriber.rs new file mode 100644 index 0000000..559cbfe --- /dev/null +++ b/src/subscriber.rs @@ -0,0 +1,144 @@ +use std::{ + hash::{Hash, Hasher}, + io::Write, + marker::PhantomData, +}; + +use owo_colors::OwoColorize; +use rand::{SeedableRng, seq::IndexedRandom}; +use tracing::{Subscriber, field::Visit}; +use tracing_subscriber::{Layer, field::VisitOutput, registry::LookupSpan}; + +use crate::utils::trim_string; + +pub(crate) struct NowSubscriberLayer std::io::Stderr> { + make_writer: W, + builder_name_limit: usize, + _subscriber: PhantomData, +} + +impl Default for NowSubscriberLayer { + fn default() -> Self { + Self { + make_writer: std::io::stderr, + builder_name_limit: 40, + _subscriber: Default::default(), + } + } +} + +impl Layer for NowSubscriberLayer +where + S: Subscriber + for<'span> LookupSpan<'span>, + W: for<'writer> tracing_subscriber::fmt::writer::MakeWriter<'writer> + 'static, +{ + fn on_event( + &self, + event: &tracing::Event<'_>, + _ctx: tracing_subscriber::layer::Context<'_, S>, + ) { + let mut fields_visitor = NowSubscriberVisitor::new(self.builder_name_limit); + event.record(&mut fields_visitor); + if let Some(log_line) = fields_visitor.finish() { + let _ = writeln!( + self.make_writer.make_writer_for(event.metadata()), + "{}", + log_line + ); + } + } +} + +struct NowSubscriberVisitor { + builder_name_limit: usize, + builder: Option, + is_remote: Option, + step: Option, + message: Option, +} + +impl NowSubscriberVisitor { + fn new(builder_name_limit: usize) -> Self { + NowSubscriberVisitor { + builder_name_limit, + builder: None, + is_remote: None, + step: None, + message: None, + } + } +} + +impl Visit for NowSubscriberVisitor { + fn record_debug(&mut self, field: &tracing::field::Field, value: &dyn core::fmt::Debug) { + match field.name() { + "message" => self.message = Some(format!("{:?}", value)), + _ => (), + } + } + + fn record_bool(&mut self, field: &tracing::field::Field, value: bool) { + match field.name() { + "is_remote" => self.is_remote = Some(value), + _ => self.record_debug(field, &value), + } + } + + fn record_str(&mut self, field: &tracing::field::Field, value: &str) { + match field.name() { + "builder" => self.builder = Some(value.to_string()), + "step" => self.step = Some(value.to_string()), + _ => self.record_debug(field, &value), + } + } +} + +impl tracing_subscriber::field::VisitOutput> for NowSubscriberVisitor { + fn finish(self) -> Option { + let Some(message) = self.message else { + return None; + }; + let Some(builder) = self.builder else { + return Some(message); + }; + let is_remote = self.is_remote.is_some_and(|is_remote| is_remote); + let style = get_style_for_runner(is_remote, &builder); + if let Some(step) = self.step { + Some(format!( + "{} {}", + format!( + "{} step[{}]>", + trim_string(builder, self.builder_name_limit), + step + ) + .style(style), + message + )) + } else { + Some(format!( + "{} {}", + format!("{}>", trim_string(builder, self.builder_name_limit)).style(style), + message + )) + } + } +} + +fn get_style_for_runner(is_remote: bool, builder: &str) -> owo_colors::Style { + if is_remote { + let mut hasher = std::hash::DefaultHasher::new(); + builder.hash(&mut hasher); + *[ + owo_colors::Style::new().yellow(), + owo_colors::Style::new().magenta(), + owo_colors::Style::new().green(), + owo_colors::Style::new().cyan(), + owo_colors::Style::new().purple(), + owo_colors::Style::new().red(), + ] + .choose(&mut rand::rngs::SmallRng::seed_from_u64(hasher.finish())) + .expect("not empty") + } else { + owo_colors::Style::new().blue() + } +} diff --git a/src/workflow.rs b/src/workflow.rs index 7848cd7..d0d6adb 100644 --- a/src/workflow.rs +++ b/src/workflow.rs @@ -20,16 +20,17 @@ use std::{ path::{Path, PathBuf}, pin::Pin, process::Command, + time::Duration, }; use futures::stream::FuturesUnordered; -use owo_colors::OwoColorize; use petgraph::{ acyclic::Acyclic, algo::Cycle, matrix_graph::NodeIndex, stable_graph::StableDiGraph, visit::EdgeRef, }; use serde::Deserialize; use smol::{channel, stream::StreamExt}; +use tracing::info; use crate::{ CheckoutStrategy, @@ -104,6 +105,7 @@ pub(crate) struct NowWorkflowParams { pub(crate) nixpkgs_expr: String, pub(crate) use_cache: bool, pub(crate) abort: bool, + pub(crate) timeout: Option, pub(crate) eval: bool, pub(crate) jobs: Option>, pub(crate) all_jobs: bool, @@ -119,6 +121,7 @@ impl NowEnvironment { nixpkgs_expr, use_cache, abort, + timeout, eval, jobs, all_jobs, @@ -127,11 +130,12 @@ impl NowEnvironment { }: NowWorkflowParams, ) -> color_eyre::Result<()> { let builder = LocalBuilder::new(self, use_cache, strategy, builders)?; - let style = builder.get_style(); + let runner = builder.get_name(); - eprintln!( - "{} Evaluating workflow '{}'...", - format!("{}>", builder.get_name()).style(style), + info!( + builder = runner, + is_remote = false, + "Evaluating workflow '{}'...", workflow_path.to_string_lossy() ); let workflow = self.evaluate_workflow(&workflow_path, nixpkgs_expr, use_cache)?; @@ -141,15 +145,17 @@ impl NowEnvironment { } if let Some(name) = workflow.name.as_ref() { - eprintln!( - "{} Building tree for '{}'...", - format!("{}>", builder.get_name()).style(style), + info!( + builder = runner, + is_remote = false, + "Building tree for '{}'...", name ); } else { - eprintln!( - "{} Building tree for workflow...", - format!("{}>", builder.get_name()).style(style) + info!( + builder = runner, + is_remote = false, + "Building tree for workflow..." ); } let NowWorkflowGraph { @@ -164,10 +170,23 @@ impl NowEnvironment { let _ = sender.try_send(()); })?; let builder_ref = &builder; - let ctrl_c_task = executor.spawn(async move { - if ctrl_c.recv().await.is_ok() { - builder_ref.cancel_builders(); - } + let abort_task = executor.spawn(async move { + smol::future::race( + async { + if ctrl_c.recv().await.is_ok() { + builder_ref.cancel_builders(); + } + }, + async { + if let Some(timeout) = timeout { + smol::Timer::after(timeout).await; + builder_ref.cancel_builders(); + } else { + smol::future::pending::<()>().await; + } + }, + ) + .await; smol::future::pending::>().await }); @@ -242,7 +261,7 @@ impl NowEnvironment { } }); - smol::future::block_on(executor.run(smol::future::or(workflow_task, ctrl_c_task))) + smol::future::block_on(executor.run(smol::future::or(workflow_task, abort_task))) } fn evaluate_workflow( -- knotmirror 0.0.1