name: Check

on:
  push:
    branches:
      - 'master'
  pull_request:
    branches:
      - '**'

jobs:
  check:
    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [24.x]

    env:
      VITE_BEE_HOST: https://api.test-node.staging.ethswarm.org/
      VITE_FORMBRICKS_ENV_ID: ${{ secrets.VITE_FORMBRICKS_ENV_ID }}
      VITE_FORMBRICKS_APP_URL: ${{ secrets.VITE_FORMBRICKS_APP_URL }}

    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - uses: pnpm/action-setup@v4
        with:
          version: 10
      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v4
        with:
          node-version: ${{ matrix.node-version }}

      - name: Setup pnpm cache
        uses: actions/cache@v3
        with:
          path: ~/.pnpm-store
          key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }}
          restore-keys: |
            ${{ runner.os }}-pnpm-

      - name: Install dependencies
        run: pnpm install --frozen-lockfile

      - name: Commit linting
        uses: wagoid/commitlint-github-action@v6
        with:
          configFile: ./commitlint.config.cjs

      - name: Code linting
        run: pnpm run lint
        env:
          CI: true

      - name: Dependency check
        run: pnpm run depcheck

      - name: Types check
        run: pnpm run check:types

      - name: Build
        run: pnpm run build

      - name: Build Component
        run: pnpm run build:component

      - name: Create preview
        uses: ethersphere/swarm-actions/pr-preview@v1
        continue-on-error: true
        with:
          bee-url: https://unlimited.gateway.ethswarm.org
          token: ${{ secrets.GHA_PAT_BASIC }}
          error-document: index.html
          headers: '${{ secrets.GATEWAY_AUTHORIZATION_HEADER }}'

      - name: Upload to testnet
        uses: ethersphere/swarm-actions/upload-dir@v1
        continue-on-error: true
        with:
          index-document: index.html
          error-document: index.html
          dir: ./build
          bee-url: https://api.gateway.testnet.ethswarm.org
