Skip to content

Commit c08644e

Browse files
feat: set branch as alias on deploy command (#8111)
1 parent e95762d commit c08644e

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

src/lib/build.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ export const getRunBuildOptions = async ({
138138
defaultConfig,
139139
deployHandler,
140140
deployId,
141-
options: { context, cwd, debug, dry, json, offline, silent },
141+
options: { alias, context, cwd, debug, dry, json, offline, silent },
142142
packagePath,
143143
skewProtectionToken,
144144
token,
@@ -186,6 +186,7 @@ export const getRunBuildOptions = async ({
186186
token: token ?? undefined,
187187
dry,
188188
debug,
189+
branch: alias,
189190
context,
190191
mode: 'cli',
191192
telemetry: false,

tests/integration/commands/deploy/deploy.test.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,6 +1441,48 @@ describe.concurrent('deploy command', () => {
14411441
})
14421442
})
14431443

1444+
test('should use alias as the branch for both the deploy request and the build', async (t) => {
1445+
await withMockDeploy(async (mockApi) => {
1446+
await withSiteBuilder(t, async (builder) => {
1447+
builder
1448+
.withContentFile({
1449+
path: 'public/index.html',
1450+
content: '<h1>test</h1>',
1451+
})
1452+
.withNetlifyToml({
1453+
config: {
1454+
build: { publish: 'public' },
1455+
plugins: [{ package: './plugins/log-branch' }],
1456+
},
1457+
})
1458+
.withBuildPlugin({
1459+
name: 'log-branch',
1460+
plugin: {
1461+
async onPreBuild() {
1462+
console.log(`TEST_BRANCH: ${require('process').env.BRANCH}`)
1463+
},
1464+
},
1465+
})
1466+
1467+
await builder.build()
1468+
1469+
const output: string = await callCli(
1470+
['deploy', '--alias', 'custom-alias', '--context', 'deploy-preview'],
1471+
getCLIOptions({ apiUrl: mockApi.apiUrl, builder }),
1472+
)
1473+
1474+
const [, branch] = output.match(/TEST_BRANCH: (.+)/) ?? []
1475+
expect(branch).toBe('custom-alias')
1476+
1477+
const createDeployRequest = mockApi.requests.find(
1478+
(req) => req.method === 'POST' && req.path === '/api/v1/sites/site_id/deploys',
1479+
)
1480+
expect(createDeployRequest).toBeDefined()
1481+
expect((createDeployRequest!.body as Record<string, unknown>).branch).toBe('custom-alias')
1482+
})
1483+
})
1484+
})
1485+
14441486
test('should include build_version in deploy body', async (t) => {
14451487
await withMockDeploy(async (mockApi, deployState) => {
14461488
await withSiteBuilder(t, async (builder) => {

0 commit comments

Comments
 (0)