image: cirrusci/flutter:latest

stages:
  - test
  - update
  - build
  - deploy

tests:
  stage: test
  script:
    - flutter test
  interruptible: true

update:
  stage: update
  script:
    - flutter packages get
    - flutter packages upgrade
  interruptible: true

android:build:
  stage: build
  script:
    # Flutter local configuration
    - echo flutter.sdk=$FLUTTER_PATH > android/local.properties
    - echo sdk.dir=$ANDROID_SDK_PATH >> android/local.properties
    - echo flutter.buildMode=release >> android/local.properties
    # Android signing
    - echo "$ANDROID_KEYSTORE_FILE" | base64 -d > android/app/my.keystore
    - echo storeFile=my.keystore > android/key.properties
    - echo storePassword=$ANDROID_KEYSTORE_PASSWORD >> android/key.properties
    - echo keyAlias=$ANDROID_KEY_ALIAS >> android/key.properties
    - echo keyPassword=$ANDROID_KEY_PASSWORD >> android/key.properties
    # build flutter app
    - flutter build apk
  artifacts:
    paths:
    - build/app/outputs/apk/release
    expire_in: 1 week
  interruptible: true

android:deploy:
  stage: deploy
  only:
    - master
  dependencies:
    - android:build
  script:
    - wget ${REPOSITORY_UPDATE_WEBHOOK}?token=${REPOSITORY_TOKEN}
