# SPDX-FileCopyrightText: 2018-2023 Bruce Cowan <bruce@bcowan.me.uk>
#
# SPDX-License-Identifier: GPL-3.0-or-later
flatpak:
  image: alpine:latest
  stage: build
  variables:
    MANIFEST_PATH: "uk.me.bcowan.Rugby.yml"
    RUNTIME_REPO: "https://flathub.org/repo/flathub.flatpakrepo"
    FLATPAK_MODULE: "rugby"
    BUNDLE: "rugby.flatpak"
    APP_ID: "uk.me.bcowan.Rugby"

  script:
  - apk update && apk add flatpak-builder
  - flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
  - flatpak install -y flathub org.gnome.Platform 44
  - flatpak install -y flathub org.gnome.Sdk 44
  - flatpak-builder --stop-at=${FLATPAK_MODULE} app ${MANIFEST_PATH}
  - flatpak build app meson --prefix=/app ${MESON_ARGS} _build
  - flatpak build app ninja -C _build install
  - flatpak-builder --finish-only --repo=repo app ${MANIFEST_PATH}
  - flatpak build-bundle repo ${BUNDLE} --runtime-repo=${RUNTIME_REPO} ${APP_ID}
  artifacts:
    paths:
    - ${BUNDLE}
    - _build/meson-logs/meson-log.txt
  cache:
    paths:
      - .flatpak-builder/cache
