name: Deploy to Pages

on:
  push:
    branches: ['main']
  
  pull_request:
    branches: ['main']
  
  workflow_dispatch:

concurrency:
  group: 'pages'
  cancel-in-progress: false

jobs:
  build:
    runs-on: docker

    steps:
      - uses: actions/checkout@v4

      - name: Setup Node
        uses: actions/setup-node@v4
        with:
          node-version-file: '.nvmrc'
          cache: 'npm'

      - name: Install dependencies
        run: npm ci

      - name: Lint
        run: |
          npm run lint
          npm run typecheck
          npm run qa:no-em-dashes
          npm run qa:spelling
          npm run qa:no-github-links

      - name: Build
        run: npm run build

      - name: QA build
        run: |
          npm run qa:astro-audit
          npm run qa:links
          npm run qa:no-js
          npm run qa:overflow
          npm run qa:preview-cropping

      - name: On main, Copy build to host pages mount
        if: github.event_name == 'push' && github.ref == 'refs/heads/main'
        uses: http://forgejo:3000/andras/ci-actions/deploy-pages@main
        with:
          source: dist
          target: schmelczer-dev

      - name: Copy build to staging pages mount
        if: github.event_name == 'pull_request'
        uses: http://forgejo:3000/andras/ci-actions/deploy-pages@main
        with:
          source: dist
          target: schmelczer-dev-staging
