question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

No environment variables in chromatic github action

See original GitHub issue

Using the github action, I want to disable stories on a global level in .storybook/preview.js with an environment variable. It doesn’t work and, when I render a story with <pre>{JSON.stringify(process.env, null, 4)}</pre>, all I get is:

{
    "NODE_ENV": "production",
    "NODE_PATH": "",
    "STORYBOOK": "true",
    "PUBLIC_URL": "."
}

This must be filtering out environment variables somehow, considering that there is a large list of environment variables that are available in github actions.

Is there a way to not filter these out? Or at least allow me to define some environment variables I want to allow through?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:15 (9 by maintainers)

github_iconTop GitHub Comments

3reactions
phil-rcommented, Feb 15, 2021

I think it’s not a chromatic issue, but storybook’s. Storybook only works with env variables that start with STORYBOOK_

Here is what worked for us, The part of our workflow file(we use secret, not a github action env variable, you’ll need to figure out how to rename it):

   - uses: chromaui/action@v1
        with:
          projectToken: ${{ secrets.CHROMATIC_TOKEN }}
          token: ${{ secrets.GITHUB_TOKEN }}
          exitOnceUploaded: true
        env:
          STORYBOOK_API_URL: ${{ secrets.API_URL }}

and in code we can now access process.env.STORYBOOK_API_URL.

IMHO this should be better documented on chromatic’s side.

2reactions
brett-eastcommented, Mar 2, 2022

Is there not a way that you can allow environment variables that come from ${{ secrets.VAR_NAME }}, like @saiichihashimoto says, trying to chain these environment variables in the code doesn’t make sense at all.

My app shouldn’t need to know anything at all about storybook, and I don’t want any storybook specific code in a component or page.

I would love to be able to specifically and intentionally pass in environment variables into my chromatic.yml file like so:

        env:
          #👇 Sets the environment variable
          SOME_VAR: 'a random string'
          SOME_OTHER_VAR: ${{ secrets.SOME_OTHER_VAR }}

I’m getting storybook errors because I can’t start some parts of the app that require keys, and it doesn’t seem to make any sense to me at all to need to include STORYBOOK_ and check for it anywhere in my code.

For what it’s worth, storybook deploys completely fine from the cli, because it is running though my webpack in the main.ts, but for some reason this isn’t working with the github action.

How can I get an environment variable that isn’t prefixed with STORYBOOK_ into my storybook build, or how can I get the github action to behave like the chromatic cli where I can make the builds work.

Or at the very least what is the expected pattern? Writing something like STORYBOOK_PAYPAL_INIT_KEY, and then using in my codebase, just so that storybook can also use it feels a lot like smelly code.

Am I missing something? Like why does the cli work and the github action doesn’t, when adding my environment variables?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Automate Chromatic with GitHub Actions • Chromatic docs
Environment variables are supported in Chromatic. You can use them to customize your workflow execution or provide project-related variables (e.g., API URLs).
Read more >
Pass environment variables to Github action - Stack Overflow
You'll need to do cat .env >> $GITHUB_ENV (and use actions/checkout ) for each job where you need to access env vars from...
Read more >
Publish Storybook
We recommend Chromatic, a free publishing service made for Storybook that ... Secrets are secure environment variables provided by GitHub so that you...
Read more >
chromatic - npm
Do not run this based on a github pull_request event. ... You can also use the environment variable: CHROMATIC_PROJECT_TOKEN ...
Read more >
Setting up GitHub Actions - Nx
Configuring CI Using GitHub Actions and Nx. The GitHub can track the last successful run on main branch and use this as a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found