Initial stabilization #1
5 changed files with 1429 additions and 0 deletions
initial load version
commit
d659076f1c
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
target/
|
||||
action.yml
|
||||
1319
Cargo.lock
generated
Normal file
1319
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
23
Cargo.toml
Normal file
23
Cargo.toml
Normal 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
3
build.rs
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fn main() {
|
||||
anode_build::build();
|
||||
}
|
||||
82
src/main.rs
Normal file
82
src/main.rs
Normal 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(())
|
||||
}
|
||||
Loading…
Reference in a new issue