name: Release please

on:
  push:
    branches:
      - main

permissions:
  contents: write
  pull-requests: write

jobs:
  release-please:
    runs-on: ubuntu-latest
    outputs:
      release_created: ${{ steps.release.outputs.release_created }}
      tag_name: ${{ steps.release.outputs.tag_name }}
    steps:
      - uses: actions/create-github-app-token@v3.0.0
        id: app-token
        with:
          app-id: ${{ vars.ORCA_BRO_ID }}
          private-key: ${{ secrets.ORCA_BRO_PRIVATE_KEY }}
      - id: release
        uses: googleapis/release-please-action@v4
        with:
          token: ${{ steps.app-token.outputs.token }}

  pypi:
    needs: release-please
    if: ${{ needs.release-please.outputs.release_created }}
    runs-on: ubuntu-latest
    permissions:
      id-token: write
    environment:
      name: pypi
      url: https://pypi.org/p/antimeridian
    steps:
      - uses: actions/checkout@v6
        with:
          ref: ${{ needs.release-please.outputs.tag_name }}
      - uses: actions/setup-python@v6
        with:
          python-version: "3.x"
      - name: Install build
        run: pip install build
      - name: Build
        run: python -m build
      - uses: pypa/gh-action-pypi-publish@release/v1
