name: Release

on:
  release:
    types: [published]
  workflow_dispatch:

permissions:
  contents: read

env:
  python_version: "3.11"
  rye_version: "0.44.0"

jobs:
  release-pypi:
    name: upload release to PyPI
    runs-on: ubuntu-latest
    environment: PyPI
    steps:
      - uses: actions/checkout@v4
      - name: Set up Python ${{ env.python_version }}
        uses: actions/setup-python@v5
        with:
          python-version: ${{ env.python_version }}
      - name: Set up Rye ${{ env.rye_version }}
        uses: sksat/setup-rye@v0.31.0
        with:
          version: ${{ env.rye_version }}
      - name: Install dependencies with rye
        run: |
          rye sync
      - name: Build
        run: |
          rye build
      - name: Publish package
        uses: pypa/gh-action-pypi-publish@v1.12.4
        with:
          user: __token__
          password: ${{ secrets.PYPI_API_TOKEN }}

  sleep:
    name: sleep (to account for delay in PyPI package availability)
    needs: release-pypi
    runs-on: ubuntu-latest
    steps:
      - run: sleep 120

  aur-update:
    name: publish to AUR
    needs: sleep
    runs-on: ubuntu-latest
    environment: AUR
    concurrency:
      group: "aur"
      cancel-in-progress: true
    steps:
      - uses: actions/checkout@v4
      - uses: loqusion/aur-publish-action@main
        with:
          ssh-private-key: ${{ secrets.AUR_SSH_PRIVATE_KEY }}
          package-name: hyprshade
