name: deploy docs
on:
  workflow_dispatch:
  push:
    branches:
      - main

permissions:
  contents: write
jobs:
  deploy-docs:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: git config --global user.email "gh@runner.com"
      - run: git config --global user.name "gh-runner"

      - name: Set up Bun
        uses: oven-sh/setup-bun@v2
        with:
          scope: "@silencelaboratories"
          registry-url: "https://registry.npmjs.org"
          bun-version: "latest"

      - name: Install dependencies
        shell: bash
        run: bun install --frozen-lockfile
        env:
          VITE_SILENCE_LABS_NPM_TOKEN: ${{ secrets.VITE_SILENCE_LABS_NPM_TOKEN }}
          BUN_AUTH_TOKEN: ${{ secrets.VITE_SILENCE_LABS_NPM_TOKEN }}

      - name: Build
        shell: bash
        run: bun run build
        env:
          VITE_SILENCE_LABS_NPM_TOKEN: ${{ secrets.VITE_SILENCE_LABS_NPM_TOKEN }}
          BUN_AUTH_TOKEN: ${{ secrets.VITE_SILENCE_LABS_NPM_TOKEN }}

      - name: Set remote url
        run: git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/bcnmy/useAA.git

      - name: Run the tests
        run: bun run docs:deploy

      - name: Deploy 🚀
        uses: JamesIves/github-pages-deploy-action@v4
        with:
          folder: ./docs
