Skip to content

Commit

Permalink
Implement github actions cache
Browse files Browse the repository at this point in the history
  • Loading branch information
huonw committed Sep 21, 2023
1 parent de1a3d3 commit 3195570
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/python/pants/option/global_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,16 @@ def renderer(_: object) -> str:
"""
),
),
_RemoteAddressScheme(
schemes=("github-actions-cache",),
supports_execution=False,
experimental=True,
description=softwrap(
"""
TODO
"""
),
),
)


Expand Down
6 changes: 6 additions & 0 deletions src/rust/engine/fs/store/src/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ async fn choose_provider(options: RemoteOptions) -> Result<Arc<dyn ByteStoreProv
"byte-store".to_owned(),
options,
)?))
} else if let Some(path) = address.strip_prefix("github-actions-cache://") {
Ok(Arc::new(base_opendal::Provider::github_actions_cache(
path,
"byte-store".to_owned(),
options,
)?))
} else {
Err(format!(
"Cannot initialise remote byte store provider with address {address}, as the scheme is not supported",
Expand Down
15 changes: 15 additions & 0 deletions src/rust/engine/fs/store/src/remote/base_opendal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ use workunit_store::ObservationMetric;

use super::{ByteStoreProvider, LoadDestination, RemoteOptions};

const GITHUB_ACTIONS_CACHE_VERSION: &str = "pants-1";

#[derive(Debug, Clone, Copy)]
pub enum LoadMode {
Validate,
Expand Down Expand Up @@ -71,6 +73,19 @@ impl Provider {
Provider::new(builder, scope, options)
}

pub fn github_actions_cache(
path: &str,
scope: String,
options: RemoteOptions,
) -> Result<Provider, String> {
let mut builder = opendal::services::Ghac::default();
if !path.is_empty() {
builder.root(path);
}
builder.version(GITHUB_ACTIONS_CACHE_VERSION);
Provider::new(builder, scope, options)
}

fn path(&self, fingerprint: Fingerprint) -> String {
// We include the first two bytes as parent directories to make listings less wide.
format!(
Expand Down
6 changes: 6 additions & 0 deletions src/rust/engine/process_execution/remote/src/remote_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ async fn choose_provider(
"action-cache".to_owned(),
remote_options,
)?))
} else if let Some(path) = address.strip_prefix("github-actions-cache://") {
Ok(Arc::new(base_opendal::Provider::github_actions_cache(
path,
"action-cache".to_owned(),
remote_options,
)?))
} else {
Err(format!(
"Cannot initialise remote action cache provider with address {address}, as the scheme is not supported",
Expand Down

0 comments on commit 3195570

Please sign in to comment.