reactjsgithubgithub-actionschromatic

How to auto accept changes in chromatic github workflow for main branch?


In Chromatic github workflow, how can I accept all changes automatically using the CLI option --auto-accept-changes if the branch is main?

I am using the following github chromatic workflow to deploy the components of my app in chromatic:

# .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.REPO_GITHUB_TOKEN }}
          # 👇 Chromatic projectToken, refer to the manage page to obtain it.
          projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}

The branch detection appears in the docs, but Im not sure how to use it in my yml file, since my action is just yarn.


Solution

  • You have autoAcceptChanges where you can define flag or branch name

    - 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'
    

    so it should be:

    # .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.REPO_GITHUB_TOKEN }}
              # 👇 Chromatic projectToken, refer to the manage page to obtain it.
              projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
              autoAcceptChanges: 'main'