Skip to content

CLI: Fix throwing in readonly environments #31785

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

Open
wants to merge 2 commits into
base: next
Choose a base branch
from

Conversation

JReinhold
Copy link
Contributor

@JReinhold JReinhold commented Jun 16, 2025

Closes #31709

What I did

  1. Changed the global settings logic to only log a warning if it can't save the file, instead of throwing an error
  2. Don't run global settings logic in CI
  3. Added a utility to more resiliently check for optional, boolean environment variables, and a shortcut isCI that uses that.

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 PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the @storybookjs/core team here.

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

Greptile Summary

Modified global settings handling to prevent failures in read-only environments like CI systems by replacing error throwing with warning logs.

  • Removed SavingGlobalSettingsFileError from code/core/src/server-errors.ts
  • Added CI environment detection to skip global settings in code/core/src/telemetry/storybook-metadata.ts
  • Updated code/core/src/cli/globalSettings.ts to log warnings instead of throwing errors on save failures
  • Modified test cases in code/core/src/cli/globalSettings.test.ts to verify new warning behavior

@JReinhold JReinhold requested review from tmeasday and shilman June 16, 2025 08:33
@JReinhold JReinhold self-assigned this Jun 16, 2025
@JReinhold JReinhold added bug ci: do not merge cli telemetry ci:normal patch:yes Bugfix & documentation PR that need to be picked to main branch and removed ci: do not merge labels Jun 16, 2025
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.

LGTM

4 files reviewed, no comments
Edit PR Review Bot Settings | Greptile

Copy link

nx-cloud bot commented Jun 16, 2025

View your CI Pipeline Execution ↗ for commit c458370.

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

☁️ Nx Cloud last updated this comment at 2025-06-18 07:26:31 UTC

@@ -57,10 +57,10 @@ export const computeStorybookMetadata = async ({
mainConfig?: StorybookConfig & Record<string, any>;
configDir: string;
}): Promise<StorybookMetadata> => {
const settings = await globalSettings();
const settings = process.env.CI === 'true' ? undefined : await globalSettings();
Copy link
Member

Choose a reason for hiding this comment

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

Seeing several different usages of process.env.CI in the codebase. This one seems like the safest to me:

inCI: Boolean(process.env.CI),

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Boolean('false') returns true, seems pretty bad to me.

Ie. CI=false storybook dev would make that thing become true.

Although process.env.CI === 'true' wouldn't support CI=1, but I'm not sure how many use that.

Copy link
Member

Choose a reason for hiding this comment

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

Should we use this

const optionalEnvToBoolean = (input: string | undefined): boolean | undefined => {
if (input === undefined) {
return undefined;
}
if (input.toUpperCase() === 'FALSE') {
return false;
}
if (input.toUpperCase() === 'TRUE') {
return true;
}
if (typeof input === 'string') {
return true;
}
return undefined;
};

Copy link
Member

Choose a reason for hiding this comment

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

Slight detour but can we also fix that across the codebase? If Boolean('false') returns true that's a bug. And there's a ton of other places that just refer to process.env.CI directly.

Copy link
Contributor Author

@JReinhold JReinhold Jun 18, 2025

Choose a reason for hiding this comment

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

alright, I refactored it to export a utility from storybook/internal/common and used that everywhere we were reading a boolean env. please re-review @shilman or @tmeasday.

Copy link
Member

@shilman shilman left a comment

Choose a reason for hiding this comment

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

Looks good with one minor nit

@storybook-pr-benchmarking
Copy link

Package Benchmarks

Commit: c458370, ran on 18 June 2025 at 07:31:55 UTC

The following packages have significant changes to their size or dependencies:

storybook

Before After Difference
Dependency count 49 49 0
Self size 31.87 MB 31.90 MB 🚨 +30 KB 🚨
Dependency size 17.41 MB 17.41 MB 0 B
Bundle Size Analyzer Link Link

@storybook/nextjs

Before After Difference
Dependency count 531 531 0
Self size 902 KB 217 KB 🎉 -686 KB 🎉
Dependency size 58.92 MB 58.92 MB 🎉 -172 B 🎉
Bundle Size Analyzer Link Link

@storybook/nextjs-vite

Before After Difference
Dependency count 131 131 0
Self size 3.07 MB 2.39 MB 🎉 -685 KB 🎉
Dependency size 22.30 MB 22.30 MB 🎉 -500 B 🎉
Bundle Size Analyzer Link Link

sb

Before After Difference
Dependency count 50 50 0
Self size 1 KB 1 KB 0 B
Dependency size 49.27 MB 49.30 MB 🚨 +30 KB 🚨
Bundle Size Analyzer Link Link

@storybook/cli

Before After Difference
Dependency count 216 216 0
Self size 582 KB 582 KB 🎉 -39 B 🎉
Dependency size 94.59 MB 94.64 MB 🚨 +47 KB 🚨
Bundle Size Analyzer Link Link

@storybook/codemod

Before After Difference
Dependency count 185 185 0
Self size 31 KB 31 KB 0 B
Dependency size 78.72 MB 78.75 MB 🚨 +30 KB 🚨
Bundle Size Analyzer Link Link

create-storybook

Before After Difference
Dependency count 1 1 0
Self size 12.47 MB 12.49 MB 🚨 +16 KB 🚨
Dependency size 98 KB 98 KB 0 B
Bundle Size Analyzer Link Link

Copy link
Member

@tmeasday tmeasday left a comment

Choose a reason for hiding this comment

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

I have a couple questions but looks good otherwise, good improvement.

Comment on lines +78 to +80
if (input.toUpperCase() === 'TRUE' || input === '1') {
return true;
}
Copy link
Member

Choose a reason for hiding this comment

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

This is redundant right.. do we think it's better for brevity? Should this function be unit tested?

* Doing Boolean(process.env.CI) or !process.env.CI is not enough, because users might set CI=false
* or CI=0, which would be truthy, and thus return true in those cases.
*/
export const isCI = optionalEnvToBoolean(process.env.CI);
Copy link
Member

Choose a reason for hiding this comment

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

Is it OK for this file to read process.env? It's never used in a scenario where one of those might be undefined?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug ci:normal cli patch:yes Bugfix & documentation PR that need to be picked to main branch telemetry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: SB_CORE-SERVER_0001 on read-only file system
3 participants