on:
  push:
    tags:
      - "*"

name: MacOS build and release
jobs:
  macos:
    name: MacOS
    runs-on: macos-latest
    steps:
      - name: Set up Flutter
        uses: subosito/flutter-action@v2
        with:
          cache: true
          flutter-version: "3.24.5"
          channel: "stable"

      - uses: actions/checkout@v4
        with:
          path: "app"

      - name: Cache pub dependencies
        uses: actions/cache@v3
        with:
          path: |
            ${{ env.PUB_CACHE }}
            app/.dart_tool
          key: ${{ runner.os }}-pub-${{ hashFiles('app/**/pubspec.lock') }}
          restore-keys: |
            ${{ runner.os }}-pub-

      - uses: actions/checkout@v4
        with:
          repository: "hmziqrs/keys-n-stuff"
          path: "app/.keys-n-stuff"
          token: ${{ secrets.TOKEN }}

      - name: Execute Keys n Stuff
        run: |
          cd app
          dart ./scripts/keys-n-stuff.dart

      - name: Enable MacOS desktop support
        run: flutter config --enable-macos-desktop

      - name: Install pub dependencies
        run: cd app && flutter pub get

      - name: Activate flutter fire
        run: flutter pub global activate flutterfire_cli

      - run: |
          cd app
          flutter build macos -t lib/main.firebase.dart --release
          cd build/macos/Build/Products/Release
          ditto -c -k --sequesterRsrc --keepParent flutter_uis.app macos-release.zip

      - uses: ncipollo/release-action@v1
        with:
          artifacts: "app/build/macOS/Build/Products/Release/macos-release.zip"
          token: ${{ secrets.TOKEN }}
          allowUpdates: true
