fix: PR Commenting logic #6
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: 'Chromatic' | |
permissions: | |
contents: read | |
pull-requests: write | |
on: | |
# TODO: Remove the push event before merging this PR | |
push: | |
branches: | |
- storybook | |
workflow_dispatch: | |
pull_request: | |
branches: "*" | |
paths: | |
- "*.stories.*" | |
jobs: | |
chromatic: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Setup Node | |
uses: actions/setup-node@v4 | |
with: | |
node-version: "20.x" | |
cache: "npm" | |
- name: Cache node modules | |
uses: actions/cache@v3 | |
with: | |
path: node_modules | |
key: ${{ runner.os }}-modules-${{ hashFiles('**/package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-modules- | |
- name: Install Dependencies | |
run: npm install | |
- name: Build & Publish Storybook | |
id: publish | |
uses: chromaui/action@v1 | |
with: | |
projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }} | |
token: ${{ secrets.GITHUB_TOKEN }} | |
buildScriptName: "storybook-build" | |
- name: PR Comment | |
if: (github.event_name == 'pull_request' || github.event.number) && steps.publish.outputs.storyBookUrl | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
github.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: `Changes published to Chromatic. Review at: ${steps.publish.outputs.storybookUrl}` | |
}) | |