image: git.fortiss.org:5001/diewald/maven-releng:latest

stages:
  - build
  - test
  - deploy

variables:
  # recursive should work here, but gitlab-runner does not pull the latest remote
  # for submodules: https://gitlab.com/gitlab-org/gitlab-runner/issues/3011
  GIT_SUBMODULE_STRATEGY: none
  GIT_SUBMODULE_OPTS: "--remote --recursive --init --recommend-shallow"
  MAVEN_CLI_OPTS: "--batch-mode"
  MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository"
  MAVEN_BUILD_OPTS: "-Dbuild.tooling=true -Dbuild.af3=true -Dbuild.emf=true"
  MAVEN_TEST_OPTS: "-Dbuild.tests=true"
  MAVEN_BUILD_DIR: "-Duser.dir=/builds/$CI_PROJECT_PATH"


cache:
  key: Default
  paths:
    - .m2/repository/

build:
  stage: build
  cache:
    key: Default
  before_script:
    - git submodule update $GIT_SUBMODULE_OPTS
  script:
    - mvn $MAVEN_CLI_OPTS $MAVEN_BUILD_OPTS verify
  artifacts:
    untracked: true
    paths:
      - releng/org.fortiss.af3.update/target/repository/
      - releng/org.fortiss.tooling.update/target/repository/
      - products/af3/org.fortiss.af3.phoenix.product/target/products/org.fortiss.af3.phoenix.product-*.zip

test:
  stage: test
  dependencies: 
    - build
  cache:
    key: Default
  before_script:
    - git submodule update $GIT_SUBMODULE_OPTS releng/org.fortiss.af3.target
    - git submodule update $GIT_SUBMODULE_OPTS tests/af3
    - git submodule update $GIT_SUBMODULE_OPTS features/af3
    - git submodule update $GIT_SUBMODULE_OPTS features/tooling
    - xvfb.sh # Setup of a virtual display needed for bringing up eclipse
  script:
    - mvn $MAVEN_CLI_OPTS $MAVEN_TEST_OPTS $MAVEN_BUILD_DIR integration-test
  artifacts:
    paths:
      - tests/af3/org.fortiss.af3.phoenix.product.tests/target/surefire-reports/TEST-org.fortiss.af3.phoenix.product.tests.AllTests.xml
      - products/af3/org.fortiss.af3.phoenix.product/target/products/org.fortiss.af3.phoenix.product-*.zip

deploy:
  stage: deploy
  dependencies:
    - test
  rules:
    - if: '$BUILD_TYPE == "nightly"' # This rule will be evaluated
      when: on_success
  script:
    - ls
  artifacts:
    paths:
      - products/af3/org.fortiss.af3.phoenix.product/target/products/org.fortiss.af3.phoenix.product-linux.gtk.x86_64.zip
      - products/af3/org.fortiss.af3.phoenix.product/target/products/org.fortiss.af3.phoenix.product-macosx.cocoa.x86_64.zip
      - products/af3/org.fortiss.af3.phoenix.product/target/products/org.fortiss.af3.phoenix.product-win32.win32.x86_64.zip
