new auto-inferred VARLOCK_ENV #285
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR explores the idea of automatically inferring a
VARLOCK_ENVthat tries to just magically be set to the right thing.The intention here is that you can use
# @currentEnv=$VARLOCK_ENVwithout defining it and it will "Just Work".To make this possible, we detect a bunch of known env vars based on various CI/deployment platforms and attempt to normalize them. While these magic vars will always be available, they do not automatically appear in your schema until they are used/references.
The full list of magic vars for now is:
VARLOCK_ENV- development, preview, staging, production, testVARLOCK_IS_CI- true if we are in CIVARLOCK_BRANCH- branch name being tested/deployedVARLOCK_PR_NUMBER- PR number if this is a PR buildVARLOCK_COMMIT_SHA/VARLOCK_COMMIT_SHA- current commit sha long/short versionsVARLOCK_BUILD_URL- url where this will be deployedVARLOCK_REPO- current repo in "owner/repo" format (e.g.,dmno-dev/varlock)VARLOCK_PLATFORM- current platform name (eg, "Github Actions", "Cloudfalre")Not all platforms populate all of these, so we would just populate whatever we can.
You may reference these vars and they will automatically appear in your schema. For others you want added to your schema, but don't necessarily reference anywhere else, we could let you just define them without a value (e.g.,
VARLOCK_BRANCH=).Alternatively, we could have some kind of root decorator that explicitly adds these built-in vars to your schema.
Or a special
infer()function which is only available on these vars. This is clean, although the automatic vars have more than just a value - description, type info, etc...Open to ideas!
One other challenge here is that we may not always be able to infer when
VARLOCK_ENVistest. This is because in some cases the test runner will automatically setNODE_ENV=test(or another similar env var) after varlock already loads the config. For examplevarlock run -- some-test-command .... It depends a bit on your test runner and the integration. For vite/vitest if you use the vite plugin instead ofvarlock run, it should work. The workaround when it cannot be set automatically is to just writeVARLOCK_ENV=test varlock run -- your-test-cmdOf course users can also be more explicit and construct their own env flag too - and we'll add a few more utility functions to make that more clear, especially with multi-line function calls now working.