name: Deploy Docs

on:
  push:
    branches:
      - main

jobs:
  deploy-docs:
    name: Deploy Docs
    runs-on: ubuntu-latest

    steps:
      - name: Checkout repo
        uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
        with:
          clean: false

      - name: Setup mdBook
        uses: peaceiris/actions-mdbook@ee69d230fe19748b7abf22df32acaa93833fad08 # v2
        with:
          mdbook-version: "0.4.37"

      - name: Build book
        run: |
          set -euo pipefail
          mkdir -p target/deploy
          mdbook build ./docs --dest-dir=../target/deploy/docs/

      - name: Deploy Docs
        uses: cloudflare/wrangler-action@f84a562284fc78278ff9052435d9526f9c718361 # v3
        with:
          apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
          accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
          command: pages deploy target/deploy --project-name=docs

      - name: Deploy Install
        uses: cloudflare/wrangler-action@f84a562284fc78278ff9052435d9526f9c718361 # v3
        with:
          apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
          accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
          command: r2 object put -f script/install.sh zed-open-source-website-assets/install.sh

      - name: Deploy Docs Workers
        uses: cloudflare/wrangler-action@f84a562284fc78278ff9052435d9526f9c718361 # v3
        with:
          apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
          accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
          command: deploy .cloudflare/docs-proxy/src/worker.js

      - name: Deploy Install Workers
        uses: cloudflare/wrangler-action@f84a562284fc78278ff9052435d9526f9c718361 # v3
        with:
          apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
          accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
          command: deploy .cloudflare/docs-proxy/src/worker.js
