stages:
  - package
  - compile
  - test
  - build

variables:
  MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository"

cache:
  paths:
    - .m2/repository/
    - "**/target/"

container:
  stage: package
  image: $CI_REGISTRY/ict/images/alpine/ci:latest
  variables:
    BUILDAH_ISOLATION: chroot
    IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
  before_script:
    - apk add buildah fuse-overlayfs
    - buildah login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
    - buildah info
  script:
    - buildah build --tag $IMAGE_TAG -f Dockerfile
    - buildah push $IMAGE_TAG

compile:
  stage: compile
  image: maven:3.8.6-openjdk-18
  script:
    - ./mvnw clean compile

test:
  stage: test
  image: markhobson/maven-chrome:jdk-18
  script:
    - ./mvnw test
  artifacts:
    name: "Surefire test reports from $CI_PROJECT_NAME on $CI_COMMIT_REF_SLUG"
    expire_in: 1 day
    reports:
      junit:
        - "**/target/surefire-reports/TEST-*.xml"

check:
  stage: build
  image: markhobson/maven-chrome:jdk-18
  script:
    - ./mvnw clean compile # dependency-check:aggregate
    - ./mvnw sonar:sonar -Dsonar.projectKey=$SONAR_PROJECT -Dsonar.projectName=$SONAR_PROJECT -Dsonar.host.url=$SONAR_URL -Dsonar.token=$SONAR_TOKEN

build:
  stage: build
  image: maven:3.8.6-openjdk-18
  script:
    - ./mvnw package -DskipTests
  artifacts:
    name: "Maven artifacts from $CI_PROJECT_NAME on $CI_COMMIT_REF_SLUG"
    paths:
      - "**/target/*.jar"
