v2 #2

Merged
dzu merged 24 commits from dev into main 2026-02-21 11:06:58 +01:00
3 changed files with 88 additions and 6 deletions
Showing only changes of commit a67277b563 - Show all commits

ench: use tracing for logging
All checks were successful
Build and update the action / build-and-upload (push) Successful in 2m50s

Artem Diachenko 2026-02-20 14:41:48 +00:00

70
Cargo.lock generated
View file

@ -32,13 +32,15 @@ dependencies = [
[[package]] [[package]]
name = "anode-cache-common" name = "anode-cache-common"
version = "0.1.0" version = "0.1.0"
source = "git+https://git.dzuchun.ing/actions/cache-common-src.git#03a207d32a9b72647a5a1015b3cf63adb6d24b36" source = "git+https://git.dzuchun.ing/actions/cache-common-src.git#479d6fe4149b1cc4c81486fdf0eb6f6a56fc9282"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"isahc", "isahc",
"secrecy", "secrecy",
"serde_json", "serde_json",
"thiserror", "thiserror",
"tracing",
"tracing-subscriber",
] ]
[[package]] [[package]]
@ -115,6 +117,7 @@ dependencies = [
"flate2", "flate2",
"secrecy", "secrecy",
"tar", "tar",
"tracing",
] ]
[[package]] [[package]]
@ -485,6 +488,12 @@ version = "1.0.17"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2" checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2"
[[package]]
name = "lazy_static"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.182" version = "0.2.182"
@ -564,6 +573,15 @@ dependencies = [
"simd-adler32", "simd-adler32",
] ]
[[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]] [[package]]
name = "once_cell" name = "once_cell"
version = "1.21.3" version = "1.21.3"
@ -774,6 +792,15 @@ dependencies = [
"zmij", "zmij",
] ]
[[package]]
name = "sharded-slab"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6"
dependencies = [
"lazy_static",
]
[[package]] [[package]]
name = "shlex" name = "shlex"
version = "1.3.0" version = "1.3.0"
@ -878,6 +905,15 @@ dependencies = [
"syn", "syn",
] ]
[[package]]
name = "thread_local"
version = "1.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f60246a4944f24f6e018aa17cdeffb7818b76356965d03b07d6a9886e8962185"
dependencies = [
"cfg-if",
]
[[package]] [[package]]
name = "tinystr" name = "tinystr"
version = "0.8.2" version = "0.8.2"
@ -918,6 +954,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a" checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a"
dependencies = [ dependencies = [
"once_cell", "once_cell",
"valuable",
] ]
[[package]] [[package]]
@ -930,6 +967,31 @@ dependencies = [
"tracing", "tracing",
] ]
[[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.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2f30143827ddab0d256fd843b7a66d164e9f271cfa0dde49142c5ca0ca291f1e"
dependencies = [
"nu-ansi-term",
"sharded-slab",
"smallvec",
"thread_local",
"tracing-core",
"tracing-log",
]
[[package]] [[package]]
name = "unicode-ident" name = "unicode-ident"
version = "1.0.24" version = "1.0.24"
@ -960,6 +1022,12 @@ version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be"
[[package]]
name = "valuable"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65"
[[package]] [[package]]
name = "vcpkg" name = "vcpkg"
version = "0.2.15" version = "0.2.15"

View file

@ -10,6 +10,7 @@ anyhow = "1.0.101"
flate2 = "1.1.9" flate2 = "1.1.9"
secrecy = "0.10.3" secrecy = "0.10.3"
tar = "0.4.44" tar = "0.4.44"
tracing = { version = "0.1.44", features = ["attributes"] }
[build-dependencies] [build-dependencies]
anode-build = { git = "https://git.dzuchun.ing/dzu/anode.git", version = "0.1.0" } anode-build = { git = "https://git.dzuchun.ing/dzu/anode.git", version = "0.1.0" }

View file

@ -5,6 +5,7 @@ use anyhow::{Context, Result};
use flate2::{Compression, GzBuilder}; use flate2::{Compression, GzBuilder};
use secrecy::ExposeSecret; use secrecy::ExposeSecret;
use tar::{Builder, HeaderMode}; use tar::{Builder, HeaderMode};
use tracing::{debug, info_span, warn};
#[derive(Debug, anode::Input)] #[derive(Debug, anode::Input)]
#[name = "Cache save"] #[name = "Cache save"]
@ -21,11 +22,17 @@ struct Input {
/// Must be in UTF-8 /// Must be in UTF-8
#[parser(key_parser)] #[parser(key_parser)]
key: CacheKey, key: CacheKey,
/// If the debug log should be printed
///
/// If omitted, defined by compiler settings (print debug if `debug_assertions` is enabled)
debug: Option<bool>,
} }
fn main() -> Result<()> { fn main() -> Result<()> {
// parse inputs // parse inputs
let Input { path, key } = Input::get(); let Input { path, key, debug } = Input::get();
anode_cache_common::setup_logger(debug.unwrap_or(cfg!(debug_assertions)));
let actions_token = actions_token().context("reading actions token")?; let actions_token = actions_token().context("reading actions token")?;
let cache_url = std::env::var("ACTIONS_CACHE_URL").context("reading action cache url")?; let cache_url = std::env::var("ACTIONS_CACHE_URL").context("reading action cache url")?;
@ -33,6 +40,7 @@ fn main() -> Result<()> {
// set up http client // set up http client
let client = Client::new(actions_token.expose_secret(), cache_url) let client = Client::new(actions_token.expose_secret(), cache_url)
.context("intializing cache client")?; .context("intializing cache client")?;
debug!("Cache client initialized");
// collect and compress the cached files // collect and compress the cached files
let mut output = Vec::<u8>::with_capacity(1024 * 1024); // assume large cache size let mut output = Vec::<u8>::with_capacity(1024 * 1024); // assume large cache size
@ -41,24 +49,29 @@ fn main() -> Result<()> {
let mut archive = Builder::new(out_comp); let mut archive = Builder::new(out_comp);
archive.mode(HeaderMode::Complete); archive.mode(HeaderMode::Complete);
archive.follow_symlinks(false); archive.follow_symlinks(false);
debug!(paths = ?path);
for path in path { for path in path {
let _span = info_span!("cache-entry");
let _span = _span.enter();
if !path.exists() { if !path.exists() {
println!( warn!("Path does not exist, and will not be cached");
"warn: path {} does not exist, and will not be cached",
path.display()
);
continue; continue;
} }
if path.is_dir() { if path.is_dir() {
debug!("Caching directory");
// we actually want to write out all the directory contents // we actually want to write out all the directory contents
archive.append_dir_all(&path, &path).unwrap(); archive.append_dir_all(&path, &path).unwrap();
} else if path.is_file() { } else if path.is_file() {
debug!("Caching a file");
// rest of the file types are handled by the existing inner code // rest of the file types are handled by the existing inner code
archive.append_path(path).unwrap(); archive.append_path(path).unwrap();
} else {
warn!("Path is neither directory, nor a file and will not be cached");
} }
} }
archive.finish().unwrap(); archive.finish().unwrap();
} }
debug!("Cache archive cleated");
client client
.save_cache(&key, output) .save_cache(&key, output)