Skip to content
New issue

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

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

Already on GitHub? # to your account

feat(turbo): add cache flag #9348

Merged
merged 14 commits into from
Nov 5, 2024
Merged

feat(turbo): add cache flag #9348

merged 14 commits into from
Nov 5, 2024

Conversation

NicholasLYang
Copy link
Contributor

@NicholasLYang NicholasLYang commented Oct 29, 2024

Description

Adds a cache flag that lets you set cache permissions per cache type and per action (read or write)

Testing Instructions

Adds tests in turborepo_cache/src/config.rs for parsing and in turborepo-lib/src/opts.rs for loading and resolving

Copy link

vercel bot commented Oct 29, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
examples-nonmonorepo ❌ Failed (Inspect) Nov 5, 2024 5:07pm
8 Skipped Deployments
Name Status Preview Comments Updated (UTC)
examples-basic-web ⬜️ Ignored (Inspect) Visit Preview Nov 5, 2024 5:07pm
examples-designsystem-docs ⬜️ Ignored (Inspect) Visit Preview Nov 5, 2024 5:07pm
examples-gatsby-web ⬜️ Ignored (Inspect) Visit Preview Nov 5, 2024 5:07pm
examples-kitchensink-blog ⬜️ Ignored (Inspect) Visit Preview Nov 5, 2024 5:07pm
examples-native-web ⬜️ Ignored (Inspect) Visit Preview Nov 5, 2024 5:07pm
examples-svelte-web ⬜️ Ignored (Inspect) Visit Preview Nov 5, 2024 5:07pm
examples-tailwind-web ⬜️ Ignored (Inspect) Visit Preview Nov 5, 2024 5:07pm
examples-vite-web ⬜️ Ignored (Inspect) Visit Preview Nov 5, 2024 5:07pm

@NicholasLYang NicholasLYang force-pushed the nicholasyang/add-cache-flag branch from b9eea2e to 8fb5b84 Compare October 30, 2024 17:20
@NicholasLYang NicholasLYang force-pushed the nicholasyang/add-cache-flag branch from bfa85f1 to 02f4bfc Compare October 30, 2024 20:38
@NicholasLYang NicholasLYang force-pushed the nicholasyang/add-cache-flag branch from 02f4bfc to b5ffd7a Compare October 30, 2024 20:40
@NicholasLYang NicholasLYang force-pushed the nicholasyang/add-cache-flag branch from b5ffd7a to 0adcd94 Compare October 30, 2024 20:42
@NicholasLYang NicholasLYang force-pushed the nicholasyang/add-cache-flag branch from 0adcd94 to 0ee6787 Compare October 30, 2024 20:45
@NicholasLYang NicholasLYang marked this pull request as ready for review October 30, 2024 20:48
@NicholasLYang NicholasLYang requested a review from a team as a code owner October 30, 2024 20:48
Copy link
Member

@chris-olszewski chris-olszewski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm excited for this, biggest thing I'd like to see is some tests regarding how the new cache struct gets resolved wrt existing cache config settings.

@@ -362,16 +358,37 @@ impl<'a> TryFrom<OptsInputs<'a>> for ScopeOpts {
impl<'a> From<OptsInputs<'a>> for CacheOpts {
fn from(inputs: OptsInputs<'a>) -> Self {
let is_linked = turborepo_api_client::is_linked(inputs.api_auth);
let skip_remote = if !is_linked {
true
let mut cache = inputs.config.cache();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this layering logic is confusing since env vars or config settings can override CLI level cache settings:
e.g. TURBO_FORCE=1 turbo run build --force=false would result in remote:rw,local:rw cache behavior, but TURBO_REMOTE_ONLY=1 turbo run build --cache='local:rw would result in no caches are enabled.

I think it would make more sense to fold the existing cache flags into the new cache struct at each level in the config, but I'm not convinced that wouldn't be confusing. Could we get away with having the new cache struct conflict with existing cache flags at each level e.g turbo run build --remote-only --cache='...' would throw but TURBO_REMOTE_ONLY=1 turbo run build --cache='...' be fine where --cache wins out completely?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to have a group of flags conflict with a single flag but not with each other? I wasn't sure if that's possible in clap. Ofc I can manually add that as a restriction

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The layering issue is a tricky one. If the config specifies remote:rw in a file, but then we add on local:rw, do we want to do an OR or an AND for those? I could see either one working

Copy link
Member

@chris-olszewski chris-olszewski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LFG

#[test_case("local:rx", Err(Error::InvalidCacheAction { c: 'x', text: "local:rx".to_string(), span: Some(SourceSpan::new(6.into(), 5.into())) }) ; "invalid action")]
#[test_case("file:r", Err(Error::InvalidCacheType { s: "file".to_string(), text: "file:r".to_string(), span: Some(SourceSpan::new(0.into(), 4.into())) }) ; "invalid cache type")]
fn test_cache_config(s: &str, expected: Result<CacheConfig, Error>) {
assert_eq!(CacheConfig::from_str(s), expected);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not blocking at all, but it might be nice to snapshot the error messages, easier to update if we change the tests/logic at all. There's a JSON reporter that makes assert_json_snapshot easy to use: https://github.com/vercel/turborepo/blob/main/crates/turborepo-lib/src/engine/builder.rs#L1358

@NicholasLYang NicholasLYang force-pushed the nicholasyang/add-cache-flag branch from 112cc6c to 9be223f Compare November 5, 2024 17:06
@NicholasLYang NicholasLYang merged commit 4cfbc44 into main Nov 5, 2024
39 of 40 checks passed
@NicholasLYang NicholasLYang deleted the nicholasyang/add-cache-flag branch November 5, 2024 18:17
anthonyshew added a commit that referenced this pull request Nov 14, 2024
# DO NOT MERGE CONDITION
2.3 release.

### Description

Documenting #9348 

### Testing Instructions

👀

---------

Co-authored-by: Nicholas Yang <nicholas.yang@vercel.com>
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
area: examples Improvements or additions to examples
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants