image: eicweb.phy.anl.gov:4567/eic/juggler/juggler:$JUGGLER_TAG

default:
  before_script:
    - source .local/bin/env.sh
  interruptible: true
  tags:
    - phy-scratch
  artifacts:
    expire_in: 3 days
    paths:
      - .local/detector
      - .local/lib
      - .local/bin
      - .local/include
      - .local/share
      - results
      - config
      - juggler.env
    reports:
      dotenv: juggler.env

stages:
  - config
  - initialize
  - compile
  - run
  - benchmarks1
  - benchmarks2
  - process
  - collect
  - finish

common:setup:
  stage: config
  before_script:
    - |
      if [[ "${COMMON_BENCH_VERSION}" == "" ]] ; then
        export COMMON_BENCH_VERSION="master" 
      fi
      echo "COMMON_BENCH_VERSION = ${COMMON_BENCH_VERSION}" 
      git clone -b "${COMMON_BENCH_VERSION}" https://eicweb.phy.anl.gov/EIC/benchmarks/common_bench.git setup 
  script:
    - source setup/bin/env.sh && ./setup/bin/install_common.sh

common:detector:
  stage: initialize
  needs: ["common:setup"]
  script:
    - source .local/bin/env.sh && build_detector.sh
    - mkdir_local_data_link sim_output
    - mkdir -p results
    - mkdir -p config
    - print_env.sh

.compile_benchmark:
  needs:
    - ["common:setup"]
  before_script:
    - source .local/bin/env.sh

.rec_benchmark:
  needs:
    - ["common:detector"]
  before_script:
    - source .local/bin/env.sh
    - ls -lrtha 
    - ln -s "${LOCAL_DATA_PATH}/sim_output" sim_output
    - ln -s "${LOCAL_DATA_PATH}/datasets/data" data
    - ls -lrtha
    - bash bin/get_calibrations
  retry:
    max: 2
    when:
      - runner_system_failure
  interruptible: true

include: 
  - local: 'benchmarks/ecal/config.yml'
  - local: 'benchmarks/track_finding/config.yml'
  - local: 'benchmarks/track_fitting/config.yml'
  - local: 'benchmarks/tracking/config.yml'
  - local: 'benchmarks/clustering/config.yml'
    #  - local: 'benchmarks/rich/config.yml'
  - local: 'benchmarks/imaging_ecal/config.yml'
  - local: 'benchmarks/imaging_shower_ML/config.yml'
  - local: 'benchmarks/far_forward/config.yml'

final_report:
  stage: finish
  needs: ["ecal_collect", "tracking_central_electrons", "clustering:results", "track_finding:collect", "track_fitting:collect"]
  script:
    # disabled while we address ACTS issues
    #- mkdir -p results/views && cd results/views && bash ../../bin/download_views
    - echo "It was a success!"
  allow_failure: true

