name: CI Website

on:
  push:
    branches: [main]
    paths:
      - 'website/**'
      - 'src/**'
      - 'package.json'
      - 'package-lock.json'
      - '.tool-versions'
      - '.github/workflows/ci-website.yml'
  pull_request:
    branches: [main]
    paths:
      - 'website/**'
      - 'src/**'
      - 'package.json'
      - 'package-lock.json'
      - '.tool-versions'
      - '.github/workflows/ci-website.yml'
  workflow_dispatch:

permissions:
  contents: read

jobs:
  lint-website-client:
    name: Lint Website Client
    runs-on: ubuntu-latest
    timeout-minutes: 10
    steps:
      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
        with:
          persist-credentials: false
      - uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
        with:
          node-version-file: .tool-versions
          cache: npm
      - name: Install website client dependencies
        working-directory: website/client
        run: npm ci
      - name: Lint website client
        working-directory: website/client
        run: node --run lint

  lint-website-server:
    name: Lint Website Server
    runs-on: ubuntu-latest
    timeout-minutes: 10
    steps:
      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
        with:
          persist-credentials: false
      - uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
        with:
          node-version-file: .tool-versions
          cache: npm
      - name: Build and link local repomix
        run: |
          npm ci
          node --run build
          npm link
      - name: Install website server dependencies
        working-directory: website/server
        run: |
          npm ci
          npm link repomix
      - name: Lint website server
        working-directory: website/server
        run: node --run lint

  test-website-server:
    name: Test Website Server
    runs-on: ubuntu-latest
    timeout-minutes: 10
    steps:
      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
        with:
          persist-credentials: false
      - uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
        with:
          node-version-file: .tool-versions
          cache: npm
      - name: Build and link local repomix
        run: |
          npm ci
          node --run build
          npm link
      - name: Install website server dependencies
        working-directory: website/server
        run: |
          npm ci
          npm link repomix
      - name: Test website server
        working-directory: website/server
        run: node --run test

  bundle-website-server:
    name: Bundle Website Server
    runs-on: ubuntu-latest
    timeout-minutes: 10
    steps:
      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
        with:
          persist-credentials: false
      - uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
        with:
          node-version-file: .tool-versions
          cache: npm
      - name: Build and link local repomix
        run: |
          npm ci
          node --run build
          npm link
      - name: Install website server dependencies
        working-directory: website/server
        run: |
          npm ci
          npm link repomix
      - name: Bundle website server
        working-directory: website/server
        run: node --run bundle
