name: '🧪 Test Plugin'

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

jobs:
  test:
    runs-on: linux/amd64
    container:
      image: gitea.tourolle.paris/dtourolle/srfplay-builder:latest

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          path: test-${{ github.run_id }}

      - name: Restore dependencies
        working-directory: test-${{ github.run_id }}
        run: dotnet restore Jellyfin.Plugin.SRFPlay.sln

      - name: Build solution
        working-directory: test-${{ github.run_id }}
        run: dotnet build Jellyfin.Plugin.SRFPlay.sln --configuration Debug --no-restore --no-self-contained /m:1

      - name: Run tests
        working-directory: test-${{ github.run_id }}
        run: dotnet test Jellyfin.Plugin.SRFPlay.sln --no-build --configuration Debug --verbosity normal --logger "trx;LogFileName=test-results.trx"

      - name: Upload test results
        if: always()
        uses: actions/upload-artifact@v3
        with:
          name: test-results
          path: test-${{ github.run_id }}/**/test-results.trx
          retention-days: 7

      - name: Cleanup
        if: always()
        run: rm -rf test-${{ github.run_id }}
