-
Notifications
You must be signed in to change notification settings - Fork 443
feat: add netlify push for git-based deploys via Netlify-hosted git
#7949
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| --- | ||
| title: Netlify CLI push command | ||
| sidebar: | ||
| label: push | ||
| description: Push code to Netlify via git, triggering a build | ||
| --- | ||
|
|
||
| # `push` | ||
|
|
||
| <!-- AUTO-GENERATED-CONTENT:START (GENERATE_COMMANDS_DOCS) --> | ||
| Push code to Netlify via git, triggering a build | ||
|
|
||
| **Usage** | ||
|
|
||
| ```bash | ||
| netlify push | ||
| ``` | ||
|
|
||
| **Flags** | ||
|
|
||
| - `filter` (*string*) - For monorepos, specify the name of the application to run the command in | ||
| - `message` (*string*) - Commit message | ||
| - `debug` (*boolean*) - Print debugging information | ||
| - `auth` (*string*) - Netlify auth token - can be used to run this command without logging in | ||
|
|
||
| **Examples** | ||
|
|
||
| ```bash | ||
| netlify push | ||
| netlify push -m "Add contact form" | ||
| ``` | ||
|
|
||
|
|
||
| <!-- AUTO-GENERATED-CONTENT:END --> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import process from 'process' | ||
|
|
||
| import type BaseCommand from '../base-command.js' | ||
|
|
||
| const readStdin = (): Promise<string> => | ||
| new Promise((resolve) => { | ||
| let data = '' | ||
| process.stdin.setEncoding('utf8') | ||
| process.stdin.on('data', (chunk: string) => { | ||
| data += chunk | ||
| }) | ||
| process.stdin.on('end', () => { | ||
| resolve(data) | ||
| }) | ||
| // If stdin isn't being piped, resolve after a short timeout | ||
| if (process.stdin.isTTY) { | ||
| resolve(data) | ||
| } | ||
| }) | ||
|
|
||
| export const gitCredentials = async (command: BaseCommand) => { | ||
| const input = await readStdin() | ||
|
|
||
| // Only respond to "get" requests from the git credential protocol | ||
| if (!input.includes('protocol=') && !input.startsWith('get')) { | ||
| return | ||
| } | ||
|
|
||
| const token = command.netlify.api.accessToken | ||
| if (!token) { | ||
| throw new Error('No access token found. Please run `netlify login` first.') | ||
| } | ||
|
|
||
| // Output in git credential helper format | ||
| process.stdout.write(`username=x-access-token\npassword=${token}\n`) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import BaseCommand from '../base-command.js' | ||
|
|
||
| export const createGitCredentialsCommand = (program: BaseCommand) => | ||
| program | ||
| .command('git-credentials', { hidden: true }) | ||
| .description('Git credential helper for Netlify-hosted repos') | ||
| .action(async (_options, command: BaseCommand) => { | ||
| const { gitCredentials } = await import('./git-credentials.js') | ||
| await gitCredentials(command) | ||
| }) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import type { OptionValues } from 'commander' | ||
|
|
||
| import BaseCommand from '../base-command.js' | ||
|
|
||
| export const createPushCommand = (program: BaseCommand) => | ||
| program | ||
| .command('push') | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TBD: what should this be called? should this even be separate from |
||
| .description('Push code to Netlify via git, triggering a build') | ||
| .option('-m, --message <message>', 'Commit message') | ||
| .addExamples(['netlify push', 'netlify push -m "Add contact form"']) | ||
| .action(async (options: OptionValues, command: BaseCommand) => { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixme: use the good pattern for typing |
||
| const { push } = await import('./push.js') | ||
| await push(options, command) | ||
| }) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBD: what should this be called? Confusingly,
--manualalready exists and means something completely unrelated to "manual deploys".Should this even be opt-in (eventually)?