-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
feat: support isSecret in syncEnvVars #4203
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
fcee52f
feat(core): carry secret env vars through build layer and manifest
isshaddad d756d07
feat(build): support isSecret in syncEnvVars
isshaddad dc5511f
feat(cli): import synced secret env vars as secrets
isshaddad 2ce39b2
test(build): cover syncEnvVars isSecret partitioning + docs
isshaddad 7125eda
Merge branch 'main' into feat/sync-env-vars-is-secret-tri-11099
isshaddad 82f01f7
chore: fix formatting in deploy.ts
isshaddad 4dec9f9
fix(cli): make syncEnvVarsWithServer no-op safe for empty input
isshaddad 304d90c
Merge branch 'main' into feat/sync-env-vars-is-secret-tri-11099
isshaddad 0633aae
fix(cli): sync secret env vars on the worker build path too
isshaddad 19b39d3
Merge branch 'main' into feat/sync-env-vars-is-secret-tri-11099
isshaddad d196561
chore: scope syncEnvVars changeset to a build patch
isshaddad e084f22
fix(cli): gate synced parent env vars on branch in worker build path
isshaddad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@trigger.dev/build": patch | ||
| --- | ||
|
|
||
| You can now mark environment variables synced via the `syncEnvVars` build extension as secrets. Return `{ name, value, isSecret: true }` from your callback and those variables are stored redacted in the dashboard, just like manually created secret env vars. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import type { BuildContext, BuildLayer } from "@trigger.dev/core/v3/build"; | ||
| import { syncEnvVars, type SyncEnvVarsFunction } from "./syncEnvVars.js"; | ||
|
|
||
| async function runExtension(fn: SyncEnvVarsFunction): Promise<BuildLayer | undefined> { | ||
| let captured: BuildLayer | undefined; | ||
|
|
||
| const context = { | ||
| target: "deploy", | ||
| config: { project: "proj_test" }, | ||
| logger: { | ||
| spinner: () => ({ stop: () => {} }), | ||
| }, | ||
| addLayer: (layer: BuildLayer) => { | ||
| captured = layer; | ||
| }, | ||
| } as unknown as BuildContext; | ||
|
|
||
| const manifest = { | ||
| deploy: { env: {} }, | ||
| environment: "prod", | ||
| branch: undefined, | ||
| } as any; | ||
|
|
||
| const extension = syncEnvVars(fn); | ||
| await extension.onBuildComplete!(context, manifest); | ||
|
|
||
| return captured; | ||
| } | ||
|
|
||
| describe("syncEnvVars isSecret", () => { | ||
| it("partitions secret and non-secret vars across child and parent", async () => { | ||
| const layer = await runExtension(() => [ | ||
| { name: "PUBLIC_URL", value: "https://example.com" }, | ||
| { name: "API_KEY", value: "secret-key", isSecret: true }, | ||
| { name: "PARENT_PUBLIC", value: "parent", isParentEnv: true }, | ||
| { name: "PARENT_SECRET", value: "parent-secret", isParentEnv: true, isSecret: true }, | ||
| ]); | ||
|
|
||
| expect(layer?.deploy?.env).toEqual({ PUBLIC_URL: "https://example.com" }); | ||
| expect(layer?.deploy?.secretEnv).toEqual({ API_KEY: "secret-key" }); | ||
| expect(layer?.deploy?.parentEnv).toEqual({ PARENT_PUBLIC: "parent" }); | ||
| expect(layer?.deploy?.secretParentEnv).toEqual({ PARENT_SECRET: "parent-secret" }); | ||
| }); | ||
|
|
||
| it("treats the record form as all non-secret", async () => { | ||
| const layer = await runExtension(() => ({ DATABASE_URL: "postgres://..." })); | ||
|
|
||
| expect(layer?.deploy?.env).toEqual({ DATABASE_URL: "postgres://..." }); | ||
| expect(layer?.deploy?.secretEnv).toBeUndefined(); | ||
| expect(layer?.deploy?.secretParentEnv).toBeUndefined(); | ||
| }); | ||
|
|
||
| it("omits secret buckets when no var is marked secret", async () => { | ||
| const layer = await runExtension(() => [{ name: "PUBLIC_URL", value: "https://example.com" }]); | ||
|
|
||
| expect(layer?.deploy?.env).toEqual({ PUBLIC_URL: "https://example.com" }); | ||
| expect(layer?.deploy?.secretEnv).toBeUndefined(); | ||
| expect(layer?.deploy?.secretParentEnv).toBeUndefined(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import { defineConfig } from "vitest/config"; | ||
|
|
||
| export default defineConfig({ | ||
| test: { | ||
| include: ["src/**/*.test.ts"], | ||
| globals: true, | ||
| }, | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.