From 217320276ed52fecfc31d6724993dea53957034e Mon Sep 17 00:00:00 2001 From: dzu Date: Sun, 15 Feb 2026 17:11:40 +0000 Subject: [PATCH 01/23] ci: add build-action --- .forgejo/workflows/build-action.yml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 .forgejo/workflows/build-action.yml diff --git a/.forgejo/workflows/build-action.yml b/.forgejo/workflows/build-action.yml new file mode 100644 index 0000000..7314217 --- /dev/null +++ b/.forgejo/workflows/build-action.yml @@ -0,0 +1,26 @@ +name: Build and update the action + +on: + workflow_dispatch: + push: + branches: + - main + - dev + +jobs: + build-and-upload: + runs-on: docker + steps: + - name: Build and update the action + uses: https://git.dzuchun.ing/actions/anode-build@main + with: + src-repository: https://git.dzuchun.ing/actions/cache-save-src.git + src-ref: ${{ forgejo.ref_name }} + src-token: ${{ secrets.GIT_TOKEN }} + dst-repository: https://git.dzuchun.ing/actions/cache-save.git + dst-ref: ${{ forgejo.ref_name }} + dst-token: ${{ secrets.GIT_TOKEN }} + dst-email: forgejo-actions@dzuchun.ing + opt-release: ${{ forgejo.ref_name == 'main' }} + opt-build-std: ${{ forgejo.ref_name == 'main' }} + opt-upx: ${{ forgejo.ref_name == 'main' }} -- 2.54.0 From 95e0187f5ed396eea348cebf57a1e4e7b1997409 Mon Sep 17 00:00:00 2001 From: dzu Date: Sun, 15 Feb 2026 17:39:45 +0000 Subject: [PATCH 02/23] ench: filter out empty paths --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 1c90e5f..c2ab9f8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,7 +3,7 @@ use std::{ffi::OsString, path::PathBuf, str::FromStr, string::FromUtf8Error}; fn paths_parser(input: OsString) -> Result, FromUtf8Error> { let input = String::from_utf8(input.into_encoded_bytes())?; let mut paths = Vec::new(); - for path in input.split('\n') { + for path in input.split('\n').filter(|s| !s.is_empty()) { paths.push(match PathBuf::from_str(path) { Ok(ok) => ok, }); -- 2.54.0 From c498dd20a07a4bad3e9f1d2f8886b2db6bc46b71 Mon Sep 17 00:00:00 2001 From: dzu Date: Sun, 15 Feb 2026 18:12:03 +0000 Subject: [PATCH 03/23] add runtime action token parsing --- Cargo.lock | 16 ++++++++++++++++ Cargo.toml | 1 + src/main.rs | 20 +++++++++++++++++++- 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 578ddb8..40c6fef 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -51,6 +51,7 @@ version = "0.1.0" dependencies = [ "anode", "anode-build", + "secrecy", "thiserror", ] @@ -106,6 +107,15 @@ version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f" +[[package]] +name = "secrecy" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e891af845473308773346dc847b2c23ee78fe442e0472ac50e22a18a93d3ae5a" +dependencies = [ + "zeroize", +] + [[package]] name = "serde" version = "1.0.228" @@ -191,3 +201,9 @@ dependencies = [ "serde", "unsafe-libyaml", ] + +[[package]] +name = "zeroize" +version = "1.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b97154e67e32c85465826e8bcc1c59429aaaf107c1e4a9e53c8d8ccd5eff88d0" diff --git a/Cargo.toml b/Cargo.toml index 0734c94..1d8a250 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,6 +5,7 @@ edition = "2024" [dependencies] anode = { git = "https://git.dzuchun.ing/dzu/anode.git", version = "0.1.0" } +secrecy = "0.10.3" thiserror = "2.0.18" [build-dependencies] diff --git a/src/main.rs b/src/main.rs index c2ab9f8..ca60bd5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,7 @@ use std::{ffi::OsString, path::PathBuf, str::FromStr, string::FromUtf8Error}; +use secrecy::SecretString; + fn paths_parser(input: OsString) -> Result, FromUtf8Error> { let input = String::from_utf8(input.into_encoded_bytes())?; let mut paths = Vec::new(); @@ -56,7 +58,23 @@ struct Input { key: CacheKey, } +#[derive(Debug, thiserror::Error)] +enum ActionsTokenError { + #[error("Could not find action runtime token")] + NotPresent, + #[error("Action runtime token was not UTF-8 -encoded")] + NotUtf8, +} + +fn actions_token() -> Result { + let os_str = std::env::var_os("ACTIONS_RUNTIME_TOKEN").ok_or(ActionsTokenError::NotPresent)?; + let str = + String::from_utf8(os_str.into_encoded_bytes()).map_err(|_| ActionsTokenError::NotUtf8)?; + Ok(SecretString::new(str.into_boxed_str())) +} + fn main() { let input = Input::get(); - println!("Inputs: {input:#?}"); + let actions_token = actions_token().unwrap(); + println!("Inputs: {input:#?}, token: {actions_token:?}"); } -- 2.54.0 From f83df3c874c1cba4e8347e2887ec4be93e8f63c6 Mon Sep 17 00:00:00 2001 From: dzu Date: Tue, 17 Feb 2026 12:41:15 +0000 Subject: [PATCH 04/23] ench: cache entry reservation --- Cargo.lock | 1100 +++++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 19 +- src/main.rs | 97 ++++- 3 files changed, 1206 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 40c6fef..b4a3212 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,12 @@ # It is not intended for manual editing. version = 4 +[[package]] +name = "adler2" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" + [[package]] name = "anode" version = "0.1.0" @@ -45,28 +51,378 @@ dependencies = [ "syn", ] +[[package]] +name = "anyhow" +version = "1.0.101" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f0e0fee31ef5ed1ba1316088939cea399010ed7731dba877ed44aeb407a75ea" + +[[package]] +name = "async-channel" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81953c529336010edd6d8e358f886d9581267795c61b19475b71314bffa46d35" +dependencies = [ + "concurrent-queue", + "event-listener", + "futures-core", +] + +[[package]] +name = "autocfg" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "bitflags" +version = "2.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "843867be96c8daad0d758b57df9392b6d8d271134fce549de6ce169ff98a92af" + +[[package]] +name = "bytes" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33" + [[package]] name = "cache-save" version = "0.1.0" dependencies = [ "anode", "anode-build", + "anyhow", + "flate2", + "isahc", "secrecy", + "serde_json", + "tar", "thiserror", ] +[[package]] +name = "castaway" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2698f953def977c68f935bb0dfa959375ad4638570e969e2f1e9f433cbf1af6" + +[[package]] +name = "cc" +version = "1.2.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aebf35691d1bfb0ac386a69bac2fde4dd276fb618cf8bf4f5318fe285e821bb2" +dependencies = [ + "find-msvc-tools", + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" + +[[package]] +name = "concurrent-queue" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ca0197aee26d1ae37445ee532fefce43251d24cc7c166799f4d46817f1d3973" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crc32fast" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9481c1c90cbf2ac953f07c8d4a58aa3945c425b7185c9154d67a65e4230da511" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" + +[[package]] +name = "curl" +version = "0.4.49" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79fc3b6dd0b87ba36e565715bf9a2ced221311db47bd18011676f24a6066edbc" +dependencies = [ + "curl-sys", + "libc", + "openssl-probe", + "openssl-sys", + "schannel", + "socket2", + "windows-sys 0.59.0", +] + +[[package]] +name = "curl-sys" +version = "0.4.85+curl-8.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0efa6142b5ecc05f6d3eaa39e6af4888b9d3939273fb592c92b7088a8cf3fdb" +dependencies = [ + "cc", + "libc", + "libnghttp2-sys", + "libz-sys", + "openssl-sys", + "pkg-config", + "vcpkg", + "windows-sys 0.59.0", +] + +[[package]] +name = "displaydoc" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "encoding_rs" +version = "0.8.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75030f3c4f45dafd7586dd6780965a8c7e8e285a5ecb86713e63a79c5b2766f3" +dependencies = [ + "cfg-if", +] + [[package]] name = "equivalent" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" +[[package]] +name = "errno" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" +dependencies = [ + "libc", + "windows-sys 0.61.2", +] + +[[package]] +name = "event-listener" +version = "2.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" + +[[package]] +name = "fastrand" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e51093e27b0797c359783294ca4f0a911c270184cb10f85783b118614a1501be" +dependencies = [ + "instant", +] + +[[package]] +name = "filetime" +version = "0.2.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f98844151eee8917efc50bd9e8318cb963ae8b297431495d3f758616ea5c57db" +dependencies = [ + "cfg-if", + "libc", + "libredox", +] + +[[package]] +name = "find-msvc-tools" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582" + +[[package]] +name = "flate2" +version = "1.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "843fba2746e448b37e26a819579957415c8cef339bf08564fe8b7ddbd959573c" +dependencies = [ + "crc32fast", + "miniz_oxide", +] + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "form_urlencoded" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futures-core" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e3450815272ef58cec6d564423f6e755e25379b217b0bc688e295ba24df6b1d" + +[[package]] +name = "futures-io" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cecba35d7ad927e23624b22ad55235f2239cfa44fd10428eecbeba6d6a717718" + +[[package]] +name = "futures-lite" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49a9d51ce47660b1e808d3c990b4709f2f415d928835a17dfd16991515c46bce" +dependencies = [ + "fastrand", + "futures-core", + "futures-io", + "memchr", + "parking", + "pin-project-lite", + "waker-fn", +] + [[package]] name = "hashbrown" version = "0.16.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100" +[[package]] +name = "http" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "601cbb57e577e2f5ef5be8e7b83f0f63994f25aa94d673e54a92d5c516d101f1" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "icu_collections" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c6b649701667bbe825c3b7e6388cb521c23d88644678e83c0c4d0a621a34b43" +dependencies = [ + "displaydoc", + "potential_utf", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locale_core" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edba7861004dd3714265b4db54a3c390e880ab658fec5f7db895fae2046b5bb6" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_normalizer" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f6c8828b67bf8908d82127b2054ea1b4427ff0230ee9141c54251934ab1b599" +dependencies = [ + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7aedcccd01fc5fe81e6b489c15b247b8b0690feb23304303a9e560f37efc560a" + +[[package]] +name = "icu_properties" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "020bfc02fe870ec3a66d93e677ccca0562506e5872c650f893269e08615d74ec" +dependencies = [ + "icu_collections", + "icu_locale_core", + "icu_properties_data", + "icu_provider", + "zerotrie", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "616c294cf8d725c6afcd8f55abc17c56464ef6211f9ed59cccffe534129c77af" + +[[package]] +name = "icu_provider" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85962cf0ce02e1e0a629cc34e7ca3e373ce20dda4c4d7294bbd0bf1fdb59e614" +dependencies = [ + "displaydoc", + "icu_locale_core", + "writeable", + "yoke", + "zerofrom", + "zerotrie", + "zerovec", +] + +[[package]] +name = "idna" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de" +dependencies = [ + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3acae9609540aa318d1bc588455225fb2085b9ed0c4f6bd0d9d5bcd86f1a0344" +dependencies = [ + "icu_normalizer", + "icu_properties", +] + [[package]] name = "indexmap" version = "2.13.0" @@ -77,12 +433,230 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "instant" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0242819d153cba4b4b05a5a8f2a7e9bbf97b6055b2a002b395c96b5ff3c0222" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "isahc" +version = "1.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "334e04b4d781f436dc315cb1e7515bd96826426345d498149e4bde36b67f8ee9" +dependencies = [ + "async-channel", + "castaway", + "crossbeam-utils", + "curl", + "curl-sys", + "encoding_rs", + "event-listener", + "futures-lite", + "http", + "log", + "mime", + "once_cell", + "polling", + "slab", + "sluice", + "tracing", + "tracing-futures", + "url", + "waker-fn", +] + [[package]] name = "itoa" version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2" +[[package]] +name = "libc" +version = "0.2.182" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6800badb6cb2082ffd7b6a67e6125bb39f18782f793520caee8cb8846be06112" + +[[package]] +name = "libnghttp2-sys" +version = "0.1.12+1.68.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31d4c51112b381b39a072a6010bc5d3e5557996c5d0150abacd1d349b2636299" +dependencies = [ + "cc", + "libc", +] + +[[package]] +name = "libredox" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d0b95e02c851351f877147b7deea7b1afb1df71b63aa5f8270716e0c5720616" +dependencies = [ + "bitflags 2.11.0", + "libc", + "redox_syscall", +] + +[[package]] +name = "libz-sys" +version = "1.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15d118bbf3771060e7311cc7bb0545b01d08a8b4a7de949198dec1fa0ca1c0f7" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "linux-raw-sys" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df1d3c3b53da64cf5760482273a98e575c651a67eec7f77df96b5b642de8f039" + +[[package]] +name = "litemap" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6373607a59f0be73a39b6fe456b8192fcc3585f602af20751600e974dd455e77" + +[[package]] +name = "log" +version = "0.4.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" + +[[package]] +name = "memchr" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "miniz_oxide" +version = "0.8.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fa76a2c86f704bdb222d66965fb3d63269ce38518b83cb0575fca855ebb6316" +dependencies = [ + "adler2", + "simd-adler32", +] + +[[package]] +name = "once_cell" +version = "1.21.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" + +[[package]] +name = "openssl-probe" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d05e27ee213611ffe7d6348b942e8f942b37114c00cc03cec254295a4a17852e" + +[[package]] +name = "openssl-src" +version = "300.5.5+3.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f1787d533e03597a7934fd0a765f0d28e94ecc5fb7789f8053b1e699a56f709" +dependencies = [ + "cc", +] + +[[package]] +name = "openssl-sys" +version = "0.9.111" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82cab2d520aa75e3c58898289429321eb788c3106963d0dc886ec7a5f4adc321" +dependencies = [ + "cc", + "libc", + "openssl-src", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "parking" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f38d5652c16fde515bb1ecef450ab0f6a219d619a7274976324d5e377f7dceba" + +[[package]] +name = "percent-encoding" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" + +[[package]] +name = "pin-project" +version = "1.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677f1add503faace112b9f1373e43e9e054bfdd22ff1a63c1bc485eaec6a6a8a" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e918e4ff8c4549eb882f14b3a4bc8c8bc93de829416eacf579f1207a8fbf861" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" + +[[package]] +name = "pkg-config" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" + +[[package]] +name = "polling" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b2d323e8ca7996b3e23126511a523f7e62924d93ecd5ae73b333815b0eb3dce" +dependencies = [ + "autocfg", + "bitflags 1.3.2", + "cfg-if", + "concurrent-queue", + "libc", + "log", + "pin-project-lite", + "windows-sys 0.48.0", +] + +[[package]] +name = "potential_utf" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b73949432f5e2a09657003c25bca5e19a0e9c84f8058ca374f49e0ebe605af77" +dependencies = [ + "zerovec", +] + [[package]] name = "proc-macro2" version = "1.0.106" @@ -101,12 +675,43 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "redox_syscall" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35985aa610addc02e24fc232012c86fd11f14111180f902b67e2d5331f8ebf2b" +dependencies = [ + "bitflags 2.11.0", +] + +[[package]] +name = "rustix" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "146c9e247ccc180c1f61615433868c99f3de3ae256a30a43b49f67c2d9171f34" +dependencies = [ + "bitflags 2.11.0", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.61.2", +] + [[package]] name = "ryu" version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f" +[[package]] +name = "schannel" +version = "0.1.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "891d81b926048e76efe18581bf793546b4c0eaf8448d72be8de2bbee5fd166e1" +dependencies = [ + "windows-sys 0.61.2", +] + [[package]] name = "secrecy" version = "0.10.3" @@ -146,6 +751,70 @@ dependencies = [ "syn", ] +[[package]] +name = "serde_json" +version = "1.0.149" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86" +dependencies = [ + "itoa", + "memchr", + "serde", + "serde_core", + "zmij", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "simd-adler32" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e320a6c5ad31d271ad523dcf3ad13e2767ad8b1cb8f047f75a8aeaf8da139da2" + +[[package]] +name = "slab" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" + +[[package]] +name = "sluice" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d7400c0eff44aa2fcb5e31a5f24ba9716ed90138769e4977a2ba6014ae63eb5" +dependencies = [ + "async-channel", + "futures-core", + "futures-io", +] + +[[package]] +name = "smallvec" +version = "1.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" + +[[package]] +name = "socket2" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86f4aa3ad99f2088c990dfa82d367e19cb29268ed67c574d10d0a4bfe71f07e0" +dependencies = [ + "libc", + "windows-sys 0.60.2", +] + +[[package]] +name = "stable_deref_trait" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" + [[package]] name = "syn" version = "2.0.115" @@ -157,6 +826,28 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "synstructure" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tar" +version = "0.4.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d863878d212c87a19c1a610eb53bb01fe12951c0501cf5a0d65f724914a667a" +dependencies = [ + "filetime", + "libc", + "xattr", +] + [[package]] name = "thiserror" version = "2.0.18" @@ -177,6 +868,58 @@ dependencies = [ "syn", ] +[[package]] +name = "tinystr" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42d3e9c45c09de15d06dd8acf5f4e0e399e85927b7f00711024eb7ae10fa4869" +dependencies = [ + "displaydoc", + "zerovec", +] + +[[package]] +name = "tracing" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" +dependencies = [ + "log", + "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", +] + +[[package]] +name = "tracing-core" +version = "0.1.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a" +dependencies = [ + "once_cell", +] + +[[package]] +name = "tracing-futures" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97d095ae15e245a057c8e8451bab9b3ee1e1f68e9ba2b4fbc18d0ac5237835f2" +dependencies = [ + "pin-project", + "tracing", +] + [[package]] name = "unicode-ident" version = "1.0.23" @@ -189,6 +932,280 @@ version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861" +[[package]] +name = "url" +version = "2.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff67a8a4397373c3ef660812acab3268222035010ab8680ec4215f38ba3d0eed" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", + "serde", +] + +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "waker-fn" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "317211a0dc0ceedd78fb2ca9a44aed3d7b9b26f81870d485c07122b4350673b7" + +[[package]] +name = "windows-link" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" +dependencies = [ + "windows-targets 0.53.5", +] + +[[package]] +name = "windows-sys" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm 0.52.6", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.53.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4945f9f551b88e0d65f3db0bc25c33b8acea4d9e41163edf90dcd0b19f9069f3" +dependencies = [ + "windows-link", + "windows_aarch64_gnullvm 0.53.1", + "windows_aarch64_msvc 0.53.1", + "windows_i686_gnu 0.53.1", + "windows_i686_gnullvm 0.53.1", + "windows_i686_msvc 0.53.1", + "windows_x86_64_gnu 0.53.1", + "windows_x86_64_gnullvm 0.53.1", + "windows_x86_64_msvc 0.53.1", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnu" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "960e6da069d81e09becb0ca57a65220ddff016ff2d6af6a223cf372a506593a3" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_i686_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650" + +[[package]] +name = "writeable" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9edde0db4769d2dc68579893f2306b26c6ecfbe0ef499b013d731b7b9247e0b9" + +[[package]] +name = "xattr" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32e45ad4206f6d2479085147f02bc2ef834ac85886624a23575ae137c8aa8156" +dependencies = [ + "libc", + "rustix", +] + [[package]] name = "yaml_serde" version = "0.10.3" @@ -202,8 +1219,91 @@ dependencies = [ "unsafe-libyaml", ] +[[package]] +name = "yoke" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72d6e5c6afb84d73944e5cedb052c4680d5657337201555f9f2a16b7406d4954" +dependencies = [ + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b659052874eb698efe5b9e8cf382204678a0086ebf46982b79d6ca3182927e5d" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + +[[package]] +name = "zerofrom" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50cc42e0333e05660c3587f3bf9d0478688e15d870fab3346451ce7f8c9fbea5" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d71e5d6e06ab090c67b5e44993ec16b72dcbaabc526db883a360057678b48502" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + [[package]] name = "zeroize" version = "1.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b97154e67e32c85465826e8bcc1c59429aaaf107c1e4a9e53c8d8ccd5eff88d0" + +[[package]] +name = "zerotrie" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a59c17a5562d507e4b54960e8569ebee33bee890c70aa3fe7b97e85a9fd7851" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", +] + +[[package]] +name = "zerovec" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c28719294829477f525be0186d13efa9a3c602f7ec202ca9e353d310fb9a002" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eadce39539ca5cb3985590102671f2567e659fca9666581ad3411d59207951f3" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zmij" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa" diff --git a/Cargo.toml b/Cargo.toml index 1d8a250..d19fdd3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,16 +5,21 @@ edition = "2024" [dependencies] anode = { git = "https://git.dzuchun.ing/dzu/anode.git", version = "0.1.0" } +anyhow = "1.0.101" +flate2 = "1.1.9" +isahc = { version = "1.7.2", features = ["static-ssl", "static-curl"] } secrecy = "0.10.3" +serde_json = "1.0.149" +tar = "0.4.44" thiserror = "2.0.18" [build-dependencies] anode-build = { git = "https://git.dzuchun.ing/dzu/anode.git", version = "0.1.0" } -[profile.release] -opt-level = "s" -lto = true -codegen-units = 1 -strip = true -panic = "abort" -incremental = false +# [profile.release] +# opt-level = "s" +# lto = true +# codegen-units = 1 +# strip = true +# panic = "abort" +# incremental = false diff --git a/src/main.rs b/src/main.rs index ca60bd5..9e674b8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,15 @@ use std::{ffi::OsString, path::PathBuf, str::FromStr, string::FromUtf8Error}; -use secrecy::SecretString; +use anyhow::{Context, Result, bail}; +use flate2::{Compression, GzBuilder}; +use isahc::{ + HttpClient, HttpClientBuilder, Request, + auth::{Authentication, Credentials}, + config::Configurable, + http::{Method, StatusCode, Uri}, +}; +use secrecy::{ExposeSecret, SecretString}; +use tar::{Archive, Builder, HeaderMode}; fn paths_parser(input: OsString) -> Result, FromUtf8Error> { let input = String::from_utf8(input.into_encoded_bytes())?; @@ -56,6 +65,9 @@ struct Input { /// Must be in UTF-8 #[parser(key_parser)] key: CacheKey, + /// A server url to upload the cache to + #[default_str("${{ forgejo.api_url }}")] + base_url: String, } #[derive(Debug, thiserror::Error)] @@ -73,8 +85,87 @@ fn actions_token() -> Result { Ok(SecretString::new(str.into_boxed_str())) } +struct Client { + http_client: HttpClient, + base_url: String, +} + +#[derive(Debug, Clone, Copy)] +struct CacheId(u64); + +impl Client { + fn reserve(&self, key: &CacheKey, cacheSize: usize) -> Result { + let request = Request::builder() + .uri(format!( + "{}/_apis/artifactcache/reverveCache", + self.base_url + )) + .method(Method::POST) + .body( + serde_json::json! {{ + "key": &key.0, + "version": "0", + "cacheSize": cacheSize, + }} + .to_string(), + ) + .context("building the request")?; + let response = self + .http_client + .send(request) + .context("sending the request")?; + let status = response.status(); + if status != StatusCode::OK { + bail!( + "Failed reserving a cache (status {status}): {:?}", + response.body() + ); + } + + todo!() + } +} + fn main() { - let input = Input::get(); + // parse inputs + let Input { + path, + key, + base_url, + } = Input::get(); let actions_token = actions_token().unwrap(); - println!("Inputs: {input:#?}, token: {actions_token:?}"); + + // set up http client + let http_client = HttpClientBuilder::new() + .authentication(Authentication::basic()) + .credentials(Credentials::new("Bearer", actions_token.expose_secret())) + .build() + .unwrap(); + let client = Client { + http_client, + base_url, + }; + + // collect and compress the cached files + let mut output = Vec::::with_capacity(1024 * 1024); // assume large cache size + let out_comp = GzBuilder::new().write(&mut output, Compression::best()); + { + let mut archive = Builder::new(out_comp); + archive.mode(HeaderMode::Complete); + archive.follow_symlinks(false); + for path in path { + if path.is_dir() { + // we actually want to write out all the directory contents + archive.append_dir_all("", path).unwrap(); + } else if path.is_file() { + // rest of the file types are handled by the existing inner code + archive.append_path(path).unwrap(); + } + } + archive.finish().unwrap(); + } + + let cache_id = client.reserve(&key, output.len()).unwrap(); + + println!("Reserved cache with id {cache_id:?}"); } -- 2.54.0 From 6a04d3e9e390c4b384b45433faa2958d15cf0b2e Mon Sep 17 00:00:00 2001 From: dzu Date: Tue, 17 Feb 2026 14:01:51 +0000 Subject: [PATCH 05/23] dbg: log the uri used --- src/main.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 9e674b8..34f25a2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -95,11 +95,10 @@ struct CacheId(u64); impl Client { fn reserve(&self, key: &CacheKey, cacheSize: usize) -> Result { + let uri = format!("{}/_apis/artifactcache/reverveCache", self.base_url); + println!("will use uri: {uri}"); let request = Request::builder() - .uri(format!( - "{}/_apis/artifactcache/reverveCache", - self.base_url - )) + .uri(uri) .method(Method::POST) .body( serde_json::json! {{ -- 2.54.0 From 9931aec24da3e022e223029a0ec6f0d09c0ee54e Mon Sep 17 00:00:00 2001 From: dzu Date: Tue, 17 Feb 2026 18:54:20 +0000 Subject: [PATCH 06/23] fix: endpoint typo --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 34f25a2..5581e06 100644 --- a/src/main.rs +++ b/src/main.rs @@ -95,7 +95,7 @@ struct CacheId(u64); impl Client { fn reserve(&self, key: &CacheKey, cacheSize: usize) -> Result { - let uri = format!("{}/_apis/artifactcache/reverveCache", self.base_url); + let uri = format!("{}/_apis/artifactcache/reserveCache", self.base_url); println!("will use uri: {uri}"); let request = Request::builder() .uri(uri) -- 2.54.0 From 770ef5f8fc429fd8fb6bfc97d707b1eacede1301 Mon Sep 17 00:00:00 2001 From: dzu Date: Tue, 17 Feb 2026 18:54:44 +0000 Subject: [PATCH 07/23] minor: capitalization --- src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 5581e06..c0e4b17 100644 --- a/src/main.rs +++ b/src/main.rs @@ -94,7 +94,7 @@ struct Client { struct CacheId(u64); impl Client { - fn reserve(&self, key: &CacheKey, cacheSize: usize) -> Result { + fn reserve(&self, key: &CacheKey, cache_size: usize) -> Result { let uri = format!("{}/_apis/artifactcache/reserveCache", self.base_url); println!("will use uri: {uri}"); let request = Request::builder() @@ -104,7 +104,7 @@ impl Client { serde_json::json! {{ "key": &key.0, "version": "0", - "cacheSize": cacheSize, + "cacheSize": cache_size, }} .to_string(), ) -- 2.54.0 From 39dae4365d4194f5e2e363dea7418d390a612f9b Mon Sep 17 00:00:00 2001 From: dzu Date: Tue, 17 Feb 2026 19:05:47 +0000 Subject: [PATCH 08/23] use correct cache URL --- src/main.rs | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/main.rs b/src/main.rs index c0e4b17..f5d1288 100644 --- a/src/main.rs +++ b/src/main.rs @@ -65,9 +65,6 @@ struct Input { /// Must be in UTF-8 #[parser(key_parser)] key: CacheKey, - /// A server url to upload the cache to - #[default_str("${{ forgejo.api_url }}")] - base_url: String, } #[derive(Debug, thiserror::Error)] @@ -127,11 +124,7 @@ impl Client { fn main() { // parse inputs - let Input { - path, - key, - base_url, - } = Input::get(); + let Input { path, key } = Input::get(); let actions_token = actions_token().unwrap(); // set up http client @@ -142,7 +135,7 @@ fn main() { .unwrap(); let client = Client { http_client, - base_url, + base_url: std::env::var("ACTIONS_CACHE_URL").unwrap(), }; // collect and compress the cached files -- 2.54.0 From 6fe8aa2ee29048ba5dbd62655ed6b0d57d27c2c1 Mon Sep 17 00:00:00 2001 From: dzu Date: Tue, 17 Feb 2026 19:55:27 +0000 Subject: [PATCH 09/23] fix: reserve url ? --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index f5d1288..e6dfa62 100644 --- a/src/main.rs +++ b/src/main.rs @@ -92,7 +92,7 @@ struct CacheId(u64); impl Client { fn reserve(&self, key: &CacheKey, cache_size: usize) -> Result { - let uri = format!("{}/_apis/artifactcache/reserveCache", self.base_url); + let uri = format!("{}_apis/artifactcache/caches", self.base_url); println!("will use uri: {uri}"); let request = Request::builder() .uri(uri) -- 2.54.0 From b3b08936f26f478d579daccc2097ba917cb732cf Mon Sep 17 00:00:00 2001 From: dzu Date: Tue, 17 Feb 2026 20:15:00 +0000 Subject: [PATCH 10/23] add: cacheId parsing and priting --- src/main.rs | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index e6dfa62..c6aef4a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -use std::{ffi::OsString, path::PathBuf, str::FromStr, string::FromUtf8Error}; +use std::{ffi::OsString, io::Read, path::PathBuf, str::FromStr, string::FromUtf8Error}; use anyhow::{Context, Result, bail}; use flate2::{Compression, GzBuilder}; @@ -93,7 +93,6 @@ struct CacheId(u64); impl Client { fn reserve(&self, key: &CacheKey, cache_size: usize) -> Result { let uri = format!("{}_apis/artifactcache/caches", self.base_url); - println!("will use uri: {uri}"); let request = Request::builder() .uri(uri) .method(Method::POST) @@ -118,7 +117,25 @@ impl Client { ); } - todo!() + let mut body = Vec::with_capacity(100); + response + .into_body() + .read_to_end(&mut body) + .context("reading response body")?; + let body_value = + serde_json::from_slice::(&body).context("parsing response body")?; + + println!("{body_value:#?}"); + + let cache_id = body_value + .get("result") + .context("response.result")? + .get("cacheId") + .context("response.result.cacheId")? + .as_u64() + .context("cacheId as u64")?; + + Ok(CacheId(cache_id)) } } @@ -160,4 +177,6 @@ fn main() { let cache_id = client.reserve(&key, output.len()).unwrap(); println!("Reserved cache with id {cache_id:?}"); + + todo!(); } -- 2.54.0 From 8a6ad8af24ddc5a1e7eaecfa4913841b296b4770 Mon Sep 17 00:00:00 2001 From: dzu Date: Tue, 17 Feb 2026 20:19:14 +0000 Subject: [PATCH 11/23] fix: cacheId respose path --- src/main.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index c6aef4a..d06427f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -128,10 +128,8 @@ impl Client { println!("{body_value:#?}"); let cache_id = body_value - .get("result") - .context("response.result")? .get("cacheId") - .context("response.result.cacheId")? + .context("response.cacheId")? .as_u64() .context("cacheId as u64")?; -- 2.54.0 From 1aa6a60f4ea6fc01a2ddb7e6cc1748b1224a7d16 Mon Sep 17 00:00:00 2001 From: dzu Date: Tue, 17 Feb 2026 20:30:31 +0000 Subject: [PATCH 12/23] add: save the cache + minor formatting --- src/main.rs | 47 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/src/main.rs b/src/main.rs index d06427f..5822c90 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,10 +6,10 @@ use isahc::{ HttpClient, HttpClientBuilder, Request, auth::{Authentication, Credentials}, config::Configurable, - http::{Method, StatusCode, Uri}, + http::{Method, StatusCode}, }; use secrecy::{ExposeSecret, SecretString}; -use tar::{Archive, Builder, HeaderMode}; +use tar::{Builder, HeaderMode}; fn paths_parser(input: OsString) -> Result, FromUtf8Error> { let input = String::from_utf8(input.into_encoded_bytes())?; @@ -105,23 +105,23 @@ impl Client { .to_string(), ) .context("building the request")?; - let response = self + let mut response = self .http_client .send(request) .context("sending the request")?; let status = response.status(); + let mut body = Vec::with_capacity(100); + response + .body_mut() + .read_to_end(&mut body) + .context("reading response body")?; if status != StatusCode::OK { bail!( "Failed reserving a cache (status {status}): {:?}", - response.body() + String::from_utf8_lossy(&body) ); } - let mut body = Vec::with_capacity(100); - response - .into_body() - .read_to_end(&mut body) - .context("reading response body")?; let body_value = serde_json::from_slice::(&body).context("parsing response body")?; @@ -135,6 +135,33 @@ impl Client { Ok(CacheId(cache_id)) } + + fn save(&self, id: CacheId, archive: Vec) -> Result<()> { + let uri = format!("{}_apis/artifactcache/caches/{}", self.base_url, id.0); + let request = Request::builder() + .uri(uri) + .method(Method::PATCH) + .body(archive) + .context("building the request")?; + let mut response = self + .http_client + .send(request) + .context("sending the request")?; + let status = response.status(); + let mut body = Vec::with_capacity(100); + response + .body_mut() + .read_to_end(&mut body) + .context("reading response body")?; + if status != StatusCode::OK { + bail!( + "Failed saving a cache (status {status}): {:?}", + String::from_utf8_lossy(&body) + ); + } + + Ok(()) + } } fn main() { @@ -176,5 +203,5 @@ fn main() { println!("Reserved cache with id {cache_id:?}"); - todo!(); + client.save(cache_id, output).unwrap(); } -- 2.54.0 From af385b3f82ceea3870cf98926edc493c512fc081 Mon Sep 17 00:00:00 2001 From: dzu Date: Tue, 17 Feb 2026 20:38:15 +0000 Subject: [PATCH 13/23] fix: add upload headers --- src/main.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 5822c90..15ed1ba 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,7 +6,7 @@ use isahc::{ HttpClient, HttpClientBuilder, Request, auth::{Authentication, Credentials}, config::Configurable, - http::{Method, StatusCode}, + http::{Method, StatusCode, header}, }; use secrecy::{ExposeSecret, SecretString}; use tar::{Builder, HeaderMode}; @@ -141,6 +141,11 @@ impl Client { let request = Request::builder() .uri(uri) .method(Method::PATCH) + .header(header::CONTENT_TYPE, "application/octet-stream") + .header( + header::CONTENT_RANGE, + format!("bytes {}-{}/*", 0, archive.len()), + ) .body(archive) .context("building the request")?; let mut response = self -- 2.54.0 From d110f903b100f94f4bff4bb3685fe923a2424317 Mon Sep 17 00:00:00 2001 From: dzu Date: Thu, 19 Feb 2026 10:17:59 +0000 Subject: [PATCH 14/23] move out the common code --- Cargo.lock | 23 +++++-- Cargo.toml | 3 +- src/main.rs | 179 ++++------------------------------------------------ 3 files changed, 32 insertions(+), 173 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b4a3212..6d3cb2a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -29,6 +29,18 @@ dependencies = [ "yaml_serde", ] +[[package]] +name = "anode-cache-common" +version = "0.1.0" +source = "git+https://git.dzuchun.ing/actions/cache-common-src.git#9de30e2308eedaf79384260c8c915573cad011b4" +dependencies = [ + "anyhow", + "isahc", + "secrecy", + "serde_json", + "thiserror", +] + [[package]] name = "anode-macros" version = "0.1.0" @@ -98,11 +110,10 @@ version = "0.1.0" dependencies = [ "anode", "anode-build", + "anode-cache-common", "anyhow", "flate2", - "isahc", "secrecy", - "serde_json", "tar", "thiserror", ] @@ -817,9 +828,9 @@ checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" [[package]] name = "syn" -version = "2.0.115" +version = "2.0.116" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e614ed320ac28113fa64972c4262d5dbc89deacdfd00c34a3e4cea073243c12" +checksum = "3df424c70518695237746f84cede799c9c58fcb37450d7b23716568cc8bc69cb" dependencies = [ "proc-macro2", "quote", @@ -922,9 +933,9 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.23" +version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "537dd038a89878be9b64dd4bd1b260315c1bb94f4d784956b81e27a088d9a09e" +checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" [[package]] name = "unsafe-libyaml" diff --git a/Cargo.toml b/Cargo.toml index d19fdd3..254beca 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,11 +5,10 @@ edition = "2024" [dependencies] anode = { git = "https://git.dzuchun.ing/dzu/anode.git", version = "0.1.0" } +anode-cache-common = { git = "https://git.dzuchun.ing/actions/cache-common-src.git", version = "0.1.0" } anyhow = "1.0.101" flate2 = "1.1.9" -isahc = { version = "1.7.2", features = ["static-ssl", "static-curl"] } secrecy = "0.10.3" -serde_json = "1.0.149" tar = "0.4.44" thiserror = "2.0.18" diff --git a/src/main.rs b/src/main.rs index 15ed1ba..737194f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,55 +1,11 @@ -use std::{ffi::OsString, io::Read, path::PathBuf, str::FromStr, string::FromUtf8Error}; +use std::path::PathBuf; -use anyhow::{Context, Result, bail}; +use anode_cache_common::{CacheKey, Client, actions_token, key_parser, paths_parser}; +use anyhow::{Context, Result}; use flate2::{Compression, GzBuilder}; -use isahc::{ - HttpClient, HttpClientBuilder, Request, - auth::{Authentication, Credentials}, - config::Configurable, - http::{Method, StatusCode, header}, -}; -use secrecy::{ExposeSecret, SecretString}; +use secrecy::ExposeSecret; use tar::{Builder, HeaderMode}; -fn paths_parser(input: OsString) -> Result, FromUtf8Error> { - let input = String::from_utf8(input.into_encoded_bytes())?; - let mut paths = Vec::new(); - for path in input.split('\n').filter(|s| !s.is_empty()) { - paths.push(match PathBuf::from_str(path) { - Ok(ok) => ok, - }); - } - Ok(paths) -} - -#[derive(Debug)] -struct CacheKey(String); - -#[derive(Debug, thiserror::Error)] -enum CacheKeyError { - #[error(transparent)] - Utf8(#[from] FromUtf8Error), - #[error("Cache key is at most 512 characters long. {len} characters long key provided")] - Length { len: usize }, - #[error("Cache key cannot contain commas. Comma found at offset {offset}")] - Comma { offset: usize }, -} - -fn key_parser(input: OsString) -> Result { - let input = String::from_utf8(input.into_encoded_bytes())?; - let mut len = 0; - for (offset, ch) in input.char_indices() { - if ch == ',' { - return Err(CacheKeyError::Comma { offset }); - } - len += 1; - } - if len > 512 { - return Err(CacheKeyError::Length { len }); - } - Ok(CacheKey(input)) -} - #[derive(Debug, anode::Input)] #[name = "Cache save"] struct Input { @@ -67,123 +23,16 @@ struct Input { key: CacheKey, } -#[derive(Debug, thiserror::Error)] -enum ActionsTokenError { - #[error("Could not find action runtime token")] - NotPresent, - #[error("Action runtime token was not UTF-8 -encoded")] - NotUtf8, -} - -fn actions_token() -> Result { - let os_str = std::env::var_os("ACTIONS_RUNTIME_TOKEN").ok_or(ActionsTokenError::NotPresent)?; - let str = - String::from_utf8(os_str.into_encoded_bytes()).map_err(|_| ActionsTokenError::NotUtf8)?; - Ok(SecretString::new(str.into_boxed_str())) -} - -struct Client { - http_client: HttpClient, - base_url: String, -} - -#[derive(Debug, Clone, Copy)] -struct CacheId(u64); - -impl Client { - fn reserve(&self, key: &CacheKey, cache_size: usize) -> Result { - let uri = format!("{}_apis/artifactcache/caches", self.base_url); - let request = Request::builder() - .uri(uri) - .method(Method::POST) - .body( - serde_json::json! {{ - "key": &key.0, - "version": "0", - "cacheSize": cache_size, - }} - .to_string(), - ) - .context("building the request")?; - let mut response = self - .http_client - .send(request) - .context("sending the request")?; - let status = response.status(); - let mut body = Vec::with_capacity(100); - response - .body_mut() - .read_to_end(&mut body) - .context("reading response body")?; - if status != StatusCode::OK { - bail!( - "Failed reserving a cache (status {status}): {:?}", - String::from_utf8_lossy(&body) - ); - } - - let body_value = - serde_json::from_slice::(&body).context("parsing response body")?; - - println!("{body_value:#?}"); - - let cache_id = body_value - .get("cacheId") - .context("response.cacheId")? - .as_u64() - .context("cacheId as u64")?; - - Ok(CacheId(cache_id)) - } - - fn save(&self, id: CacheId, archive: Vec) -> Result<()> { - let uri = format!("{}_apis/artifactcache/caches/{}", self.base_url, id.0); - let request = Request::builder() - .uri(uri) - .method(Method::PATCH) - .header(header::CONTENT_TYPE, "application/octet-stream") - .header( - header::CONTENT_RANGE, - format!("bytes {}-{}/*", 0, archive.len()), - ) - .body(archive) - .context("building the request")?; - let mut response = self - .http_client - .send(request) - .context("sending the request")?; - let status = response.status(); - let mut body = Vec::with_capacity(100); - response - .body_mut() - .read_to_end(&mut body) - .context("reading response body")?; - if status != StatusCode::OK { - bail!( - "Failed saving a cache (status {status}): {:?}", - String::from_utf8_lossy(&body) - ); - } - - Ok(()) - } -} - -fn main() { +fn main() -> Result<()> { // parse inputs let Input { path, key } = Input::get(); - let actions_token = actions_token().unwrap(); + let actions_token = actions_token().context("reading actions token")?; + + let cache_url = std::env::var("ACTIONS_CACHE_URL").context("reading action cache url")?; // set up http client - let http_client = HttpClientBuilder::new() - .authentication(Authentication::basic()) - .credentials(Credentials::new("Bearer", actions_token.expose_secret())) - .build() - .unwrap(); - let client = Client { - http_client, - base_url: std::env::var("ACTIONS_CACHE_URL").unwrap(), - }; + let client = Client::new(actions_token.expose_secret(), cache_url) + .context("intializing cache client")?; // collect and compress the cached files let mut output = Vec::::with_capacity(1024 * 1024); // assume large cache size @@ -204,9 +53,9 @@ fn main() { archive.finish().unwrap(); } - let cache_id = client.reserve(&key, output.len()).unwrap(); + client + .save_cache(&key, output) + .context("saving the cache")?; - println!("Reserved cache with id {cache_id:?}"); - - client.save(cache_id, output).unwrap(); + Ok(()) } -- 2.54.0 From 285f856cb733ea41f2e50e29fa8a569552a3ad1c Mon Sep 17 00:00:00 2001 From: dzu Date: Fri, 20 Feb 2026 08:51:44 +0000 Subject: [PATCH 15/23] add: cargo release profile config --- Cargo.toml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 254beca..6bd5677 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,10 +15,10 @@ thiserror = "2.0.18" [build-dependencies] anode-build = { git = "https://git.dzuchun.ing/dzu/anode.git", version = "0.1.0" } -# [profile.release] -# opt-level = "s" -# lto = true -# codegen-units = 1 -# strip = true -# panic = "abort" -# incremental = false +[profile.release] +opt-level = "s" +lto = true +codegen-units = 1 +strip = true +panic = "abort" +incremental = false -- 2.54.0 From 144385a87e977c43ac946e0844e66450171be57c Mon Sep 17 00:00:00 2001 From: dzu Date: Fri, 20 Feb 2026 08:59:10 +0000 Subject: [PATCH 16/23] rem: thiserror dependency --- Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 6bd5677..099d465 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,6 @@ anyhow = "1.0.101" flate2 = "1.1.9" secrecy = "0.10.3" tar = "0.4.44" -thiserror = "2.0.18" [build-dependencies] anode-build = { git = "https://git.dzuchun.ing/dzu/anode.git", version = "0.1.0" } -- 2.54.0 From 1c6d38bdef1f64adc3a940db77df453454c46c87 Mon Sep 17 00:00:00 2001 From: dzu Date: Fri, 20 Feb 2026 08:59:33 +0000 Subject: [PATCH 17/23] upd: common repo ref --- Cargo.lock | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6d3cb2a..c0161bb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -32,7 +32,7 @@ dependencies = [ [[package]] name = "anode-cache-common" version = "0.1.0" -source = "git+https://git.dzuchun.ing/actions/cache-common-src.git#9de30e2308eedaf79384260c8c915573cad011b4" +source = "git+https://git.dzuchun.ing/actions/cache-common-src.git#03a207d32a9b72647a5a1015b3cf63adb6d24b36" dependencies = [ "anyhow", "isahc", @@ -65,9 +65,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.101" +version = "1.0.102" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f0e0fee31ef5ed1ba1316088939cea399010ed7731dba877ed44aeb407a75ea" +checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c" [[package]] name = "async-channel" @@ -115,7 +115,6 @@ dependencies = [ "flate2", "secrecy", "tar", - "thiserror", ] [[package]] @@ -828,9 +827,9 @@ checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" [[package]] name = "syn" -version = "2.0.116" +version = "2.0.117" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3df424c70518695237746f84cede799c9c58fcb37450d7b23716568cc8bc69cb" +checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99" dependencies = [ "proc-macro2", "quote", -- 2.54.0 From bd2ba0b2e76521b43719a687e80627973d700f42 Mon Sep 17 00:00:00 2001 From: dzu Date: Fri, 20 Feb 2026 10:17:03 +0000 Subject: [PATCH 18/23] ench: add warn for saving non-existent paths --- src/main.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main.rs b/src/main.rs index 737194f..d1c275d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -42,6 +42,13 @@ fn main() -> Result<()> { archive.mode(HeaderMode::Complete); archive.follow_symlinks(false); for path in path { + if !path.exists() { + println!( + "warn: path {} does not exist, and will not be cached", + path.display() + ); + continue; + } if path.is_dir() { // we actually want to write out all the directory contents archive.append_dir_all("", path).unwrap(); -- 2.54.0 From 285a3236bfd0db327d80d02248098b01605fba75 Mon Sep 17 00:00:00 2001 From: dzu Date: Fri, 20 Feb 2026 10:41:00 +0000 Subject: [PATCH 19/23] fix: save directories at the correct paths --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index d1c275d..2ff9a80 100644 --- a/src/main.rs +++ b/src/main.rs @@ -51,7 +51,7 @@ fn main() -> Result<()> { } if path.is_dir() { // we actually want to write out all the directory contents - archive.append_dir_all("", path).unwrap(); + archive.append_dir_all(&path, &path).unwrap(); } else if path.is_file() { // rest of the file types are handled by the existing inner code archive.append_path(path).unwrap(); -- 2.54.0 From a67277b563322cda146237f29dd76070992f368f Mon Sep 17 00:00:00 2001 From: dzu Date: Fri, 20 Feb 2026 14:41:48 +0000 Subject: [PATCH 20/23] ench: use `tracing` for logging --- Cargo.lock | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++- Cargo.toml | 1 + src/main.rs | 23 ++++++++++++++---- 3 files changed, 88 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c0161bb..b51c609 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -32,13 +32,15 @@ dependencies = [ [[package]] name = "anode-cache-common" 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 = [ "anyhow", "isahc", "secrecy", "serde_json", "thiserror", + "tracing", + "tracing-subscriber", ] [[package]] @@ -115,6 +117,7 @@ dependencies = [ "flate2", "secrecy", "tar", + "tracing", ] [[package]] @@ -485,6 +488,12 @@ version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2" +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + [[package]] name = "libc" version = "0.2.182" @@ -564,6 +573,15 @@ dependencies = [ "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]] name = "once_cell" version = "1.21.3" @@ -774,6 +792,15 @@ dependencies = [ "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]] name = "shlex" version = "1.3.0" @@ -878,6 +905,15 @@ dependencies = [ "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]] name = "tinystr" version = "0.8.2" @@ -918,6 +954,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a" dependencies = [ "once_cell", + "valuable", ] [[package]] @@ -930,6 +967,31 @@ dependencies = [ "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]] name = "unicode-ident" version = "1.0.24" @@ -960,6 +1022,12 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" +[[package]] +name = "valuable" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65" + [[package]] name = "vcpkg" version = "0.2.15" diff --git a/Cargo.toml b/Cargo.toml index 099d465..6386de0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ anyhow = "1.0.101" flate2 = "1.1.9" secrecy = "0.10.3" tar = "0.4.44" +tracing = { version = "0.1.44", features = ["attributes"] } [build-dependencies] anode-build = { git = "https://git.dzuchun.ing/dzu/anode.git", version = "0.1.0" } diff --git a/src/main.rs b/src/main.rs index 2ff9a80..d6c7f06 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,6 +5,7 @@ use anyhow::{Context, Result}; use flate2::{Compression, GzBuilder}; use secrecy::ExposeSecret; use tar::{Builder, HeaderMode}; +use tracing::{debug, info_span, warn}; #[derive(Debug, anode::Input)] #[name = "Cache save"] @@ -21,11 +22,17 @@ struct Input { /// Must be in UTF-8 #[parser(key_parser)] key: CacheKey, + /// If the debug log should be printed + /// + /// If omitted, defined by compiler settings (print debug if `debug_assertions` is enabled) + debug: Option, } fn main() -> Result<()> { // 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 cache_url = std::env::var("ACTIONS_CACHE_URL").context("reading action cache url")?; @@ -33,6 +40,7 @@ fn main() -> Result<()> { // set up http client let client = Client::new(actions_token.expose_secret(), cache_url) .context("intializing cache client")?; + debug!("Cache client initialized"); // collect and compress the cached files let mut output = Vec::::with_capacity(1024 * 1024); // assume large cache size @@ -41,24 +49,29 @@ fn main() -> Result<()> { let mut archive = Builder::new(out_comp); archive.mode(HeaderMode::Complete); archive.follow_symlinks(false); + debug!(paths = ?path); for path in path { + let _span = info_span!("cache-entry"); + let _span = _span.enter(); if !path.exists() { - println!( - "warn: path {} does not exist, and will not be cached", - path.display() - ); + warn!("Path does not exist, and will not be cached"); continue; } if path.is_dir() { + debug!("Caching directory"); // we actually want to write out all the directory contents archive.append_dir_all(&path, &path).unwrap(); } else if path.is_file() { + debug!("Caching a file"); // rest of the file types are handled by the existing inner code archive.append_path(path).unwrap(); + } else { + warn!("Path is neither directory, nor a file and will not be cached"); } } archive.finish().unwrap(); } + debug!("Cache archive cleated"); client .save_cache(&key, output) -- 2.54.0 From 06f4c69350592c039084d36bb46d009bff1e0ebf Mon Sep 17 00:00:00 2001 From: dzu Date: Fri, 20 Feb 2026 15:01:44 +0000 Subject: [PATCH 21/23] upd: bump anode revision --- Cargo.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b51c609..73cd863 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11,7 +11,7 @@ checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" [[package]] name = "anode" version = "0.1.0" -source = "git+https://git.dzuchun.ing/dzu/anode.git#2c1972141b3c011df32341385c858af5ae656a85" +source = "git+https://git.dzuchun.ing/dzu/anode.git#98addf4d54ae16c21979a1dae63d17738b3a277b" dependencies = [ "anode-macros", "thiserror", @@ -20,7 +20,7 @@ dependencies = [ [[package]] name = "anode-build" version = "0.1.0" -source = "git+https://git.dzuchun.ing/dzu/anode.git#2c1972141b3c011df32341385c858af5ae656a85" +source = "git+https://git.dzuchun.ing/dzu/anode.git#98addf4d54ae16c21979a1dae63d17738b3a277b" dependencies = [ "anode-macros-input", "quote", @@ -46,7 +46,7 @@ dependencies = [ [[package]] name = "anode-macros" version = "0.1.0" -source = "git+https://git.dzuchun.ing/dzu/anode.git#2c1972141b3c011df32341385c858af5ae656a85" +source = "git+https://git.dzuchun.ing/dzu/anode.git#98addf4d54ae16c21979a1dae63d17738b3a277b" dependencies = [ "anode-macros-input", "proc-macro2", @@ -58,7 +58,7 @@ dependencies = [ [[package]] name = "anode-macros-input" version = "0.1.0" -source = "git+https://git.dzuchun.ing/dzu/anode.git#2c1972141b3c011df32341385c858af5ae656a85" +source = "git+https://git.dzuchun.ing/dzu/anode.git#98addf4d54ae16c21979a1dae63d17738b3a277b" dependencies = [ "proc-macro2", "quote", -- 2.54.0 From 735e735ab9940689fa367355cd941a79057afb25 Mon Sep 17 00:00:00 2001 From: dzu Date: Sat, 21 Feb 2026 03:24:20 +0000 Subject: [PATCH 22/23] rel: lock git dependencies revisions --- Cargo.lock | 10 +++++----- Cargo.toml | 15 +++++++++++---- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 73cd863..216a648 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11,7 +11,7 @@ checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" [[package]] name = "anode" version = "0.1.0" -source = "git+https://git.dzuchun.ing/dzu/anode.git#98addf4d54ae16c21979a1dae63d17738b3a277b" +source = "git+https://git.dzuchun.ing/dzu/anode.git?rev=98addf4d54ae16c21979a1dae63d17738b3a277b#98addf4d54ae16c21979a1dae63d17738b3a277b" dependencies = [ "anode-macros", "thiserror", @@ -20,7 +20,7 @@ dependencies = [ [[package]] name = "anode-build" version = "0.1.0" -source = "git+https://git.dzuchun.ing/dzu/anode.git#98addf4d54ae16c21979a1dae63d17738b3a277b" +source = "git+https://git.dzuchun.ing/dzu/anode.git?rev=98addf4d54ae16c21979a1dae63d17738b3a277b#98addf4d54ae16c21979a1dae63d17738b3a277b" dependencies = [ "anode-macros-input", "quote", @@ -32,7 +32,7 @@ dependencies = [ [[package]] name = "anode-cache-common" version = "0.1.0" -source = "git+https://git.dzuchun.ing/actions/cache-common-src.git#479d6fe4149b1cc4c81486fdf0eb6f6a56fc9282" +source = "git+https://git.dzuchun.ing/actions/cache-common-src.git?rev=5656a3ff6f58a48e3365c221fb2102918db6c284#5656a3ff6f58a48e3365c221fb2102918db6c284" dependencies = [ "anyhow", "isahc", @@ -46,7 +46,7 @@ dependencies = [ [[package]] name = "anode-macros" version = "0.1.0" -source = "git+https://git.dzuchun.ing/dzu/anode.git#98addf4d54ae16c21979a1dae63d17738b3a277b" +source = "git+https://git.dzuchun.ing/dzu/anode.git?rev=98addf4d54ae16c21979a1dae63d17738b3a277b#98addf4d54ae16c21979a1dae63d17738b3a277b" dependencies = [ "anode-macros-input", "proc-macro2", @@ -58,7 +58,7 @@ dependencies = [ [[package]] name = "anode-macros-input" version = "0.1.0" -source = "git+https://git.dzuchun.ing/dzu/anode.git#98addf4d54ae16c21979a1dae63d17738b3a277b" +source = "git+https://git.dzuchun.ing/dzu/anode.git?rev=98addf4d54ae16c21979a1dae63d17738b3a277b#98addf4d54ae16c21979a1dae63d17738b3a277b" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index 6386de0..f77def7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,16 +4,23 @@ version = "0.1.0" edition = "2024" [dependencies] -anode = { git = "https://git.dzuchun.ing/dzu/anode.git", version = "0.1.0" } -anode-cache-common = { git = "https://git.dzuchun.ing/actions/cache-common-src.git", version = "0.1.0" } anyhow = "1.0.101" flate2 = "1.1.9" secrecy = "0.10.3" tar = "0.4.44" tracing = { version = "0.1.44", features = ["attributes"] } -[build-dependencies] -anode-build = { git = "https://git.dzuchun.ing/dzu/anode.git", version = "0.1.0" } +[dependencies.anode] +git = "https://git.dzuchun.ing/dzu/anode.git" +rev = "98addf4d54ae16c21979a1dae63d17738b3a277b" + +[dependencies.anode-cache-common] +git = "https://git.dzuchun.ing/actions/cache-common-src.git" +rev = "5656a3ff6f58a48e3365c221fb2102918db6c284" + +[build-dependencies.anode-build] +git = "https://git.dzuchun.ing/dzu/anode.git" +rev = "98addf4d54ae16c21979a1dae63d17738b3a277b" [profile.release] opt-level = "s" -- 2.54.0 From 540398e562b0d8b687c8acf4236e031dc08bc948 Mon Sep 17 00:00:00 2001 From: dzu Date: Sat, 21 Feb 2026 09:57:13 +0000 Subject: [PATCH 23/23] upd: bump common crate to v2 --- Cargo.lock | 10 +++++----- Cargo.toml | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 216a648..baf73f7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11,7 +11,7 @@ checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" [[package]] name = "anode" version = "0.1.0" -source = "git+https://git.dzuchun.ing/dzu/anode.git?rev=98addf4d54ae16c21979a1dae63d17738b3a277b#98addf4d54ae16c21979a1dae63d17738b3a277b" +source = "git+https://git.dzuchun.ing/dzu/anode.git?tag=v1#98addf4d54ae16c21979a1dae63d17738b3a277b" dependencies = [ "anode-macros", "thiserror", @@ -20,7 +20,7 @@ dependencies = [ [[package]] name = "anode-build" version = "0.1.0" -source = "git+https://git.dzuchun.ing/dzu/anode.git?rev=98addf4d54ae16c21979a1dae63d17738b3a277b#98addf4d54ae16c21979a1dae63d17738b3a277b" +source = "git+https://git.dzuchun.ing/dzu/anode.git?tag=v1#98addf4d54ae16c21979a1dae63d17738b3a277b" dependencies = [ "anode-macros-input", "quote", @@ -32,7 +32,7 @@ dependencies = [ [[package]] name = "anode-cache-common" version = "0.1.0" -source = "git+https://git.dzuchun.ing/actions/cache-common-src.git?rev=5656a3ff6f58a48e3365c221fb2102918db6c284#5656a3ff6f58a48e3365c221fb2102918db6c284" +source = "git+https://git.dzuchun.ing/actions/cache-common-src.git?tag=v2#0a3a59229111c6a96a2565de8a3e097c7bc2808b" dependencies = [ "anyhow", "isahc", @@ -46,7 +46,7 @@ dependencies = [ [[package]] name = "anode-macros" version = "0.1.0" -source = "git+https://git.dzuchun.ing/dzu/anode.git?rev=98addf4d54ae16c21979a1dae63d17738b3a277b#98addf4d54ae16c21979a1dae63d17738b3a277b" +source = "git+https://git.dzuchun.ing/dzu/anode.git?tag=v1#98addf4d54ae16c21979a1dae63d17738b3a277b" dependencies = [ "anode-macros-input", "proc-macro2", @@ -58,7 +58,7 @@ dependencies = [ [[package]] name = "anode-macros-input" version = "0.1.0" -source = "git+https://git.dzuchun.ing/dzu/anode.git?rev=98addf4d54ae16c21979a1dae63d17738b3a277b#98addf4d54ae16c21979a1dae63d17738b3a277b" +source = "git+https://git.dzuchun.ing/dzu/anode.git?tag=v1#98addf4d54ae16c21979a1dae63d17738b3a277b" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index f77def7..d295da4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,15 +12,15 @@ tracing = { version = "0.1.44", features = ["attributes"] } [dependencies.anode] git = "https://git.dzuchun.ing/dzu/anode.git" -rev = "98addf4d54ae16c21979a1dae63d17738b3a277b" +tag = "v1" [dependencies.anode-cache-common] git = "https://git.dzuchun.ing/actions/cache-common-src.git" -rev = "5656a3ff6f58a48e3365c221fb2102918db6c284" +tag = "v2" [build-dependencies.anode-build] git = "https://git.dzuchun.ing/dzu/anode.git" -rev = "98addf4d54ae16c21979a1dae63d17738b3a277b" +tag = "v1" [profile.release] opt-level = "s" -- 2.54.0