image: "openjdk:14"

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

before_script:
  - "mkdir -p $(pwd)/.gradle"
  - "export GRADLE_USER_HOME=$(pwd)/.gradle"
  - "echo $SIGNING_properties | base64 -d > .gradle/gradle.properties"
  - "echo $SIGNING_secretKey | base64 -d > .gradle/sonatype_upload.gpg"
  - "chmod +x ./gradlew"

stages:
  - "test"
  - "release"

test:
  stage: "test"
  script:
    - "./gradlew check --stacktrace"
  artifacts:
    paths:
      - "build/test-results/**/TEST-*.xml"
    reports:
      junit:
        - "build/test-results/**/TEST-*.xml"
  rules:
    - if: "$CI_COMMIT_BRANCH == 'main'"
      when: on_success

release:
  stage: "release"
  cache: {}
  script:
    - "./gradlew publish"
  artifacts:
    paths:
      - "build/libs/*"
  dependencies:
    - "test"
  rules:
    - if: "$CI_COMMIT_TAG != '' && $CI_COMMIT_BRANCH == 'main'"
      when: on_success
