stages:
  - Gradle Test
  - Documentation
  - Release
  - Build Release

Gradle Test:
  image: griefed/baseimage-ubuntu-jdk-8:2.0.4
  stage: Gradle Test
  services:
    - name: griefed/gitlab-ci-cd:2.0.1
      alias: docker
  variables:
    project_name: $CI_PROJECT_NAME
    SEMANTIC_RELEASE_PACKAGE: $CI_PROJECT_NAME
  before_script:
    - echo "**** Running in $CI_JOB_ID ****"
    - echo "**** Java location ****"
    - which java
    - echo "**** Java version ****"
    - java -version
    - echo "**** Allowing execution of gradlew ****"
    - chmod +x gradlew
    - echo "**** Ensure clean environment ****"
    - ./gradlew about
  script:
    - echo "**** Building ServerPackCreator ****"
    - ./gradlew build --info
  except:
    refs:
      - tags
      - webservice
    variables:
      - $CI_COMMIT_TITLE =~ /^RELEASE:.+$/

Release:
  needs:
    - job: 'Gradle Test'
      artifacts: false
  stage: Release
  image: griefed/gitlab-ci-cd:2.0.1
  services:
    - name: griefed/gitlab-ci-cd:2.0.1
      alias: docker
  variables:
    project_name: $CI_PROJECT_NAME
    SEMANTIC_RELEASE_PACKAGE: $CI_PROJECT_NAME
  script:
    - npx semantic-release
  only:
    - main
  except:
    refs:
      - tags
    variables:
      - $CI_COMMIT_TITLE =~ /^RELEASE:.+$/

pages:
  image: griefed/baseimage-ubuntu-jdk-8:2.0.4
  stage: Documentation
  services:
    - name: griefed/gitlab-ci-cd:2.0.1
      alias: docker
  variables:
    project_name: $CI_PROJECT_NAME
    SEMANTIC_RELEASE_PACKAGE: $CI_PROJECT_NAME
  before_script:
    - which java
    - chmod +x gradlew
    - ./gradlew about
  script:
    - ./gradlew build --info -x test
    - cp -Rf build/docs/javadoc public
    - LC_COLLATE=C ls -ahl --group-directories-first --color=auto
      public
  only:
    - master
    - main
  artifacts:
    paths:
      - public
    expire_in: 1 week