name: Release

on:
  push:
    branches-ignore:
      - "**"
    tags:
      - "**"

jobs:
  build:
    name: Build
    if: github.repository == 'streamlink/streamlink'
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
        with:
          fetch-depth: 300
      - name: Fetch tags
        run: ./.github/workflows/scripts/fetch-tags.sh
      - uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
        with:
          python-version: "3.14"
      - uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39 # v8.2.0
      - name: Build man page
        run: |
          uv run --frozen --group docs make --directory=docs man
      - name: Build shell completions
        run: |
          uv run --frozen --group script ./script/build-shell-completions.py
      - name: Build sdist and wheels
        run: |
          uv run --frozen --group build ./script/build-and-sign.sh
        env:
          SIGNING_KEY_ID: 1AEB6400EDA27DA9
          SIGNING_KEY_PASSPHRASE: ${{ secrets.SIGNING_KEY_PASSPHRASE }}
      - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
        with:
          name: dist
          path: dist/

  deploy:
    name: Deploy
    if: github.repository == 'streamlink/streamlink'
    needs:
      - build
    runs-on: ubuntu-latest
    permissions:
      contents: write
      id-token: write
    steps:
      - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
        with:
          fetch-depth: 300
      - name: Fetch tags
        run: ./.github/workflows/scripts/fetch-tags.sh
      - uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
        with:
          python-version: "3.14"
      - uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39 # v8.2.0
      - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
        with:
          name: dist
          path: dist/
      - name: Github release
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: uv run --frozen --only-group script ./script/github-release.py dist/*.tar.gz{,.asc}
      - name: Delete signatures before deploying to PyPI
        run: rm dist/*.asc
      - name: PyPI release
        uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b # v1.14.0
