image: ghcr.io/cirruslabs/flutter:stable

workflow:
  rules:
    - if: $CI_COMMIT_TAG
    - if: $CI_PIPELINE_SOURCE == "merge_request_event"
    - if: $CI_COMMIT_BRANCH

stages:
  - verify
  - build

variables:
  PUB_CACHE: "$CI_PROJECT_DIR/.pub-cache"

cache:
  key:
    files:
      - pubspec.lock
  paths:
    - .pub-cache/
    - .dart_tool/

before_script:
  - flutter --version
  - flutter pub get

analyze:
  stage: verify
  script:
    - flutter analyze --no-fatal-infos

test:
  stage: verify
  script:
    - flutter test

build_android_apk:
  stage: build
  script:
    - flutter build apk --release
  artifacts:
    when: always
    expire_in: 7 days
    paths:
      - build/app/outputs/flutter-apk/app-release.apk
  rules:
    - if: $CI_COMMIT_TAG
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH

build_android_appbundle:
  stage: build
  script:
    - flutter build appbundle --release
  artifacts:
    when: always
    expire_in: 7 days
    paths:
      - build/app/outputs/bundle/release/app-release.aab
  rules:
    - if: $CI_COMMIT_TAG
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
