Initial stabilization #1

Merged
dzu merged 22 commits from stabilize-v1 into main 2026-02-21 04:54:42 +01:00
Showing only changes of commit 1aa6a60f4e - Show all commits

add: save the cache
All checks were successful
Build and update the action / build-and-upload (push) Successful in 2m36s

+ minor formatting
Artem Diachenko 2026-02-17 20:30:31 +00:00

View file

@ -6,10 +6,10 @@ use isahc::{
HttpClient, HttpClientBuilder, Request, HttpClient, HttpClientBuilder, Request,
auth::{Authentication, Credentials}, auth::{Authentication, Credentials},
config::Configurable, config::Configurable,
http::{Method, StatusCode, Uri}, http::{Method, StatusCode},
}; };
use secrecy::{ExposeSecret, SecretString}; use secrecy::{ExposeSecret, SecretString};
use tar::{Archive, Builder, HeaderMode}; use tar::{Builder, HeaderMode};
fn paths_parser(input: OsString) -> Result<Vec<PathBuf>, FromUtf8Error> { fn paths_parser(input: OsString) -> Result<Vec<PathBuf>, FromUtf8Error> {
let input = String::from_utf8(input.into_encoded_bytes())?; let input = String::from_utf8(input.into_encoded_bytes())?;
@ -105,23 +105,23 @@ impl Client {
.to_string(), .to_string(),
) )
.context("building the request")?; .context("building the request")?;
let response = self let mut response = self
.http_client .http_client
.send(request) .send(request)
.context("sending the request")?; .context("sending the request")?;
let status = response.status(); 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 { if status != StatusCode::OK {
bail!( bail!(
"Failed reserving a cache (status {status}): {:?}", "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 = let body_value =
serde_json::from_slice::<serde_json::Value>(&body).context("parsing response body")?; serde_json::from_slice::<serde_json::Value>(&body).context("parsing response body")?;
@ -135,6 +135,33 @@ impl Client {
Ok(CacheId(cache_id)) Ok(CacheId(cache_id))
} }
fn save(&self, id: CacheId, archive: Vec<u8>) -> 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() { fn main() {
@ -176,5 +203,5 @@ fn main() {
println!("Reserved cache with id {cache_id:?}"); println!("Reserved cache with id {cache_id:?}");
todo!(); client.save(cache_id, output).unwrap();
} }