Skip to content

Automigration: Fail with non-zero exit code on migration failure #31923

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

Conversation

mrginglymus
Copy link
Contributor

@mrginglymus mrginglymus commented Jul 1, 2025

Closes #31919

What I did

Added a --fail option to the automigrate command indicating that any failed migrations should cause a non-zero exit code.

Checklist for Contributors

Testing

The changes in this PR are covered in the following automated tests:

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

Manual testing

This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/lib/cli-storybook/src/sandbox-templates.ts

  • Make sure this PR contains one of the labels below:

    Available labels
    • bug: Internal changes that fixes incorrect behavior.
    • maintenance: User-facing maintenance tasks.
    • dependencies: Upgrading (sometimes downgrading) dependencies.
    • build: Internal-facing build tooling & test updates. Will not show up in release changelog.
    • cleanup: Minor cleanup style change. Will not show up in release changelog.
    • documentation: Documentation only changes. Will not show up in release changelog.
    • feature request: Introducing a new feature.
    • BREAKING CHANGE: Changes that break compatibility in some way with current major version.
    • other: Changes that don't fit in the above categories.

🦋 Canary release

This pull request has been released as version 0.0.0-pr-31923-sha-c04cd64d. Try it out in a new sandbox by running npx [email protected] sandbox or in an existing project with npx [email protected] upgrade.

More information
Published version 0.0.0-pr-31923-sha-c04cd64d
Triggered by @valentinpalkovic
Repository mrginglymus/storybook
Branch fail-on-failed-migrations
Commit c04cd64d
Datetime Mon Jul 7 10:58:08 UTC 2025 (1751885888)
Workflow run 16115065163

To request a new release of this pull request, mention the @storybookjs/core team.

core team members can create a new canary release here or locally with gh workflow run --repo storybookjs/storybook canary-release-pr.yml --field pr=31923

Greptile Summary

Added a new --fail flag to the Storybook CLI's automigrate command that causes non-zero exit codes when migrations fail, enhancing CI/CD pipeline capabilities.

  • Added fail boolean option to AutofixOptionsFromCLI interface in code/lib/cli-storybook/src/automigrate/types.ts
  • Implemented error throwing logic in code/lib/cli-storybook/src/automigrate/index.ts when migrations fail and fail flag is enabled
  • Added new test cases in code/lib/cli-storybook/src/automigrate/index.test.ts to verify both soft and hard failure modes
  • Added --fail (-f) option to CLI interface in code/lib/cli-storybook/src/bin/index.ts

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

4 files reviewed, 1 comment
Edit PR Review Bot Settings | Greptile

Copy link

nx-cloud bot commented Jul 1, 2025

View your CI Pipeline Execution ↗ for commit c04cd64

Command Status Duration Result
nx run-many -t build --parallel=3 ✅ Succeeded 1m 16s View ↗

☁️ Nx Cloud last updated this comment at 2025-07-07 11:16:05 UTC

@mrginglymus mrginglymus force-pushed the fail-on-failed-migrations branch from f4fc217 to 0dac061 Compare July 1, 2025 15:54
@valentinpalkovic
Copy link
Contributor

Hi @mrginglymus

Thank you for your contribution!

For me it makes a ton of sense to return with a non-zero exit code if automigrations are failing while running the automigrate command. Would you agree that when running npx storybook automigrate, the script should return a non-zero exit code by default, and adding a flag isn't strictly necessary?

@storybook-pr-benchmarking
Copy link

storybook-pr-benchmarking bot commented Jul 2, 2025

Package Benchmarks

Commit: c04cd64, ran on 7 July 2025 at 13:09:25 UTC

No significant changes detected, all good. 👏

@mrginglymus
Copy link
Contributor Author

That would be my preference, I was just worried about changing default behaviours.

Presumably no escape-hatch flag needed, unless applied as a general purpose flag to handleCommandFailure

Comment on lines 194 to 196
if (hasFailures) {
throw new Error('Some migrations failed');
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's throw the error at the end of the doAutomigrate function instead, so that the dependencies can still be installed and the doctor command can run. If one automigration fails, it should not necessarily block others. Additionally, the automigrate function can be called programmatically, and it should return the result of each automigration as it does so far. So by moving this piece of code to doAutomigrate, we just influence how the automigrate cli command behaves in the case of an automigration error.

@mrginglymus mrginglymus force-pushed the fail-on-failed-migrations branch from 6aa0dd2 to c04cd64 Compare July 7, 2025 10:52
@valentinpalkovic valentinpalkovic changed the title cli: add option for non-zero exit code on migration failure in automigrate command Automigration: Fail with non-zero exit code on migration failure Jul 7, 2025
Copy link
Contributor

@valentinpalkovic valentinpalkovic left a comment

Choose a reason for hiding this comment

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

LGTM!

@valentinpalkovic valentinpalkovic merged commit 3ac2fec into storybookjs:next Jul 7, 2025
52 of 53 checks passed
@valentinpalkovic valentinpalkovic added the patch:yes Bugfix & documentation PR that need to be picked to main branch label Jul 7, 2025
ghengeveld pushed a commit that referenced this pull request Jul 8, 2025
Automigration: Fail with non-zero exit code on migration failure
(cherry picked from commit 3ac2fec)
@github-actions github-actions bot added the patch:done Patch/release PRs already cherry-picked to main/release branch label Jul 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automigrations bug ci:normal patch:done Patch/release PRs already cherry-picked to main/release branch patch:yes Bugfix & documentation PR that need to be picked to main branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: automigrate exits with 0 code even when migrations fail
2 participants