Skip to content

feat(build): add utils.deploy.env.add build plugin API#6918

Open
ndhoule wants to merge 9 commits intomainfrom
nathanhoule/ex-27-add-api-to-netlifybuild-for-registering-deploy-variables
Open

feat(build): add utils.deploy.env.add build plugin API#6918
ndhoule wants to merge 9 commits intomainfrom
nathanhoule/ex-27-add-api-to-netlifybuild-for-registering-deploy-variables

Conversation

@ndhoule
Copy link
Contributor

@ndhoule ndhoule commented Feb 5, 2026

feat(build): add utils.deploy.env.add build plugin API

This changeset adds a new utility to build plugins:
utils.deploy.env.add(). This utility function allows build plugins to
register environment variables at build time that will be injected into
a specific deploy.

Userland build plugins cannot see or manipulate the deploy environment
variables registered by core or other userland plugins.

Deploy-specific environment variables are collected by the build
supervisor process and processed by the deploy step, which sends them to
Buildbot for processing. They are also returned by the programmatic dev
interface; we'll use these returned variables in the CLI, where we'll
e.g. set them on functions.

While I was in here I also converted a few files to TypeScript/generally
did my best to improve the types along the way.

@ndhoule ndhoule force-pushed the nathanhoule/ex-27-add-api-to-netlifybuild-for-registering-deploy-variables branch 2 times, most recently from c9fa671 to acfbc22 Compare February 6, 2026 00:11
@github-actions
Copy link
Contributor

github-actions bot commented Feb 6, 2026

This pull request adds or modifies JavaScript (.js, .cjs, .mjs) files.
Consider converting them to TypeScript.

@ndhoule ndhoule marked this pull request as ready for review February 6, 2026 00:17
@ndhoule ndhoule requested a review from a team as a code owner February 6, 2026 00:17
@ndhoule ndhoule requested a review from eduardoboucas February 6, 2026 00:34
@ndhoule ndhoule force-pushed the nathanhoule/ex-27-add-api-to-netlifybuild-for-registering-deploy-variables branch 4 times, most recently from bd84b54 to 293c047 Compare February 13, 2026 00:41
@ndhoule ndhoule marked this pull request as draft February 13, 2026 00:50
@ndhoule ndhoule force-pushed the nathanhoule/ex-27-add-api-to-netlifybuild-for-registering-deploy-variables branch 3 times, most recently from d0c7d72 to 216b989 Compare February 13, 2026 02:42
@ndhoule ndhoule marked this pull request as ready for review February 13, 2026 02:43
@ndhoule ndhoule force-pushed the nathanhoule/ex-27-add-api-to-netlifybuild-for-registering-deploy-variables branch from 216b989 to 393ffee Compare February 13, 2026 18:28
VitaliyR
VitaliyR previously approved these changes Feb 13, 2026
Copy link
Contributor

@VitaliyR VitaliyR left a comment

Choose a reason for hiding this comment

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

LGTM, minor comment

@ndhoule ndhoule force-pushed the nathanhoule/ex-27-add-api-to-netlifybuild-for-registering-deploy-variables branch from a353bf8 to 44cc578 Compare February 13, 2026 21:13
This changeset adds a new utility to build plugins:
`utils.deploy.env.add()`. This utility function allows build plugins to
register environment variables at build time that will be injected into
a specific deploy.

Userland build plugins cannot see or manipulate the deploy environment
variables registered by core or other userland plugins.

Deploy-specific environment variables are collected by the `build`
supervisor process and processed by the deploy step, which sends them to
Buildbot for processing. They are also returned by the programmatic `dev`
interface; we'll use these returned variables in the CLI, where we'll
e.g. set them on functions.

While I was in here I also converted a few files to TypeScript/generally
did my best to improve the types along the way.
@ndhoule ndhoule force-pushed the nathanhoule/ex-27-add-api-to-netlifybuild-for-registering-deploy-variables branch from 44cc578 to 72209ec Compare February 13, 2026 21:15
@jaredm563
Copy link

jaredm563 commented Feb 13, 2026

last thing i can think of @ndhoule , maybe there is still WIP, i havent been following very much so might not apply.

Here's a little gap I found w the transport logic:

Background:

  1. models.DeployEnvironmentVariable in the open-api package has scopes as a required field

  2. The buildbot test at deploy_server_test.go:239-254 tests scopes e-2-e

  3. the deploy server deserializes and forwards them to SetEnvironment() on the builder.

The gap: in util.ts we calculate normalizedScopes but it stores only { key, value, isSecret } (no scope)

That means buildbot receives env vars without scopes,which is a lil confusing since the Open API model says it's required which leads me to think that vars will get broader exposure than you are intending

Side note; (in the open api enum)
buildbot uses post-processing (kebab)
build uses post_processing (snake)
Can this little difference cause a scope mismatch?

This is required to consume these variables in the CLI.
@ndhoule
Copy link
Contributor Author

ndhoule commented Feb 13, 2026

@jaredm563 Totally correct, just an oversight. Addressed in 97a4d85

@jaredm563
Copy link

Whew! Structure looks great so far! Putting some last thoughts regarding transport flow (in a comment because im being a bum >:)), then I'll let @eduardoboucas give another set of eyes since he's much more familiar than me with this architecture

  1. [Maybe bug] We should double check if let normalizedScopes = new Set(...scopes) behavior is correct. I'm still a little suspicious the Set() primitive will only take in one iterable argument, but we are using spread operator. Tests are passing so maybe this is intended behavior?

smol code example

new Set(...['builds', 'functions'])
// equivalent to: new Set('builds', 'functions')
// 'functions' is ignored → Set { 'b', 'u', 'i', 'l', 'd', 's' }
  1. [Bug] Seems like a little JSON mismatch here, what do you think?

in buildbot_client: environment: { key: string; value: string; isSecret: boolean }[]

But the Go model always expect isSecret

IsSecret bool `json:"is_secret,omitempty"`

So, "isSecret" key -> IsSecret is always false.

  1. [TS Nits] Since we are converting to TS (Thank you for doing this btw @ndhoule ) there are some intermediete types we could add scopes

BuildRequest.environment line 54 needs scopes
deploySiteWithBuildbotClient param line 117 needs scope
CoreStepFunctionArgs.deployEnvVars types.ts:47 needs scopes

@ndhoule
Copy link
Contributor Author

ndhoule commented Feb 13, 2026

@jaredm563 Addressed all those comments. Thanks for the in-depth review!

@ndhoule ndhoule force-pushed the nathanhoule/ex-27-add-api-to-netlifybuild-for-registering-deploy-variables branch from 3dbf57f to 41e6f8f Compare February 14, 2026 00:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants