Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/commands/deploy/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ const runDeploy = async ({
draft,
branch: alias,
include_upload_url: options.uploadSourceZip,
deploy_source: 'cli',
deploy_source: process.env.NETLIFY_DEPLOY_SOURCE || 'cli',
}

const createDeployResponse = await api.createSiteDeploy({ siteId, title, body: createDeployBody })
Expand Down Expand Up @@ -1363,7 +1363,12 @@ export const deploy = async (options: DeployOptionValues, command: BaseCommand)
}

const draft = options.draft || (!deployToProduction && !alias)
const createDeployBody = { draft, branch: alias, include_upload_url: options.uploadSourceZip, deploy_source: 'cli' }
const createDeployBody = {
draft,
branch: alias,
include_upload_url: options.uploadSourceZip,
deploy_source: process.env.NETLIFY_DEPLOY_SOURCE || 'cli',
}

// TODO: Type this properly in `@netlify/api`.
const deployMetadata = (await api.createSiteDeploy({
Expand Down
28 changes: 28 additions & 0 deletions tests/integration/commands/deploy/deploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1507,6 +1507,34 @@ describe.concurrent('deploy command', () => {
})
})

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')
})
})
})

Comment on lines +1510 to +1537
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.

test('should include build_version in deploy body', async (t) => {
await withMockDeploy(async (mockApi, deployState) => {
await withSiteBuilder(t, async (builder) => {
Expand Down
Loading