-
Notifications
You must be signed in to change notification settings - Fork 79
Open
Labels
Description
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
- Add a
shainput parameter to the action (similar to the existingbranchNameinput) - Respect user-provided
CHROMATIC_SHAenvironment 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:
- Honor
--branch-namewhen using GitHub Action and other cases #452 - Honor--branch-namewhen using GitHub Action - Support turbosnap for pull_request workflow trigger #731 - Suggests the action should leverage typical GitHub environment variables instead of directly referencing GitHub event JSON
Reactions are currently unavailable