name: Publish docs

on:
  push:
    branches:
      - master

jobs:
  build:
    name: Build
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v3

      - uses: pnpm/action-setup@v3
        with:
          version: 8

      - name: Install Node.js
        uses: actions/setup-node@v4
        with:
          node-version: 20
          cache: "pnpm"

      - name: Install packages
        working-directory: ./.docs
        run: pnpm install

      - name: Build project
        working-directory: ./.docs
        run: pnpm run generate
        env:
          NUXT_APP_BASE_URL: /providers/

      - name: Upload production-ready build files
        uses: actions/upload-pages-artifact@v1
        with:
          path: ./.docs/.output/public

  deploy:
    name: Deploy
    needs: build
    permissions:
      pages: write
      id-token: write
    environment:
      name: docs
      url: ${{ steps.deployment.outputs.page_url }}
    runs-on: ubuntu-latest
    steps:
      - name: Deploy to GitHub Pages
        id: deployment
        uses: actions/deploy-pages@v2
