name: .NET MAUI CI/CD

on:
  push:
    branches: [ "main", "develop" ]
  pull_request:
    branches: [ "main", "develop" ]

jobs:
  build:
    runs-on: windows-latest
    
    steps:
    - uses: actions/checkout@v4
      with:
        fetch-depth: 0
    
    - name: Setup .NET
      uses: actions/setup-dotnet@v4
      with:
        dotnet-version: '10.0.x'
    
    - name: Restore dependencies
      run: dotnet restore BookReader.sln
    
    - name: Build
      run: dotnet build BookReader.sln --configuration Release --no-restore
    
    - name: Run Code Analysis
      run: dotnet build BookReader.sln --configuration Release --no-restore /p:RunAnalyzers=true /p:EnforceCodeStyleInBuild=true
    
    - name: Publish APK (Debug)
      if: github.event_name == 'push' && github.ref == 'refs/heads/main'
      run: |
        dotnet publish BookReader/BookReader.csproj -c Release -f net10.0-android --no-restore
    
    - name: Upload APK
      if: github.event_name == 'push' && github.ref == 'refs/heads/main'
      uses: actions/upload-artifact@v4
      with:
        name: app-release
        path: |
          **/bin/**/Release/**/*.apk
