name: Preview build
run-name: "Preview build - ${{ github.sha }}"

on:
  push:
    branches:
      - "master"
    tags-ignore:
      - "**"
    paths:
      - "pyproject.toml"
      - "uv.lock"
      - "setup.py"
      - "MANIFEST.in"
      - "build_backend/**"
      - "src/**"

jobs:
  trigger:
    name: "Preview build - ${{ github.sha }}"
    if: github.repository == 'streamlink/streamlink'
    runs-on: ubuntu-slim
    steps:
      - name: Windows builds
        run: |
          workflow=streamlink/windows-builds/actions/workflows/preview-build.yml
          html_url=$(curl -sfL \
            -X POST \
            -H 'Accept: application/vnd.github+json' \
            -H 'X-GitHub-Api-Version: 2022-11-28' \
            -H 'Authorization: Bearer ${{ secrets.STREAMLINKBOT_PREVIEW_BUILD }}' \
            -d '{"return_run_details":true,"ref":"master","inputs":{"ref":"${{ github.sha }}"}}' \
            "https://api.github.com/repos/${workflow}/dispatches" \
            | jq -r '.html_url' \
          )
          echo -e "## Windows builds\n\n- ${html_url}\n- https://github.com/${workflow}\n" \
            >> "${GITHUB_STEP_SUMMARY}"
      - name: Linux AppImage
        run: |
          workflow=streamlink/streamlink-appimage/actions/workflows/preview-build.yml
          html_url=$(curl -sfL \
            -X POST \
            -H 'Accept: application/vnd.github+json' \
            -H 'X-GitHub-Api-Version: 2022-11-28' \
            -H 'Authorization: Bearer ${{ secrets.STREAMLINKBOT_PREVIEW_BUILD }}' \
            -d '{"return_run_details":true,"ref":"master","inputs":{"ref":"${{ github.sha }}"}}' \
            "https://api.github.com/repos/${workflow}/dispatches" \
            | jq -r '.html_url' \
          )
          echo -e "## AppImage\n\n- ${html_url}\n- https://github.com/${workflow}\n" \
            >> "${GITHUB_STEP_SUMMARY}"
