Skip to content

chore: update size-history to new cache API #2114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/size-history.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ jobs:
git submodule update --init dpe

- name: Configure actions-cache environment variables
uses: actions/github-script@v6
uses: actions/github-script@v7
with:
script: |
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
core.exportVariable('ACTIONS_RESULTS_URL', process.env.ACTIONS_RESULTS_URL || '');
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
core.exportVariable('ACTIONS_CACHE_SERVICE_V2', 'on');

- name: Run size analysis (look at workflow "Summary" tab for results)
run: |
Expand Down
54 changes: 54 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion ci-tools/size-history/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ edition = "2021"

[dependencies]
caliptra-builder.workspace = true
ghac = "0.2.0"
serde = { workspace = true, features = ["derive"] }
serde_json.workspace = true
tinytemplate.workspace = true
tinytemplate.workspace = true
29 changes: 18 additions & 11 deletions ci-tools/size-history/src/cache_gha.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Licensed under the Apache-2.0 license

use ghac::v1::{self as ghac_types, GetCacheEntryDownloadUrlResponse};
use serde::{Deserialize, Serialize};

use crate::{
Expand All @@ -15,10 +16,11 @@ pub struct GithubActionCache {
}
impl GithubActionCache {
pub fn new() -> std::io::Result<Self> {
let wrap_err = |_| other_err("ACTIONS_CACHE_URL environment variable not set".to_string());
let wrap_err =
|_| other_err("ACTIONS_RESULTS_URL environment variable not set".to_string());
let prefix = format!(
"{}/_apis/artifactcache",
std::env::var("ACTIONS_CACHE_URL").map_err(wrap_err)?
"{}/twirp/github.actions.results.api.v1.CacheService",
std::env::var("ACTIONS_RESULTS_URL").map_err(wrap_err)?
);
Ok(Self { prefix })
}
Expand Down Expand Up @@ -46,21 +48,26 @@ impl Cache for GithubActionCache {

fn get(&self, key: &str) -> std::io::Result<Option<Vec<u8>>> {
let url_key = format_key(key);
let response = http::api_get(&format!(
"{}/cache?keys={url_key}&version={VERSION}",
self.prefix
))?;
let request = ghac_types::GetCacheEntryDownloadUrlRequest {
key: url_key.clone(),
version: VERSION.into(),
metadata: None,
restore_keys: vec![],
};
let body = Buffer::from(request.encode_to_vec());
let response = http::api_post(&format!("{}/GetCacheEntryDownloadURL", self.prefix), body)?;
if response.status == 204 {
return Ok(None);
}
let response: CacheResponse = json_response(&response)?;
if response.cache_key != url_key {
let response: GetCacheEntryDownloadUrlResponse =
GetCacheEntryDownloadUrlResponse::decode(response.data)?;
if response.matched_key != url_key {
return Err(other_err(format!(
"Expected key {url_key:?}, was {:?}",
response.cache_key
response.matched_key
)));
}
let response = http::raw_get(&response.archive_location)?;
let response = http::raw_get(&response.signed_download_url)?;
Ok(Some(response.data))
}
}
Expand Down
Loading