image: "k8r.eu/justjanne/android-sdk:27-27.0.3-26.1.1"

variables:
  GRADLE_OPTS: "-Dorg.gradle.daemon=false"

cache:
  key: "$CI_PROJECT_NAME"
  paths:
    - ".gradle/wrapper"
    - ".gradle/caches"

before_script:
  - "export GRADLE_USER_HOME=$(pwd)/.gradle"
  - "export ANDROID_HOME=/android-sdk-linux"
  - "export PATH=$PATH:/android-sdk-linux/platform-tools/"
  - "chmod +x ./gradlew"

  - "echo $SIGNING_KEYSTORE | base64 -d > /root/signing.keystore"
  - "echo $SIGNING_PROPERTIES | base64 -d > signing.properties"

stages:
  - "build"
  - "test"
  - "deploy"

build:
  stage: "build"
  script:
    - "./gradlew assembleRelease"
    - "cp app/build/outputs/apk/release/*.apk ."
  artifacts:
    paths:
      - "*.apk"

unitTests:
  stage: "test"
  cache:
    policy: "pull"
  script:
    - "./gradlew check"

deploy:
  stage: "deploy"
  image: "k8r.eu/justjanne/docker-s3cmd:latest"
  only:
    refs:
    - "master"
    variables:
    - "$S3_CONFIG"
  dependencies:
  - "build"
  script:
  - "echo $S3_CONFIG > $HOME/.s3cfg"
  - "export VERSION=$(ls *.apk)"
  - "s3cmd put $VERSION s3://releases/quasseldroid-ng/$VERSION"
  - "s3cmd cp s3://releases/quasseldroid-ng/$VERSION s3://releases/quasseldroid-ng/Quasseldroid-latest.apk"
