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

default:
  before_script:
    - git clone https://eicweb.phy.anl.gov/EIC/detectors/topside.git 
      && mkdir topside/build 
      && cd topside/build 
      && cmake ../. -DCMAKE_CXX_STANDARD=17 -DCMAKE_INSTALL_PREFIX=/usr/local 
      && make -j20 install 
      && cd ../.. 
      || exit 1
  artifacts:
    expire_in: 72 hours 
    paths:
      - .local/detector
      - .local/lib
      - results
      - config

stages:
  - config
  - initialize
  - data_init
  - simulate
  - benchmarks
  - collect
  - deploy

env:
  stage: config
  script:
    - ./util/print_env.sh
    - mkdir -p /scratch/${CI_PROJECT_NAME}_${CI_PIPELINE_ID}
    - mkdir -p /scratch/${CI_PROJECT_NAME}_${CI_PIPELINE_ID}/sim_output

detector:
  stage: initialize
  needs: ["env"]
  timeout: 1 hours
  cache:
    key:
      files:
        - options/env.sh
        - util/build_detector.sh
      prefix: "$CI_COMMIT_REF_SLUG"
    paths:
      - .local/detector
      - .local/lib
  script:
    - ./util/print_env.sh
    - ./util/build_detector.sh
    - ./util/print_env.sh
    - mkdir -p results
    - mkdir -p config

get_data:
  stage: data_init
  needs: ["detector"]
  script:
    - source options/env.sh
    - ln -s ${LOCAL_DATA_PATH}/sim_output sim_output
    - ln -s ${LOCAL_DATA_PATH}/datasets/data data
    - cd ${LOCAL_DATA_PATH} && git clone --depth=1 https://eicweb.phy.anl.gov/EIC/datasets.git datasets

.det_benchmark:
  image: eicweb.phy.anl.gov:4567/eic/juggler/juggler:$JUGGLER_TAG
  needs:
    - ["get_data"]
  before_script:
    - source options/env.sh
    - ln -s ${LOCAL_DATA_PATH}/sim_output sim_output
    - ln -s ${LOCAL_DATA_PATH}/datasets/data data
  artifacts:
    expire_in: 20 weeks
    paths:
      - results/


include: 
  - local: 'benchmarks/barrel_ecal/config.yml'
  - local: 'benchmarks/roman_pots/config.yml'
  - local: 'benchmarks/zdc/config.yml'
  - local: 'benchmarks/crystal_calorimeter/config.yml'
  - local: 'benchmarks/pid/config.yml'

deploy_results:
  stage: deploy
  needs:
    - ["collect_results:zdc","collect_results:barrel_ecal","collect_results:crystal_calorimeter"]
  script:
    - echo "deploy results!"


pages:
  stage: deploy
  rules:
    - if: '$CI_COMMIT_BRANCH == "master" && $CI_SERVER_HOST != "eicweb.phy.anl.gov"'
  cache:
    paths:
      - node_modules/
  image: node:latest
  script:
    - mkdir public && cp doc/main.html public/index.html
  artifacts:
    paths:
      - public


