#variables:
#  HOMEBREW_NO_AUTO_UPDATE: 1

stages:
  - build
  - build_flatpak
# - test

.macos_saas_runners:
  tags:
    - saas-macos-medium-m1
  image: macos-12-xcode-14
  before_script:
    - echo "started by ${GITLAB_USER_NAME}"

build_macos:
  extends:
    - .macos_saas_runners
  stage: build
  script:
    - echo "place holder for build"
    - sudo softwareupdate --install-rosetta --agree-to-license
    - git clone https://gitlab.com/veilid/veilid.git ../veilid
    #- curl –proto ‘=https’ –tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
    #- source "$HOME/.cargo/env"
    #- brew install capnp cmake wabt llvm protobuf openjdk@17 jq cocoapods
    #- cargo install wasm-bindgen-cli wasm-pack cargo-edit
    - wget https://storage.googleapis.com/flutter_infra_release/releases/stable/macos/flutter_macos_arm64_3.13.5-stable.zip
    - unzip flutter_macos_arm64_3.13.5-stable.zip && export PATH="$PATH:`pwd`/flutter/bin"
    - flutter upgrade
    - yes | flutter doctor --android-licenses
    - flutter config --enable-macos-desktop --enable-ios
    - flutter config --no-analytics
    - dart --disable-analytics
    - flutter doctor -v
    #- flutter build ipa
    #- flutter build appbundle
  when: manual

build_linux_amd64_bundle:
  tags:
    - saas-linux-medium-amd64
  image: ghcr.io/cirruslabs/flutter:3.19.4
  stage: build
  script:
    - apt-get update
    - apt-get install -y --no-install-recommends cmake ninja-build clang build-essential pkg-config libgtk-3-dev liblzma-dev lcov rustc cargo
    - flutter config --enable-linux-desktop
    - git clone https://gitlab.com/veilid/veilid.git ../veilid
    - flutter build linux
  artifacts:
    paths:
      - build/linux/x64/release/bundle/
  when: manual

build_linux_amd64_flatpak:
  tags:
    - saas-linux-small-amd64
  image: ubuntu:23.04
  stage: build_flatpak
  dependencies: [build_linux_amd64_bundle]
  script:
    - apt-get update
    - apt-get install -y --no-install-recommends flatpak flatpak-builder gnupg2 elfutils ca-certificates
    - flatpak remote-add --no-gpg-verify --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
    - flatpak install -y --noninteractive org.gnome.Sdk/x86_64/45  org.gnome.Platform/x86_64/45 app/org.flathub.flatpak-external-data-checker/x86_64/stable org.freedesktop.appstream-glib
    - pushd flatpak/
    - flatpak-builder --force-clean build-dir com.veilid.veilidchat.yml --repo=repo
    - flatpak build-bundle repo com.veilid.veilidchat.flatpak com.veilid.veilidchat
    - popd
  artifacts:
    paths: 
      - flatpak/com.veilid.veilidchat.flatpak
  when: manual

#test:
#  extends:
#    - .macos_saas_runners
#  stage: test
#  script:
#    - echo "place holder for test"
