name: Publish documentation

on:
  push:
    tags:
      - v[0-9]+.[0-9]+.[0-9]+*

permissions:
    id-token: write
    contents: read

jobs:
  docs:
    runs-on: ubuntu-latest
    environment: docs-publish
    steps:
      - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
      - uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0
        with:
          node-version-file: '.nvmrc'
          cache: 'yarn'
      - name: Install dependencies
        run: yarn --immutable
      - name: Build API documentation
        run: yarn build:docs
      - name: Azure login
        uses: azure/login@a457da9ea143d694b1b9c7c869ebb04ebe844ef5 # v2.3.0
        with:
          client-id: ${{ secrets.AZURE_OIDC_CLIENT_ID }}
          tenant-id: ${{ secrets.AZURE_OIDC_TENANT_ID }}
          subscription-id: ${{ secrets.AZURE_OIDC_SUBSCRIPTION_ID }}
      - name: Upload to Azure Blob Storage
        uses: azure/cli@9f7ce6f37c31b777ec6c6b6d1dfe7db79f497956 # v2.2.0
        with:
          inlineScript: |
            az storage blob upload-batch --account-name ${{ secrets.AZURE_ECOSYSTEM_PACKAGES_STORAGE_ACCOUNT_NAME }} -d '$web/${{ github.event.repository.name }}/${{ github.ref_name }}' -s ./docs --overwrite --auth-mode login
