name: Release Workflow

on:
  push:
    tags:
      - 'v*'

permissions:
  contents: write

jobs:
  detect-provider:
    runs-on: ubuntu-latest
    outputs:
      provider: ${{ steps.provider.outputs.provider }}
    steps:
      - name: Determine CI Provider
        id: provider
        shell: bash
        run: |
          if [ -n "${GITEA_ACTIONS}" ] || [ -n "${GITEA_REPOSITORY}" ] || [[ "${RUNNER_NAME}" == *"gitea"* ]]; then
            echo "provider=gitea" >> "$GITHUB_OUTPUT"
          else
            echo "provider=github" >> "$GITHUB_OUTPUT"
          fi

  github-release:
    needs: detect-provider
    permissions:
      contents: write
    if: needs.detect-provider.outputs.provider == 'github'
    uses: ./.github/workflows/github-release.yml
    secrets:
      RELEASE_TOKEN: ${{ secrets.GITHUB_TOKEN }}

  gitea-release:
    needs: detect-provider
    if: needs.detect-provider.outputs.provider == 'gitea'
    uses: ./.github/workflows/gitea-release.yml
    secrets:
      GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}