#
# This file describes the common rules for the stages
#
---
.only-master:
  only:
    - master@solverstack/chameleon
    - /^ci-.*$/

.only-branches:
  only:
    - branches
    - master@solverstack/chameleon
    - /^ci-.*$/
  except:
    - master
    - schedules

.build_script_template:
  image: registry.gitlab.inria.fr/solverstack/docker/distrib
  stage: build
  tags: ["linux"]
  script:
    - export LOGNAME=chameleon_${VERSION}.log
    - echo $LOGNAME
    - echo build BUILD_OPTIONS $BUILD_OPTIONS | tee -a ${LOGNAME}
    - echo build VERSION       $VERSION       | tee -a ${LOGNAME}
    - ls -l *.log
    - (cd build-$VERSION &&
       scan-build -plist --intercept-first --exclude CMakeFiles --analyze-headers -o analyzer_reports
       cmake -C ../cmake_modules/gitlab-ci-initial-cache.cmake .. $BUILD_OPTIONS &&
       scan-build -plist --intercept-first --exclude CMakeFiles --analyze-headers -o analyzer_reports
       ctest --no-compress-output -V -j 5
             -D ExperimentalBuild
             -D ExperimentalSubmit
             | tee ../${LOGNAME})
    - (cd build-$VERSION &&
       make install | tee -a ../${LOGNAME} &&
       rm install/ -r)
  except:
    - schedules

.test_script_template:
  image: registry.gitlab.inria.fr/solverstack/docker/distrib
  stage: test
  tags: ["linux"]
  script:
    - export LOGNAME=chameleon_${VERSION}_${CATEGORY}_${PRECISION}
    - echo $LOGNAME
    - echo test TESTS_RESTRICTION $TESTS_RESTRICTION  | tee -a ${LOGNAME}.log
    - echo test VERSION $VERSION     | tee -a ${LOGNAME}.log
    - echo test CATEGORY $CATEGORY   | tee -a ${LOGNAME}.log
    - echo test PRECISION $PRECISION | tee -a ${LOGNAME}.log
    - ls -l *.log
    - (cd build-$VERSION &&
       eval "ctest --no-compress-output -V
             $TESTS_RESTRICTION
             -D ExperimentalTest
             -D ExperimentalCoverage
             -D ExperimentalSubmit
             | tee -a ../${LOGNAME}.log")
    - lcov --directory build-$VERSION --capture --output-file ./${LOGNAME}.lcov
    - (cd build-$VERSION && lcov --directory . --capture --output-file ../bis_${LOGNAME}.lcov)
    - xsltproc -o report.xml /home/gitlab/ctest-to-junit.xsl build-$VERSION/Testing/**/Test.xml
  except:
    - schedules

.bench_plafrim_common:
  only:
    - schedules
  stage: test
  tags: ['plafrim']
  timeout: 1 week
  before_script:
    - git submodule update --init --recursive
  script:
    - ./tools/bench/plafrim/run.sh
  artifacts:
    name: "$CI_JOB_NAME"
    expire_in: 1 week
    paths:
      - "chameleon-$NODE-$MPI-$SLURM_NP.err"
      - "chameleon-$NODE-$MPI-$SLURM_NP.out"
      - "tools/bench/plafrim/chameleon.csv"
      - "tools/bench/plafrim/results/$JUBE_ID"
  variables:
    PLATFORM: plafrim
