name: Deploy Web Apps

on:
  push:
    branches: [main, master]
  workflow_dispatch:

jobs:
  deploy:
    runs-on: windows

    defaults:
      run:
        shell: powershell

    steps:
      - name: Checkout
        uses: https://github.com/actions/checkout@v4

      - name: Restore npm cache
        uses: https://github.com/actions/cache@v4
        with:
          path: ~/AppData/Local/npm-cache
          key: npm-windows-${{ hashFiles('package-lock.json', 'website/package-lock.json') }}
          restore-keys: npm-windows-

      - name: Install root dependencies
        env:
          NODE_ENV: development
        run: npm ci

      - name: Install website dependencies
        env:
          NODE_ENV: development
        run: npm ci --prefix website

      - name: Build Toju web app
        run: npm run build

      - name: Build Toju website
        run: |
          Push-Location website
          npm run build
          Pop-Location

      - name: Deploy both apps to IIS
        run: >
          ./tools/deploy-web-apps.ps1
          -WebsitePort 4341
          -AppPort 4492
