Skip to content

Commit 9290728

Browse files
authored
feat: support NETLIFY_DEPLOY_SOURCE env var (#8183)
πŸŽ‰ 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 - netlify/agent-runner-orchestrator#750 <!-- Explain the **motivation** for making this change. What existing problem does the pull request solve and how? --> --- For us to review and ship your PR efficiently, please perform the following steps: - [ ] Open a [bug/issue](https://github.com/netlify/cli/issues/new/choose) 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](../CONTRIBUTING.md) πŸ“–. 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)**
1 parent 32a18d6 commit 9290728

2 files changed

Lines changed: 35 additions & 2 deletions

File tree

β€Žsrc/commands/deploy/deploy.tsβ€Ž

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ const runDeploy = async ({
585585
draft,
586586
branch: alias,
587587
include_upload_url: options.uploadSourceZip,
588-
deploy_source: 'cli',
588+
deploy_source: process.env.NETLIFY_DEPLOY_SOURCE || 'cli',
589589
}
590590

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

13651365
const draft = options.draft || (!deployToProduction && !alias)
1366-
const createDeployBody = { draft, branch: alias, include_upload_url: options.uploadSourceZip, deploy_source: 'cli' }
1366+
const createDeployBody = {
1367+
draft,
1368+
branch: alias,
1369+
include_upload_url: options.uploadSourceZip,
1370+
deploy_source: process.env.NETLIFY_DEPLOY_SOURCE || 'cli',
1371+
}
13671372

13681373
// TODO: Type this properly in `@netlify/api`.
13691374
const deployMetadata = (await api.createSiteDeploy({

β€Žtests/integration/commands/deploy/deploy.test.tsβ€Ž

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,6 +1507,34 @@ describe.concurrent('deploy command', () => {
15071507
})
15081508
})
15091509

1510+
test('should honor NETLIFY_DEPLOY_SOURCE env var in create deploy request', async (t) => {
1511+
await withMockDeploy(async (mockApi) => {
1512+
await withSiteBuilder(t, async (builder) => {
1513+
builder.withContentFile({
1514+
path: 'public/index.html',
1515+
content: '<h1>test</h1>',
1516+
})
1517+
1518+
await builder.build()
1519+
1520+
await callCli(
1521+
['deploy', '--json', '--no-build', '--dir', 'public'],
1522+
getCLIOptions({
1523+
apiUrl: mockApi.apiUrl,
1524+
builder,
1525+
env: { NETLIFY_DEPLOY_SOURCE: 'agent_runner' },
1526+
}),
1527+
).then(parseDeploy)
1528+
1529+
const createDeployRequest = mockApi.requests.find(
1530+
(req) => req.method === 'POST' && req.path === '/api/v1/sites/site_id/deploys',
1531+
)
1532+
expect(createDeployRequest).toBeDefined()
1533+
expect((createDeployRequest!.body as Record<string, unknown>).deploy_source).toBe('agent_runner')
1534+
})
1535+
})
1536+
})
1537+
15101538
test('should include build_version in deploy body', async (t) => {
15111539
await withMockDeploy(async (mockApi, deployState) => {
15121540
await withSiteBuilder(t, async (builder) => {

0 commit comments

Comments
Β (0)