name: 'Build Windows'

on:
  workflow_call:
    secrets:
      CODE_SIGNING_CERTIFICATE:
        required: true
      CODE_SIGNING_PASSWORD:
        required: true
      CODE_SIGNING_PUBLISHER:
        required: true
      CODE_SIGNING_PUBLISHER_NAME:
        required: true

jobs:
  build-app-package:
    name: App Package
    runs-on: windows-latest
    steps:
      - name: Setup Environment
        uses: JagandeepBrar/LunaSea/.github/actions/prepare_for_build@master
        with:
          platform: windows

      - name: Build LunaSea
        run: npm run build:windows

      - name: Prepare Artifact
        run: Compress-Archive -path ${{ github.workspace }}\build\windows\runner\Release\* ${{github.workspace}}\output\lunasea-windows-amd64.zip
      
      - name: Upload Artifact
        uses: actions/upload-artifact@v3
        with:
          name: windows-app-package
          path: ${{ github.workspace }}/output

  build-msix-installer:
    name: MSIX Installer
    runs-on: windows-latest
    steps:
      - name: Setup Environment
        uses: JagandeepBrar/LunaSea/.github/actions/prepare_for_build@master
        with:
          platform: windows
          code-signing-certificate: ${{ secrets.CODE_SIGNING_CERTIFICATE }}

      - name: Build LunaSea
        run: |
          flutter pub run msix:create `
          --certificate-password=${{ secrets.CODE_SIGNING_PASSWORD }} `
          --certificate-path=${{ github.workspace }}/keys/codesigning.pfx `
          --output-path=${{ github.workspace }}/output `
          --publisher=${{ secrets.CODE_SIGNING_PUBLISHER }} `
          --publisher-display-name=${{ secrets.CODE_SIGNING_PUBLISHER_NAME }}

      - name: Upload Artifact
        uses: actions/upload-artifact@v3
        with:
          name: windows-msix-installer
          path: ${{ github.workspace }}/output
