Skip to content

Commit

Permalink
fix: set DEPLOY_ID and DEPLOY_URL env vars once available (#6489)
Browse files Browse the repository at this point in the history
  • Loading branch information
Skn0tt committed Apr 8, 2024
1 parent edbfbb4 commit bc24f77
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/commands/deploy/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,15 @@ const runDeploy = async ({
}: {
functionsFolder?: string
command: BaseCommand
}) => {
}): Promise<{
siteId: string
siteName: string
deployId: string
siteUrl: string
deployUrl: string
logsUrl: string
functionLogsUrl: string
}> => {
let results
let deployId

Expand Down Expand Up @@ -831,7 +839,7 @@ export const deploy = async (options: OptionValues, command: BaseCommand) => {
// @ts-expect-error TS(2339) FIXME: Property 'published_deploy' does not exist on type... Remove this comment to see the full error message
const deployToProduction = options.prod || (options.prodIfUnlocked && !siteData.published_deploy.locked)

let results = {}
let results = {} as Awaited<ReturnType<typeof prepAndRunDeploy>>

if (options.build) {
await handleBuild({
Expand All @@ -853,7 +861,7 @@ export const deploy = async (options: OptionValues, command: BaseCommand) => {
deployToProduction,
})

return {}
return { newEnvChanges: { DEPLOY_ID: results.deployId, DEPLOY_URL: results.deployUrl } }
},
})
} else {
Expand All @@ -880,7 +888,6 @@ export const deploy = async (options: OptionValues, command: BaseCommand) => {
})

if (options.open) {
// @ts-expect-error TS(2339) FIXME: Property 'siteUrl' does not exist on type '{}'.
const urlToOpen = deployToProduction ? results.siteUrl : results.deployUrl
// @ts-expect-error TS(2345) FIXME: Argument of type '{ url: any; }' is not assignable... Remove this comment to see the full error message
await openBrowser({ url: urlToOpen })
Expand Down
16 changes: 16 additions & 0 deletions tests/integration/commands/deploy/deploy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,18 @@ describe.skipIf(process.env.NETLIFY_TEST_DISABLE_LIVE === 'true').concurrent('co
.withNetlifyToml({
config: {
build: { publish: 'public' },
plugins: [{ package: './plugins/log-env' }],
},
})
.withBuildPlugin({
name: 'log-env',
plugin: {
async onSuccess() {
// eslint-disable-next-line n/global-require, no-undef
const { DEPLOY_ID, DEPLOY_URL } = require('process').env
console.log(`DEPLOY_ID: ${DEPLOY_ID}`)
console.log(`DEPLOY_URL: ${DEPLOY_URL}`)
},
},
})

Expand All @@ -232,6 +244,10 @@ describe.skipIf(process.env.NETLIFY_TEST_DISABLE_LIVE === 'true').concurrent('co
})

t.expect(output.includes('Netlify Build completed in')).toBe(true)
const [, deployId] = output.match(/DEPLOY_ID: (\w+)/)
const [, deployURL] = output.match(/DEPLOY_URL: (.+)/)
t.expect(deployId).not.toEqual('0')
t.expect(deployURL).toContain(`https://${deployId}--`)
})
})

Expand Down

2 comments on commit bc24f77

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📊 Benchmark results

  • Dependency count: 1,312
  • Package size: 294 MB
  • Number of ts-expect-error directives: 1,016

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📊 Benchmark results

  • Dependency count: 1,312
  • Package size: 294 MB
  • Number of ts-expect-error directives: 1,016

Please sign in to comment.