name: '🏗️ Build Plugin'

on:
  push:
    branches:
      - master
    paths-ignore:
      - '**/*.md'
  pull_request:
    branches:
      - master
    paths-ignore:
      - '**/*.md'
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Verify .NET installation
        run: dotnet --version

      - name: Restore dependencies
        run: dotnet restore Jellyfin.Plugin.SRFPlay.sln

      - name: Build solution
        run: dotnet build Jellyfin.Plugin.SRFPlay.sln --configuration Release --no-restore --no-self-contained

      - name: Run tests
        run: dotnet test Jellyfin.Plugin.SRFPlay.sln --no-build --configuration Release --verbosity normal

      - name: Install JPRM
        run: |
          python3 -m venv /tmp/jprm-venv
          /tmp/jprm-venv/bin/pip install jprm

      - name: Build Jellyfin Plugin
        id: jprm
        run: |
          # Create artifacts directory for JPRM output
          mkdir -p artifacts

          # Build plugin using JPRM
          /tmp/jprm-venv/bin/jprm --verbosity=debug plugin build .

          # Find the generated zip file
          ARTIFACT=$(find . -name "*.zip" -type f -print -quit)
          echo "artifact=${ARTIFACT}" >> $GITHUB_OUTPUT
          echo "Found artifact: ${ARTIFACT}"

      - name: Upload build artifact
        uses: actions/upload-artifact@v3
        with:
          name: jellyfin-srfplay-plugin
          path: ${{ steps.jprm.outputs.artifact }}
          retention-days: 30
          if-no-files-found: error
