name: 🆙 Release

concurrency: release

on:
  push:
    branches:
      - main

permissions:
  contents: read

jobs:
  check-release:
    name: Check for release
    runs-on: ubuntu-latest
    environment: release
    permissions:
      contents: read
    outputs:
      has_release: ${{ steps.check.outputs.has-release }}

    steps:
      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
        with:
          token: ${{ secrets.BOT_TOKEN }}

      - name: Check for release
        id: check
        uses: autopub/autopub-action@5fdc82e84c048a82303de6b5c5a9d027665e73cf # v1.1.1
        with:
          command: check
          autopub-version: "1.0.0a58"
          github-token: ${{ secrets.BOT_TOKEN }}
          extra-plugins: strawberry-autopub-plugins

  publish:
    name: Publish to PyPI
    needs: check-release
    if: ${{ needs.check-release.outputs.has_release == 'true' }}
    runs-on: ubuntu-latest
    environment: release
    permissions:
      contents: write
      id-token: write

    steps:
      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
        with:
          token: ${{ secrets.BOT_TOKEN }}

      - name: Prepare release
        uses: autopub/autopub-action@5fdc82e84c048a82303de6b5c5a9d027665e73cf # v1.1.1
        with:
          command: prepare
          autopub-version: "1.0.0a58"
          extra-plugins: strawberry-autopub-plugins

      - name: Build package
        uses: autopub/autopub-action@5fdc82e84c048a82303de6b5c5a9d027665e73cf # v1.1.1
        with:
          command: build
          autopub-version: "1.0.0a58"
          extra-plugins: strawberry-autopub-plugins

      - name: Publish to PyPI
        uses: autopub/autopub-action@5fdc82e84c048a82303de6b5c5a9d027665e73cf # v1.1.1
        with:
          command: publish
          autopub-version: "1.0.0a58"
          extra-plugins: strawberry-autopub-plugins
          github-token: ${{ secrets.BOT_TOKEN }}
          git-username: botberry
          git-email: bot@strawberry.rocks
        env:
          UV_PUBLISH_TOKEN: ${{ secrets.PYPI_TOKEN }}
          TYPEFULLY_API_KEY: ${{ secrets.TYPEFULLY_API_KEY }}
          TYPEFULLY_SOCIAL_SET_ID: ${{ secrets.TYPEFULLY_SOCIAL_SET_ID }}
