# This file is part of BOINC.
# http://boinc.berkeley.edu
# Copyright (C) 2023 University of California
#
# BOINC is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License
# as published by the Free Software Foundation,
# either version 3 of the License, or (at your option) any later version.
#
# BOINC is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with BOINC.  If not, see <http://www.gnu.org/licenses/>.

name: Flutter-macOS
on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]
  schedule:
    - cron:  '0 0 * * 0'

concurrency:
  group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
  cancel-in-progress: true

jobs:
  build:
    name: ${{ matrix.type }}-flutter-build
    runs-on: macos-latest
    strategy:
      matrix:
        type: [macos, ios]
      fail-fast: false
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 2

      - name: Setup xcode
        uses: maxim-lobanov/setup-xcode@v1
        with:
          xcode-version: '12.5.1'

      - name: Setup flutter
        uses: subosito/flutter-action@v1
        with:
          channel: 'beta'

      - name: Setup macos desktop
        if: matrix.type == 'macos'
        run: flutter config --enable-macos-desktop

      - name: Cache dependencies
        uses: actions/cache@v3
        if: matrix.type == 'macos'
        with:
          path: 3rdParty/buildCache
          key: osx-flutter-${{ hashFiles('3rdParty/*Mac*.sh', 'mac_build/setupForBOINC.sh', 'mac_build/dependencyNames.sh', 'mac_build/[bB]uild*.sh', '.github/workflows/flutter-macos.yml') }}

      - name: Build macos client
        if: matrix.type == 'macos'
        run: samples/flutter/ci_build_macos.sh

      - name: Install flutter dependencies
        run: cd samples/flutter/boinc/ && flutter pub get

      - name: Build macos
        if: matrix.type == 'macos'
        run: |
          cd samples/flutter/
          flutter create boinc
          cd boinc/
          flutter build macos

      - name: Build ios
        if: matrix.type == 'ios'
        run:  |
          cd samples/flutter/
          flutter create boinc
          cd boinc/
          flutter build ios --release --no-codesign
