From 3195570579016e5e39f258e4a31a276a5701279b Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Thu, 14 Sep 2023 18:25:24 +1000 Subject: [PATCH] Implement github actions cache --- src/python/pants/option/global_options.py | 10 ++++++++++ src/rust/engine/fs/store/src/remote.rs | 6 ++++++ .../engine/fs/store/src/remote/base_opendal.rs | 15 +++++++++++++++ .../process_execution/remote/src/remote_cache.rs | 6 ++++++ 4 files changed, 37 insertions(+) diff --git a/src/python/pants/option/global_options.py b/src/python/pants/option/global_options.py index 60ef83faa5bf..124d242b268b 100644 --- a/src/python/pants/option/global_options.py +++ b/src/python/pants/option/global_options.py @@ -280,6 +280,16 @@ def renderer(_: object) -> str: """ ), ), + _RemoteAddressScheme( + schemes=("github-actions-cache",), + supports_execution=False, + experimental=True, + description=softwrap( + """ + TODO + """ + ), + ), ) diff --git a/src/rust/engine/fs/store/src/remote.rs b/src/rust/engine/fs/store/src/remote.rs index 4e9c4be7da9d..2abeb6d8dd1c 100644 --- a/src/rust/engine/fs/store/src/remote.rs +++ b/src/rust/engine/fs/store/src/remote.rs @@ -81,6 +81,12 @@ async fn choose_provider(options: RemoteOptions) -> Result Result { + 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!( diff --git a/src/rust/engine/process_execution/remote/src/remote_cache.rs b/src/rust/engine/process_execution/remote/src/remote_cache.rs index a5c0f9429fe4..212fbfd3917c 100644 --- a/src/rust/engine/process_execution/remote/src/remote_cache.rs +++ b/src/rust/engine/process_execution/remote/src/remote_cache.rs @@ -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",