diff --git a/src/lib/build.ts b/src/lib/build.ts index dafc5d07f2f..975aa107d37 100644 --- a/src/lib/build.ts +++ b/src/lib/build.ts @@ -138,7 +138,7 @@ export const getRunBuildOptions = async ({ defaultConfig, deployHandler, deployId, - options: { context, cwd, debug, dry, json, offline, silent }, + options: { alias, context, cwd, debug, dry, json, offline, silent }, packagePath, skewProtectionToken, token, @@ -186,6 +186,7 @@ export const getRunBuildOptions = async ({ token: token ?? undefined, dry, debug, + branch: alias, context, mode: 'cli', telemetry: false, diff --git a/tests/integration/commands/deploy/deploy.test.ts b/tests/integration/commands/deploy/deploy.test.ts index 553d66cb9aa..1490cf5215c 100644 --- a/tests/integration/commands/deploy/deploy.test.ts +++ b/tests/integration/commands/deploy/deploy.test.ts @@ -1441,6 +1441,48 @@ describe.concurrent('deploy command', () => { }) }) + test('should use alias as the branch for both the deploy request and the build', async (t) => { + await withMockDeploy(async (mockApi) => { + await withSiteBuilder(t, async (builder) => { + builder + .withContentFile({ + path: 'public/index.html', + content: '

test

', + }) + .withNetlifyToml({ + config: { + build: { publish: 'public' }, + plugins: [{ package: './plugins/log-branch' }], + }, + }) + .withBuildPlugin({ + name: 'log-branch', + plugin: { + async onPreBuild() { + console.log(`TEST_BRANCH: ${require('process').env.BRANCH}`) + }, + }, + }) + + await builder.build() + + const output: string = await callCli( + ['deploy', '--alias', 'custom-alias', '--context', 'deploy-preview'], + getCLIOptions({ apiUrl: mockApi.apiUrl, builder }), + ) + + const [, branch] = output.match(/TEST_BRANCH: (.+)/) ?? [] + expect(branch).toBe('custom-alias') + + 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).branch).toBe('custom-alias') + }) + }) + }) + test('should include build_version in deploy body', async (t) => { await withMockDeploy(async (mockApi, deployState) => { await withSiteBuilder(t, async (builder) => {