feat: support NETLIFY_DEPLOY_SOURCE env var#8183
Conversation
📝 WalkthroughSummary by CodeRabbit
WalkthroughThe changes update the deploy creation logic to dynamically determine the Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
📊 Benchmark resultsComparing with 95b5e52
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/commands/deploy/deploy.ts (1)
588-588: Consolidatedeploy_sourceresolution 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
📒 Files selected for processing (2)
src/commands/deploy/deploy.tstests/integration/commands/deploy/deploy.test.ts
| 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') | ||
| }) | ||
| }) | ||
| }) | ||
|
|
There was a problem hiding this comment.
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.
🎉 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 aNETLIFY_DEPLOY_SOURCEenv 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_runnerso 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:
passes our tests.
A picture of a cute animal (not mandatory, but encouraged)