Skip to content

Add sha input parameter to GitHub Action (and respect user-provided CHROMATIC_SHA env var) #1230

@blimmer

Description

@blimmer

Feature request

When using the GitHub Action with pull_request events, users cannot override the commit SHA that Chromatic uses. The action extracts head.sha from the GitHub context and overwrites any user-provided CHROMATIC_SHA environment variable.

This prevents running Chromatic on the pull_request.closed event for merged PRs to establish baselines on main using the merge commit SHA instead of the PR head SHA.

Proposed solution

  1. Add a sha input parameter to the action (similar to the existing branchName input)
  2. Respect user-provided CHROMATIC_SHA environment variable instead of overwriting it

In action-src/main.ts, change:

process.env.CHROMATIC_SHA = sha;
process.env.CHROMATIC_BRANCH = branchName || branch;

To something like:

const shaInput = getInput('sha');
process.env.CHROMATIC_SHA = shaInput || process.env.CHROMATIC_SHA || sha;
process.env.CHROMATIC_BRANCH = branchName || process.env.CHROMATIC_BRANCH || branch;

Alternative solutions

Currently I'm working around this by calling the CLI directly instead of using the action:

- run: |
    npx chromatic \
      --project-token="${{ secrets.CHROMATIC_PROJECT_TOKEN }}" \
      --storybook-build-dir=packages/desktop-app/storybook-static \
      --only-changed \
      ${{ github.event.pull_request.merged && '--auto-accept-changes' || '' }}
  env:
    CHROMATIC_BRANCH: ${{ github.event.pull_request.merged && 'main' || github.event.pull_request.head.ref }}
    CHROMATIC_SHA: ${{ github.event.pull_request.merged && github.event.pull_request.merge_commit_sha || github.event.pull_request.head.sha }}
    CHROMATIC_SLUG: ${{ github.repository }}

This works but loses the convenience of the action's outputs and integration.

Additional context

Related issues:

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions