name: Build PicView WPF on Windows

on:
  push:
    branches:
      - dev
  pull_request:
    branches:
      - dev

jobs:
  build:
    runs-on: windows-latest

    steps:
      # Step 1: Checkout the code
      - name: Checkout repository
        uses: actions/checkout@v4

      # Step 2: Setup .NET 9 SDK
      - name: Setup .NET 9 SDK
        uses: actions/setup-dotnet@v4
        with:
          dotnet-version: '9.x'

      # Step 3: Get version from Directory.Build.props using PowerShell
      - name: Get version from Directory.Build.props
        id: get-version
        run: pwsh -File "${{ github.workspace }}/Build/Get-VersionInfo.ps1"
  
      # Step 4 (x64): Publish x64 version self contained
      - name: Publish x64 version
        run: |
          pwsh -File "${{ github.workspace }}\Build\Build WPF.ps1" -Platform "x64" -selfContained true"
        shell: pwsh

      # Step 5 (x64): Upload the x64 zip file as an artifact
      - name: Upload the x64 artifact
        uses: actions/upload-artifact@v4
        with:
          name: PicView-v${{steps.get-version.outputs.version}}-win-x64
          path: ${{ github.workspace }}/Build/PicView-v${{steps.get-version.outputs.version}}-win-x64/
          retention-days: 14

      # Step 6 (x64): Compile .ISS to .EXE Installer for x64
      - name: Compile .ISS to .EXE Installer (x64)
        uses: Minionguyjpro/Inno-Setup-Action@v1.2.5
        with:
          path: .\Build\install.iss
          options: /O+ /DMyAppVersion=${{steps.get-version.outputs.file-version}} /DMyAppOutputDir=${{ github.workspace }}\Build\install /DMyFileSource=${{ github.workspace }}\Build\PicView-v${{steps.get-version.outputs.version}}-win-x64 /DAppIcon=${{ github.workspace }}\src\PicView.WPF\Themes\Resources\img\icon__Q6k_icon.ico /DLicenseFile=${{ github.workspace }}\src\PicView.Core\Licenses\LICENSE.txt /DMyAppOutputName=Setup-PicView-v${{steps.get-version.outputs.version}}-win-x64

      # Step 7 (x64): Upload the Inno Setup Installer for x64 as an artifact
      - name: Upload Inno Setup Installer (x64)
        uses: actions/upload-artifact@v4
        with:
          name: PicView-${{steps.get-version.outputs.version}}-installer-x64
          path: ${{ github.workspace }}\Build\install\Setup-PicView-v${{steps.get-version.outputs.version}}-win-x64.exe
          retention-days: 14

      # Step 8 (arm64): Publish arm64 version
      - name: Publish arm64 version
        run: |
          pwsh -File "${{ github.workspace }}\Build\Build WPF.ps1" -Platform "arm64" -selfContained true"
        shell: pwsh

      # Step 9 (arm64): Upload the arm64 zip file as an artifact
      - name: Upload the arm64 artifact
        uses: actions/upload-artifact@v4
        with:
          name: PicView-v${{steps.get-version.outputs.version}}-win-arm64
          path: ${{ github.workspace }}/Build/PicView-v${{steps.get-version.outputs.version}}-win-arm64/
          retention-days: 14

      # Step 10 (arm64): Compile .ISS to .EXE Installer for arm64
      - name: Compile .ISS to .EXE Installer (arm64)
        uses: Minionguyjpro/Inno-Setup-Action@v1.2.5
        with:
          path: .\Build\install.iss
          options: /O+ /DMyAppVersion=${{steps.get-version.outputs.file-version}} /DMyAppOutputDir=${{ github.workspace }}\Build\install /DMyFileSource=${{ github.workspace }}\Build\PicView-v${{steps.get-version.outputs.version}}-win-arm64 /DAppIcon=${{ github.workspace }}\src\PicView.WPF\Themes\Resources\img\icon__Q6k_icon.ico /DLicenseFile=${{ github.workspace }}\src\PicView.Core\Licenses\LICENSE.txt /DMyAppOutputName=Setup-PicView-v${{steps.get-version.outputs.version}}-win-arm64

      # Step 11 (arm64): Upload the Inno Setup Installer for arm64 as an artifact
      - name: Upload Inno Setup Installer (arm64)
        uses: actions/upload-artifact@v4
        with:
          name: PicView-${{steps.get-version.outputs.version}}-installer-arm64
          path: ${{ github.workspace }}\Build\install\Setup-PicView-v${{steps.get-version.outputs.version}}-win-arm64.exe
          retention-days: 14
