Skip to content

feat!: run build by default before deploy #7195

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
5 changes: 3 additions & 2 deletions docs/commands/deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@ netlify deploy

- `alias` (*string*) - Specifies the alias for deployment, the string at the beginning of the deploy subdomain. Useful for creating predictable deployment URLs. Avoid setting an alias string to the same value as a deployed branch. `alias` doesn’t create a branch deploy and can’t be used in conjunction with the branch subdomain feature. Maximum 37 characters.
- `branch` (*string*) - Serves the same functionality as --alias. Deprecated and will be removed in future versions
- `build` (*boolean*) - Run build command before deploying
- `context` (*string*) - Specify a deploy context for environment variables read during the build (”production”, ”deploy-preview”, ”branch-deploy”, ”dev”) or `branch:your-branch` where `your-branch` is the name of a branch (default: dev)
- `dir` (*string*) - Specify a folder to deploy
- `filter` (*string*) - For monorepos, specify the name of the application to run the command in
- `functions` (*string*) - Specify a functions folder to deploy
- `json` (*boolean*) - Output deployment data as JSON
- `message` (*string*) - A short message to include in the deploy log
- `no-build` (*boolean*) - Do not run build command before deploying. Only use this if you have no need for a build or your site has already been built.
- `prod-if-unlocked` (*boolean*) - Deploy to production if unlocked, create a draft otherwise
- `debug` (*boolean*) - Print debugging information
- `auth` (*string*) - Netlify auth token - can be used to run this command without logging in
Expand All @@ -108,13 +108,14 @@ netlify deploy
```bash
netlify deploy
netlify deploy --site my-first-site
netlify deploy --no-build # Deploy without running a build first
netlify deploy --prod
netlify deploy --prod --open
netlify deploy --prod-if-unlocked
netlify deploy --message "A message with an $ENV_VAR"
netlify deploy --auth $NETLIFY_AUTH_TOKEN
netlify deploy --trigger
netlify deploy --build --context deploy-preview
netlify deploy --context deploy-preview
```


Expand Down
27 changes: 24 additions & 3 deletions src/commands/deploy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { env } from 'process'
import { Option } from 'commander'

import BaseCommand from '../base-command.js'
import { logAndThrowError, warn } from '../../utils/command-helpers.js'
import { chalk, logAndThrowError, warn } from '../../utils/command-helpers.js'
import type { DeployOptionValues } from './option_values.js'

export const createDeployCommand = (program: BaseCommand) =>
Expand Down Expand Up @@ -109,7 +109,19 @@ Support for package.json's main field, and intrinsic index.js entrypoints are co
'build',
),
)
.option('--build', 'Run build command before deploying', false)
.addOption(
new Option('--build', 'Do not use - this is now the default. Will be removed in future versions.')
Copy link
Collaborator

Choose a reason for hiding this comment

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

FWIW I don't think this string can ever be seen

Copy link
Contributor

@sarahetter sarahetter Apr 30, 2025

Choose a reason for hiding this comment

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

Yeah these only get added to generated cli.netlify.com docs

Copy link
Collaborator

Choose a reason for hiding this comment

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

Well, because we have hideHelp() it isn't even included there

.default(true)
.hideHelp(true),
)
/**
* Note that this has special meaning to commander. It negates the above `build` option.
* @see https://github.com/tj/commander.js/tree/83c3f4e391754d2f80b179acc4bccc2d4d0c863d?tab=readme-ov-file#other-option-types-negatable-boolean-and-booleanvalue
*/
.option(
'--no-build',
'Do not run build command before deploying. Only use this if you have no need for a build or your site has already been built.',
)
.option(
'--context <context>',
'Specify a deploy context for environment variables read during the build (”production”, ”deploy-preview”, ”branch-deploy”, ”dev”) or `branch:your-branch` where `your-branch` is the name of a branch (default: dev)',
Expand All @@ -122,15 +134,24 @@ Support for package.json's main field, and intrinsic index.js entrypoints are co
.addExamples([
'netlify deploy',
'netlify deploy --site my-first-site',
'netlify deploy --no-build # Deploy without running a build first',
'netlify deploy --prod',
'netlify deploy --prod --open',
'netlify deploy --prod-if-unlocked',
'netlify deploy --message "A message with an $ENV_VAR"',
'netlify deploy --auth $NETLIFY_AUTH_TOKEN',
'netlify deploy --trigger',
'netlify deploy --build --context deploy-preview',
'netlify deploy --context deploy-preview',
])
.action(async (options: DeployOptionValues, command: BaseCommand) => {
if (options.build && command.getOptionValueSource('build') === 'cli') {
warn(
`${chalk.cyanBright(
'--build',
)} is now the default and can safely be omitted. This will fail in a future version.`,
)
}

if (options.branch) {
warn('--branch flag has been renamed to --alias and will be removed in future versions')
}
Expand Down
Loading
Loading