Builds and publishes your Storybook to Chromatic and runs visual regression tests.
This is a wrapper for chromatic-cli, which is also where the action's source code resides.
In your git repository, create a file .github/workflows/chromatic.yml
with the following contents:
# .github/workflows/chromatic.yml
# Workflow name
name: 'Chromatic'
# Event for the workflow
on: push
# List of jobs
jobs:
chromatic-deployment:
# Operating System
runs-on: ubuntu-latest
# Job steps
steps:
- uses: actions/checkout@v1
- name: Install dependencies
run: yarn
# 👇 Adds Chromatic as a step in the workflow
- name: Publish to Chromatic
uses: chromaui/action@v1
# Chromatic GitHub Action options
with:
token: ${{ secrets.GITHUB_TOKEN }}
# 👇 Chromatic projectToken, refer to the manage page to obtain it.
projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
Make sure to replace the value of projectToken
with the project token provided to you by Chromatic. You can find it on the Manage page of your Chromatic project. The GitHub token is unrelated and will be set automatically. See below if you want to keep your projectToken secret.
Note: Chromatic requires full git history, so if you are using the
action/checkout@v2
action, ensure you set thefetch-depth: 0
option.
- uses: chromaui/action@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
projectToken: 'Your chromatic project token'
buildScriptName: 'The npm script that builds your Storybook [build-storybook]'
storybookBuildDir: 'Provide a directory with your built storybook; use if you've already built your storybook'
allowConsoleErrors: 'Do not exit when runtime errors occur in storybook'
autoAcceptChanges: 'Automatically accept all changes in chromatic: boolean or branchname'
exitZeroOnChanges: 'Positive exit of action even when there are changes: boolean or branchname'
exitOnceUploaded: 'Exit with 0 once the built version has been sent to chromatic: boolean or branchname'
ignoreLastBuildOnBranch: 'Ignores latest build on target branch as a baseline if branch is no longer present in history (i.e. branch was rebased): branchname'
We suggest you use a secret to hide the project token:
- uses: chromaui/action@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
You can to configure secrets in the repository settings (/<owner>/<repository>/settings/secrets
). However if you need to be able to run this action on pull requests from forks, because those can't access your secret.
Name | Type | Description |
---|---|---|
url |
string | An alias for the build URL (e.g. https://www.chromatic.com/build?appId=<app id goes here>&number=<build number>) |
buildUrl |
string | The build URL (e.g. https://www.chromatic.com/build?appId=<app id goes here>&number=<build number> ) |
storybookUrl |
string | The Storybook preview URL for your current branch / Pull Request (e.g. https://<app id goes here>-<branch hash>.chromatic.com/ ) |
code |
string | The exit code for the current run of the Chromatic CLI |
Version 2 of the actions/checkout
action will only checkout a single commit without history by default. Chromatic needs the full git history in order to track changes over time. Set fetch-depth: 0
to enable this. See actions/checkout for details.
Please report any issues in the chromatic-cli repository. We provide documentation and support chat at https://www.chromatic.com/docs/.