# Build multi-platform streamd binaries + Android MITM and attach them to a Forgejo release. # # Triggers: # Stable: git tag v1.2.3 && git push origin v1.2.3 # Beta: git tag v1.2.3-beta.1 && git push origin v1.2.3-beta.1 # # Each version tag gets its own release. CI also retargets a rolling channel tag: # vX.Y.Z → release + update `stable` (always-latest download URL) # vX.Y.Z-
    → prerelease + update `beta`  (always-latest beta URL)
#
# Download without pinning a version:
#   .../releases/download/stable/streamd-linux-amd64
#   .../releases/download/beta/streamd-linux-amd64
#
# Requires a Forgejo Actions runner registered against this instance
# (label must match runs-on below — default act_runner often uses "docker").
# See deploy/forgejo/README.md § Actions / releases.

name: release

on:
  push:
    tags:
      - "v*"

jobs:
  build-and-upload:
    runs-on: docker
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Classify tag (stable vs beta)
        id: meta
        run: |
          set -euo pipefail
          TAG="${{ github.ref_name }}"
          # Strict SemVer: v1.2.3 = stable; v1.2.3-beta.1 / -rc.1 / -alpha.1 = beta channel
          if echo "$TAG" | grep -Eq '^v[0-9]+\.[0-9]+\.[0-9]+$'; then
            CHANNEL=stable
            PRERELEASE=false
            TITLE="$TAG"
            NOTES_KIND=stable
          elif echo "$TAG" | grep -Eq '^v[0-9]+\.[0-9]+\.[0-9]+-(beta|rc|alpha)(\.[0-9]+)?$'; then
            CHANNEL=beta
            PRERELEASE=true
            TITLE="$TAG (beta)"
            NOTES_KIND=beta
          else
            echo "Unsupported host tag '$TAG'." >&2
            echo "Use vX.Y.Z for stable or vX.Y.Z-beta.N / -rc.N / -alpha.N for beta." >&2
            exit 1
          fi
          {
            echo "channel=$CHANNEL"
            echo "prerelease=$PRERELEASE"
            echo "title=$TITLE"
            echo "notes_kind=$NOTES_KIND"
          } >> "$GITHUB_OUTPUT"
          echo "tag=$TAG channel=$CHANNEL prerelease=$PRERELEASE"

      - name: Setup Go
        uses: actions/setup-go@v5
        with:
          # apps/proxy/device requires the newer toolchain; apps/cli is fine with it.
          go-version-file: apps/proxy/device/go.mod
          # Forgejo has no Actions cache server; setup-go cache-save hangs without one.
          cache: false

      - name: Build release artifacts
        run: |
          chmod +x scripts/build-release.sh
          ./scripts/build-release.sh "${{ github.ref_name }}"
          ls -la dist/release

      - name: Prepare release notes
        run: |
          set -euo pipefail
          TAG="${{ github.ref_name }}"
          CHANNEL="${{ steps.meta.outputs.channel }}"
          NOTES="docs/releases/${TAG}.md"
          if [ -f "$NOTES" ]; then
            cp "$NOTES" /tmp/release-notes.md
            echo "Using $NOTES"
          else
            cat > /tmp/release-notes.md <\`
          - Beta: \`…/releases/download/beta/\`

          Built with \`CGO_ENABLED=0\` via \`scripts/build-release.sh\`.
          Phone capture still needs Magisk + \`streamd proxy install-ca --reinject\`.
          EOF
            echo "No $NOTES — using generic notes"
          fi
          cat > /tmp/channel-notes.md <