Compare commits
6 changed files with 0 additions and 1455 deletions
|
|
@ -1,26 +0,0 @@
|
||||||
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-load-src.git
|
|
||||||
src-ref: ${{ forgejo.ref_name }}
|
|
||||||
src-token: ${{ secrets.GIT_TOKEN }}
|
|
||||||
dst-repository: https://git.dzuchun.ing/actions/cache-load.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
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -1,2 +0,0 @@
|
||||||
target/
|
|
||||||
action.yml
|
|
||||||
1319
Cargo.lock
generated
1319
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
23
Cargo.toml
23
Cargo.toml
|
|
@ -1,23 +0,0 @@
|
||||||
[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
3
build.rs
|
|
@ -1,3 +0,0 @@
|
||||||
fn main() {
|
|
||||||
anode_build::build();
|
|
||||||
}
|
|
||||||
82
src/main.rs
82
src/main.rs
|
|
@ -1,82 +0,0 @@
|
||||||
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