Skip to content

feat: support NETLIFY_DEPLOY_SOURCE env var#8183

Open
amun-sihra wants to merge 2 commits intomainfrom
EX-2032-deployLabel-cli
Open

feat: support NETLIFY_DEPLOY_SOURCE env var#8183
amun-sihra wants to merge 2 commits intomainfrom
EX-2032-deployLabel-cli

Conversation

@amun-sihra
Copy link
Copy Markdown
Contributor

@amun-sihra amun-sihra commented Apr 21, 2026

🎉 Thanks for submitting a pull request! 🎉

Summary

  • Lets callers that embed the CLI (e.g. the Agent Runner orchestrator) override the hardcoded deploy_source: 'cli' in create-deploy requests by setting a NETLIFY_DEPLOY_SOURCE env var. Default behavior is unchanged — when the var is unset, the CLI still sends 'cli'.

  • This unblocks the orchestrator from tagging AR-originated deploys as agent_runner so the dashboard can show "Last deployed from Agent Runners" instead of "CLI" / "API" on the site overview.

  • Applied to both deploy paths in src/commands/deploy/deploy.ts (build and --no-build), with a new integration test covering the override.

  • Fixes: https://linear.app/netlify/issue/EX-2032/last-deployed-from-ardrop-label-followup

  • https://github.com/netlify/agent-runner-orchestrator/pull/750


For us to review and ship your PR efficiently, please perform the following steps:

  • Open a bug/issue before writing your code 🧑‍💻. This ensures we can discuss the changes and get feedback from everyone that should be involved. If you`re fixing a typo or something that`s on fire 🔥 (e.g. incident related), you can skip this step.
  • Read the contribution guidelines 📖. This ensures your code follows our style guide and
    passes our tests.
  • Update or add tests (if any source code was changed or added) 🧪
  • Update or add documentation (if features were changed or added) 📝
  • Make sure the status checks below are successful ✅

A picture of a cute animal (not mandatory, but encouraged)

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 21, 2026

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Deploy source can now be configured via the NETLIFY_DEPLOY_SOURCE environment variable, defaulting to 'cli' when not set.
  • Tests

    • Added integration test to verify deploy source environment variable configuration.

Walkthrough

The changes update the deploy creation logic to dynamically determine the deploy_source value from an environment variable NETLIFY_DEPLOY_SOURCE with a fallback to 'cli', replacing the previous hardcoded constant. This update is applied to two code paths in the deploy command where deploy payloads are created. An accompanying integration test verifies the new environment variable override behavior while maintaining existing coverage for the default fallback.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding support for a NETLIFY_DEPLOY_SOURCE environment variable to allow dynamic configuration of the deploy_source value.
Description check ✅ Passed The description is well-related to the changeset, explaining the motivation, implementation details across both deploy paths, and the associated test coverage.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch EX-2032-deployLabel-cli

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 21, 2026

📊 Benchmark results

Comparing with 95b5e52

  • Dependency count: 1,061 (no change)
  • Package size: 355 MB (no change)
  • Number of ts-expect-error directives: 356 (no change)

@amun-sihra amun-sihra marked this pull request as ready for review April 21, 2026 20:48
@amun-sihra amun-sihra requested a review from a team as a code owner April 21, 2026 20:48
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/commands/deploy/deploy.ts (1)

588-588: Consolidate deploy_source resolution to avoid drift across deploy paths.

The same env fallback expression is duplicated in both create-deploy branches. Please extract it to a shared helper/constant so future updates can’t diverge.

♻️ Suggested refactor
+const getDeploySource = () => process.env.NETLIFY_DEPLOY_SOURCE || 'cli'
...
-        deploy_source: process.env.NETLIFY_DEPLOY_SOURCE || 'cli',
+        deploy_source: getDeploySource(),
...
-      deploy_source: process.env.NETLIFY_DEPLOY_SOURCE || 'cli',
+      deploy_source: getDeploySource(),

Also applies to: 1366-1371

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/commands/deploy/deploy.ts` at line 588, Extract the duplicated env
fallback for deploy_source into a shared constant or small helper and use that
in both create-deploy branches: replace all uses of
process.env.NETLIFY_DEPLOY_SOURCE || 'cli' with a single exported const or
function (e.g., const DEFAULT_DEPLOY_SOURCE = process.env.NETLIFY_DEPLOY_SOURCE
|| 'cli' or function getDeploySource()) and reference that symbol when building
the deploy payload (where deploy_source is currently assigned) and in the other
create-deploy branch (the block around lines 1366-1371) so both branches resolve
identically from one source of truth.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tests/integration/commands/deploy/deploy.test.ts`:
- Around line 1510-1537: Add a second integration test duplicating the existing
"should honor NETLIFY_DEPLOY_SOURCE env var in create deploy request" but using
the default build workflow (omit the "--no-build" flag) to cover the build-first
path: inside withMockDeploy and withSiteBuilder use builder.withContentFile +
builder.build, call callCli with ['deploy', '--json', '--dir', 'public'] (no
--no-build), pass getCLIOptions with env: { NETLITY_DEPLOY_SOURCE:
'agent_runner' } (match the exact variable NETLIFY_DEPLOY_SOURCE), await
parseDeploy, then find the POST request in mockApi.requests (same predicate) and
assert (createDeployRequest!.body as Record<string, unknown>).deploy_source ===
'agent_runner' to ensure the deploy_source override is honored in the
build-first path.

---

Nitpick comments:
In `@src/commands/deploy/deploy.ts`:
- Line 588: Extract the duplicated env fallback for deploy_source into a shared
constant or small helper and use that in both create-deploy branches: replace
all uses of process.env.NETLIFY_DEPLOY_SOURCE || 'cli' with a single exported
const or function (e.g., const DEFAULT_DEPLOY_SOURCE =
process.env.NETLIFY_DEPLOY_SOURCE || 'cli' or function getDeploySource()) and
reference that symbol when building the deploy payload (where deploy_source is
currently assigned) and in the other create-deploy branch (the block around
lines 1366-1371) so both branches resolve identically from one source of truth.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7851356e-b539-4487-b0e5-0c32a721ab5f

📥 Commits

Reviewing files that changed from the base of the PR and between 95b5e52 and 3a984ab.

📒 Files selected for processing (2)
  • src/commands/deploy/deploy.ts
  • tests/integration/commands/deploy/deploy.test.ts

Comment on lines +1510 to +1537
test('should honor NETLIFY_DEPLOY_SOURCE env var in create deploy request', async (t) => {
await withMockDeploy(async (mockApi) => {
await withSiteBuilder(t, async (builder) => {
builder.withContentFile({
path: 'public/index.html',
content: '<h1>test</h1>',
})

await builder.build()

await callCli(
['deploy', '--json', '--no-build', '--dir', 'public'],
getCLIOptions({
apiUrl: mockApi.apiUrl,
builder,
env: { NETLIFY_DEPLOY_SOURCE: 'agent_runner' },
}),
).then(parseDeploy)

const createDeployRequest = mockApi.requests.find(
(req) => req.method === 'POST' && req.path === '/api/v1/sites/site_id/deploys',
)
expect(createDeployRequest).toBeDefined()
expect((createDeployRequest!.body as Record<string, unknown>).deploy_source).toBe('agent_runner')
})
})
})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Add a build-path variant for NETLIFY_DEPLOY_SOURCE coverage.

This new test covers --no-build, but the same behavior was changed in the build-first path too. Add one integration test using the default build workflow (deploy --json) and assert the same deploy_source override in the create-deploy request.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/integration/commands/deploy/deploy.test.ts` around lines 1510 - 1537,
Add a second integration test duplicating the existing "should honor
NETLIFY_DEPLOY_SOURCE env var in create deploy request" but using the default
build workflow (omit the "--no-build" flag) to cover the build-first path:
inside withMockDeploy and withSiteBuilder use builder.withContentFile +
builder.build, call callCli with ['deploy', '--json', '--dir', 'public'] (no
--no-build), pass getCLIOptions with env: { NETLITY_DEPLOY_SOURCE:
'agent_runner' } (match the exact variable NETLIFY_DEPLOY_SOURCE), await
parseDeploy, then find the POST request in mockApi.requests (same predicate) and
assert (createDeployRequest!.body as Record<string, unknown>).deploy_source ===
'agent_runner' to ensure the deploy_source override is honored in the
build-first path.

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.

1 participant