name: Build windows zip

on:
  workflow_dispatch:

env:
  FLUTTER_VERSION: "3.13.9"

jobs:
  build:
    runs-on: ubuntu-20.04
    outputs:
      version: ${{ steps.get_version.outputs.version }}

    steps:
      - uses: actions/checkout@v4

      - name: Get version from pubspec.yaml
        id: get_version
        run: |
          VERSION=$(sed -n 's/^version: \([0-9]*\.[0-9]*\.[0-9]*\).*/\1/p' app/pubspec.yaml)
          echo "version=$VERSION" >> $GITHUB_OUTPUT

  build_windows_zip:
    needs: build
    runs-on: windows-latest

    steps:
      - name: Fix long file paths
        run: git config --system core.longpaths true

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

      - uses: subosito/flutter-action@v2
        with:
          flutter-version: ${{ env.FLUTTER_VERSION }}
          channel: "stable"

      - name: Dependencies
        working-directory: app
        run: flutter pub get

      - name: Compile for Windows
        working-directory: app
        run: flutter build windows

      - name: Create empty settings.json
        working-directory: app
        run: echo {} > build/windows/x64/runner/Release/settings.json

      - name: Zip compiled files
        working-directory: app
        run: Compress-Archive -Path build/windows/x64/runner/Release/* -DestinationPath LocalSend.zip

      - name: Upload zip
        uses: actions/upload-artifact@v3
        with:
          name: windows-zip-result
          path: app/LocalSend.zip
