name: 'CI Chromatic'

on:
  push:
    branches:
      - main
  pull_request:
    types: [labeled]
jobs:
  chromatic-deployment:
    if: contains(github.event.pull_request.labels.*.name, 'run-chromatic') || github.event_name == 'push'
    runs-on: ubuntu-latest
    env:
      REACT_APP_SERVER_BASE_URL: http://127.0.0.1:3000
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - name: Setup Node.js
        uses: actions/setup-node@v3
        with:
          node-version: "18"
      - name: Front / Write .env
        run: |
          cd front
          touch .env
          echo "REACT_APP_SERVER_BASE_URL: $REACT_APP_SERVER_BASE_URL" >> .env
      - name: Front / Install Dependencies
        run: cd front && yarn
      - name: Publish to Chromatic
        uses: chromaui/action@v1
        with:
          workingDir: ./front
          projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
          onlyChanged: true
          buildScriptName: storybook:build
        