Skip to content
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

Add ability to declare a env key in each pipeline task #1932

Conversation

mehulkar
Copy link
Contributor

@mehulkar mehulkar commented Sep 13, 2022

Adds the ability to read environment variable dependencies for each task from an env key. It supports both configs, but logs a deprecation message on the old config, and de-dupes. The de-duping feature also applies duplicate declarations in the existing dependsOn key. (Not sure if this was being de-duped somewhere downstream already)

Coming up after this PR:

  • same ability for global env vars in a separate PR
  • codemod feature for existing config files
  • lint rule for turbo.json having the wrong things?

(See #1929 for some initial refactor work that added a few more test cases if interested!)

@vercel
Copy link

vercel bot commented Sep 13, 2022

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

Name Status Preview Updated
turbo-site ✅ Ready (Inspect) Visit Preview Sep 15, 2022 at 6:17AM (UTC)

@mehulkar mehulkar force-pushed the mehulkar/turbo-225-use-new-env-key-in-turbojson-to-track branch from 9bfc0ed to a765d99 Compare September 13, 2022 00:13
@mehulkar mehulkar force-pushed the mehulkar/turbo-225-use-new-env-key-in-turbojson-to-track branch from 13d57ed to d4c2285 Compare September 13, 2022 00:20
@mehulkar mehulkar force-pushed the mehulkar/turbo-225-use-new-env-key-in-turbojson-to-track branch from d4c2285 to fb3f942 Compare September 13, 2022 00:28
@mehulkar mehulkar force-pushed the mehulkar/turbo-225-use-new-env-key-in-turbojson-to-track branch from 0b192b9 to 90b743f Compare September 13, 2022 01:13
@mehulkar mehulkar marked this pull request as ready for review September 13, 2022 01:13
@mehulkar mehulkar requested a review from a team as a code owner September 13, 2022 01:13
@mehulkar mehulkar force-pushed the mehulkar/turbo-225-use-new-env-key-in-turbojson-to-track branch from 90b743f to 8003fb0 Compare September 13, 2022 01:18
@mehulkar mehulkar force-pushed the mehulkar/turbo-225-use-new-env-key-in-turbojson-to-track branch from 548be53 to 9b4909d Compare September 13, 2022 01:44
@mehulkar
Copy link
Contributor Author

Reverting docs out of here, so we can wait until a release to update the docs. See #1936 for the changes.

Copy link
Contributor

@nathanhammond nathanhammond left a comment

Choose a reason for hiding this comment

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

There is also docs/schema.d.ts which needs to be updated. Was that part reverted out?

cli/internal/fs/testdata/legacy-env/turbo.json Outdated Show resolved Hide resolved
cli/internal/fs/turbo_json.go Outdated Show resolved Hide resolved
@mehulkar
Copy link
Contributor Author

There is also docs/schema.d.ts which needs to be updated. Was that part reverted out?

I moved to #1936 since we don't want to update it until a release! (my understanding is that schema is used only for the $schema field for hints

// Log a warning, because dependsOn accepts `$` prefixed strings to specify
// environment variable dependencies. Because we don't strip out the `$` character
// from the env key, it may be confusing to end users, who are just trying to move it over.
log.Printf("[WARNING] You specified \"%s\" in the \"env\" key. This is treated as a literal, you may want to remove the \"$\".", value)
Copy link
Contributor

Choose a reason for hiding this comment

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

I wouldn't include this warning. In general, people ignore warnings unless something breaks. If something breaks, they'll investigate. When something does break, we don't know that it will be related to this, or any other warning that we might include. In the worst case, we send them on a false trail because whatever broke is unrelated. The best help we can give them is to show what commands were invoked with what inputs. This is where something like a run summary comes into play.

For this warning in particular, users of this API will fall into two camps:

  1. Users coming from the previous behavior of dependsOn.
  2. Users new to turbo who have never seen the previous syntax

We expect going forward that group 2 will be the much larger group. They will have no reason to think they need a $ prefix. In the event of an unlikely subset who do intend to set an environment variable that starts with a $, they will then have a warning they can't get rid of.

Group 1 will have a codemod to move them to the proper syntax.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, if we do end up keeping this warning, we need to thread our cli.Ui instance in here, so that it can respect whatever output is configured. We shouldn't be using log directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, that's fair too. I've removed the warning

Copy link
Contributor

Choose a reason for hiding this comment

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

@gsoltis the issue here is that somebody will add "$FOO" to the env, get no feedback, and just assume that it works.

Later, when their cache isn't segmented, they'll have no idea why and (at this time) have no way to inspect the build to understand what happened.

In other words, failing to use this API correctly will ruin your day. We should aim to reduce the incidence of these types of failure modes which is why I propose automatically removing the $.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reached consensus in slack to throw a hard error for $ prefixed strings

@mehulkar
Copy link
Contributor Author

I tested this locally with my simplest-turbo repo and I'm able to see the error as expected (even with two tasks that may be running in parallel?)

➜  simplest-turbo git:(main) ✗ ./scripts/run
> Keeping cache
> apps/a/package.json description changed from "mydescription-ts1663216545259" to "mydescription-ts1663216569031"
> Building CLI from /Users/mehulkar/dev/vercel-projects/turborepo/cli
> Running turbo run build from /Users/mehulkar/dev/vercel-projects/turborepo/cli/turbo
==========================
 ERROR  run failed: turbo.json: You specified "$A" in the "env" key. This is treated as a literal, you may want to remove the "$"

Copy link
Contributor

@nathanhammond nathanhammond left a comment

Choose a reason for hiding this comment

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

Some proposed verbiage changes.

cli/internal/fs/turbo_json.go Outdated Show resolved Hide resolved
cli/internal/fs/turbo_json.go Outdated Show resolved Hide resolved

_, turboJSONReadErr := ReadTurboConfig(testDir, rootPackageJSON)

expectedErrorMsg := "turbo.json: You specified \"$A\" in the \"env\" key. This is treated as a literal, you may want to remove the \"$\""
Copy link
Contributor

Choose a reason for hiding this comment

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

This is fine for this case but we should (all) start to get into the habit of fmt.Errorf(%w, err) so that we can use error.Is.

@mehulkar mehulkar closed this Sep 15, 2022
@mehulkar mehulkar reopened this Sep 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants