name: Docs Deploy On Release

on:
  release:
    types: [published, edited, deleted]

permissions:
  actions: write
  contents: read

concurrency:
  group: docs-release-relay-${{ github.event.release.tag_name }}
  cancel-in-progress: true

jobs:
  relay:
    runs-on: ubuntu-latest
    steps:
      - name: Dispatch Docs Deploy on main
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          REPO: ${{ github.repository }}
          TAG: ${{ github.event.release.tag_name }}
          ACTION: ${{ github.event.action }}
        run: |
          set -euo pipefail
          gh api \
            -X POST \
            -H "Accept: application/vnd.github+json" \
            "repos/${REPO}/actions/workflows/docs-deploy.yml/dispatches" \
            -f ref=main \
            -f "inputs[full_reconcile]=false" \
            -f "inputs[release_tag]=${TAG}" \
            -f "inputs[release_action]=${ACTION}"
