name: Build and deploy typedoc

on:
  push:
    branches:
      - master
  pull_request:
    branches: [master]
  workflow_dispatch:

concurrency:
  group: typedoc
  cancel-in-progress: false

jobs:
  build:
    runs-on: node22
    steps:
      - uses: actions/checkout@v4
      - uses: ./.forgejo/actions/init
      - name: Build docs
        run: |
          pnpm run docs
          touch dist/typedoc/.nojekyll
          echo "ref.mtcute.dev" > dist/typedoc/CNAME
          echo "ignore-workspace-root-check=true" >> .npmrc
      - name: Deploy
        # only run on releases
        if: github.event_name == 'push' && github.ref == 'refs/heads/master' && github.actor == 'desu-bot'
        uses: https://github.com/cloudflare/wrangler-action@v3
        with:
          apiToken: ${{ secrets.CLOUDFLARE_PAGES_TOKEN }}
          accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
          command: pages deploy dist/typedoc --project-name=mtcute-apiref
