name: 'Test: Visual Storybook'

on:
  schedule:
    - cron: '0 0 * * *'
  workflow_dispatch:
  pull_request:
    branches:
      - master
    paths:
      - 'packages/frontend/@n8n/storybook/**'
      - 'packages/frontend/@n8n/chat/**'
      - 'packages/frontend/@n8n/design-system/**'
      - '.github/workflows/test-visual-storybook.yml'
concurrency:
  group: storybook-${{ github.event.pull_request.number || github.ref }}
  cancel-in-progress: true

jobs:
  cloudflare:
    name: Cloudflare Pages
    if: |
      !contains(github.event.pull_request.labels.*.name, 'community') &&
      github.repository == 'n8n-io/n8n'
    runs-on: blacksmith-2vcpu-ubuntu-2204
    permissions:
      contents: read
      deployments: write
    steps:
      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
        with:
          fetch-depth: 0
      - name: Setup Node.js
        uses: ./.github/actions/setup-nodejs
        with:
          build-command: pnpm run build --filter=@n8n/utils --filter=@n8n/vitest-config --filter=@n8n/design-system

      - name: Build
        working-directory: packages/frontend/@n8n/storybook
        run: |
          pnpm build

      - name: Setup Wrangler Pre-requisites
        run: |
          echo "ignore-workspace-root-check=true" >> .npmrc
          pnpm add --global wrangler

      - name: Deploy
        uses: cloudflare/wrangler-action@da0e0dfe58b7a431659754fdf3f186c529afbe65 # v3.14.1
        id: cloudflare_deployment
        with:
          apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
          accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
          command: pages deploy packages/frontend/@n8n/storybook/storybook-static --project-name=storybook --branch=${{github.ref_name}} --commit-hash=${{ github.sha }}
          gitHubToken: ${{ secrets.GITHUB_TOKEN }}
