Initial stabilization #1

Merged
dzu merged 11 commits from stabilize-v1 into master 2026-02-21 04:17:06 +01:00
5 changed files with 1429 additions and 0 deletions
Showing only changes of commit d659076f1c - Show all commits

initial load version

Artem Diachenko 2026-02-20 08:21:08 +00:00

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
target/
action.yml

1319
Cargo.lock generated Normal file

File diff suppressed because it is too large Load diff

23
Cargo.toml Normal file
View file

@ -0,0 +1,23 @@
[package]
name = "cache-load"
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"
[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

3
build.rs Normal file
View file

@ -0,0 +1,3 @@
fn main() {
anode_build::build();
}

82
src/main.rs Normal file
View file

@ -0,0 +1,82 @@
use std::{collections::HashMap, path::PathBuf};
use anode_cache_common::{CacheKey, Client, actions_token, key_parser, paths_parser};
use anyhow::{Context, Result};
use flate2::{Compression, GzBuilder};
use secrecy::ExposeSecret;
use tar::Archive;
#[derive(Debug, anode::Input)]
#[name = "Cache load"]
struct Input {
/// A set of paths to load
///
/// Must be in UTF-8
#[parser(paths_parser)]
path: Vec<PathBuf>,
/// A key to cache the files with
///
/// Allowed to be at most 512 characters, and should not contain commas
///
/// Must be in UTF-8
#[parser(key_parser)]
key: CacheKey,
}
fn main() -> Result<()> {
// parse inputs
let Input { path, key } = Input::get();
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 client = Client::new(actions_token.expose_secret(), cache_url)
.context("intializing cache client")?;
// download the cache archive
let Some(cache) = client.load_cache(&key).context("loading the cache")? else {
println!("cache miss");
return Ok(());
};
let mut cache = &*cache;
let in_uncomp = GzBuilder::new().read(&mut cache, Compression::best());
let mut archive = Archive::new(in_uncomp);
let mut paths = path
.into_iter()
.map(|p| (p, true))
.collect::<HashMap<_, _>>();
let mut entry_path = PathBuf::new();
for entry in archive.entries().context("reading cache entries")? {
let mut entry = entry.context("reading cache entry")?;
entry_path.clear();
entry_path.push(entry.path().context("reading entry path")?.as_ref());
let Some(needs_unpacking) = paths.get_mut(&entry_path) else {
println!(
"warn: unknown entry in the archive: {}",
entry_path.display()
);
continue;
};
if !core::mem::replace(needs_unpacking, false) {
println!(
"warn: double entry in the archive: {}",
entry_path.display()
);
continue;
}
entry.unpack(&entry_path).context("writing cache entry")?;
}
for (path, needs_unpacking) in paths {
if needs_unpacking {
println!(
"warn: requested cached path was not found in the cache entry: {}",
path.display(),
);
}
}
Ok(())
}