stages:
  - backend build
  - frontend build
  - backend test
  - frontend test

cache:
  key: ${CI_COMMIT_REF_SLUG}
  paths:
    - .m2/repository/
    - target/
    - .yarn
    - android-sdk/
    - .gradle/wrapper
    - .gradle/caches

variables:
  # Specify the SDK tools version and build tools version to use
  ANDROID_COMPILE_SDK: 31
  ANDROID_BUILD_TOOLS: 31.0.0
  ANDROID_SDK_TOOLS: 7583922
  ANDROID_HOME: "/usr/local/android-sdk"


Prettier check:
  image: node:16.3.0
  stage: backend test
  needs: []
  script:
    - cd backend
    - yarn
    - yarn prettier --check .
  retry: 1

Backend build:
    image: node:16.3.0
    stage: backend test
    needs: []
    script:
        - cd backend
        - yarn
        - yarn tsc

Frontend build:
    image: gradle:7.5.0-jdk11
    stage: backend test
    needs: []
    script:
        # Restore Android SDK from cache
    - if [ -d android-sdk ]; then mv android-sdk/* $ANDROID_HOME/; fi
    # Download and install Android SDK
    - wget --quiet --output-document=android-sdk.zip https://dl.google.com/android/repository/commandlinetools-linux-${ANDROID_SDK_TOOLS}_latest.zip
    - unzip -q android-sdk.zip -d android-sdk
    - echo y | android-sdk/cmdline-tools/bin/sdkmanager --sdk_root=$ANDROID_HOME "platforms;android-${ANDROID_COMPILE_SDK}" "build-tools;${ANDROID_BUILD_TOOLS}"
    - cd frontend
    - ./gradlew clean
    - ./gradlew build --refresh-dependencies
    - gradle build
