Skip to content
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

Prompt to confirm upgrade #11601

Merged
merged 5 commits into from
Dec 27, 2024
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
3 changes: 3 additions & 0 deletions .changesets/11601.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Prompt to confirm upgrade (#11601) by @pantheredeye

A prompt is added to `yarn rw upgrade` to confirm before starting.
4 changes: 3 additions & 1 deletion .github/actions/set-up-test-project/setUpTestProject.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ async function setUpTestProject({ canary }) {

if (canary) {
console.log(`Upgrading project to canary`)
await execInProject('yarn rw upgrade -t canary')
await execInProject('yarn rw upgrade -t canary', {
input: Buffer.from('Y'),
})
console.log()
}

Expand Down
39 changes: 37 additions & 2 deletions packages/cli/src/commands/upgrade.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ export const builder = (yargs) => {
type: 'boolean',
default: true,
})
.option('yes', {
alias: 'y',
describe: 'Skip prompts and use defaults',
default: false,
type: 'boolean',
})
.epilogue(
`Also see the ${terminalLink(
'Redwood CLI Reference for the upgrade command',
Expand Down Expand Up @@ -85,18 +91,47 @@ export const validateTag = (tag) => {
return tag
}

export const handler = async ({ dryRun, tag, verbose, dedupe }) => {
export const handler = async ({ dryRun, tag, verbose, dedupe, yes }) => {
recordTelemetryAttributes({
command: 'upgrade',
dryRun,
tag,
verbose,
dedupe,
yes,
})

// structuring as nested tasks to avoid bug with task.title causing duplicates
const tasks = new Listr(
[
{
title: 'Confirm upgrade',
task: async (ctx, task) => {
if (yes) {
task.skip('Skipping confirmation prompt because of --yes flag.')
return
}

const proceed = await task.prompt({
type: 'Confirm',
message:
'This will upgrade your RedwoodJS project to the latest version. Do you want to proceed?',
initial: 'Y',
default: '(Yes/no)',
format: function (value) {
if (this.state.submitted) {
return this.isTrue(value) ? 'yes' : 'no'
}

return 'Yes'
},
})
if (!proceed) {
task.skip('Upgrade cancelled by user.')
process.exit(0)
}
},
},
{
title: 'Checking latest version',
task: async (ctx) => setLatestVersionToContext(ctx, tag),
Expand Down Expand Up @@ -183,7 +218,7 @@ export const handler = async ({ dryRun, tag, verbose, dedupe }) => {
},
],
{
renderer: verbose && 'verbose',
renderer: verbose ? 'verbose' : 'default',
rendererOptions: { collapseSubtasks: false },
},
)
Expand Down
Loading