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

default:
  artifacts:
    expire_in: 72 hours 
    paths:
      - results/
      - images/
        #    exclude:
        #      - .git/
        #      - datasets/.git/
        #before_script:
        #  - git clone https://eicweb.phy.anl.gov/EIC/NPDet.git
        #  - git clone https://eicweb.phy.anl.gov/EIC/detectors/topside.git && mkdir topside/build && cd topside/build && cmake ../. -DCMAKE_INSTALL_PREFIX=/usr/local && make -j20 install && cd ../..
        #    - cd NPDet/build && cmake ../. -DCMAKE_INSTALL_PREFIX=/usr/local && make -j10 && make install

stages:
  - config
  - initialize
  - data_init
  - simulate
  - benchmarks
  - 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
  artifacts:
    paths:
      - .local/detector
      - .local/lib
      - results
      - config
  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:
    - 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

include: 
  - local: 'benchmarks/trackers/config.yml'
  - local: 'benchmarks/calorimeters/config.yml'
  - local: 'benchmarks/pid/config.yml'

    #roman_pot_simu:
    #  stage: simulate
    #  needs: 
    #    - ["get_data","detector"]
    #  script:
    #    - bash benchmarks/trackers/roman_pot_simu.sh
    #
    #roman_pot_nhits:
    #  stage: benchmarks
    #  needs:
    #    - ["roman_pot_simu","detector"]
    #  script:
    #    - root -b -q benchmarks/trackers/simple_tracking.cxx+
    #  allow_failure: true
    #
    #roman_pot_eta:
    #  stage: benchmarks
    #  needs:
    #    - ["roman_pot_simu","detector"]
    #  script:
    #    - root -b -q benchmarks/trackers/roman_pot_hit_eta.cxx+
    #  allow_failure: true
    #
    #zdc_simulation:
    #  stage: simulate
    #  needs: 
    #    - ["get_data","detector"]
    #  script:
    #    - bash benchmarks/calorimeters/run_simulation_zdc.sh
    #
    #cal_test_3_zdc_neutrons_reader:
    #  stage: benchmarks
    #  needs: 
    #    - ["zdc_simulation","detector"]
    #  script:
    #    - root -b -q benchmarks/calorimeters/zdc_neutrons_reader.cxx
    #  allow_failure: true
    #
    #
    #zdc_benchmark:
    #  stage: benchmarks
    #  needs: 
    #    - ["zdc_simulation","detector"]
    #  script:
    #    - ls -lrth sim_output
    #    - root -b -q benchmarks/calorimeters/simple_checking.cxx+
    #  allow_failure: true
    #
    #zdc_benchmark_info_histogram:
    #  stage: benchmarks
    #  needs: 
    #    - ["zdc_simulation","detector"]
    #  script:
    #    - root -b -q benchmarks/calorimeters/simple_info_plot_histograms.cxx+
    #  allow_failure: true
    #
    #crystal_emcal_simulation:
    #  stage: simulate
    #  needs: 
    #    - ["get_data"]
    #  script:
    #     bash benchmarks/calorimeters/run_simulation_crystal.sh
    #
    #crystal_benchmark:
    #  stage: benchmarks
    #  needs:
    #    - ["crystal_emcal_simulation","detector"]
    #  script:
    #    - ls -lrth sim_output
    #    - root -b -q benchmarks/calorimeters/simple_checking_crystal.cxx+
    #  allow_failure: true
    #
    #crystal_pion_simulation:
    #  stage: simulate
    #  needs:
    #    - ["get_data","detector"]
    #  tags:
    #    - silicon
    #  script:
    #    - source options/env.sh
    #    - npsim --runType batch --numberOfEvents 100 --compactFile ${DETECTOR_PATH}/topside.xml --inputFiles  data/emcal_electrons.hepmc  --outputFile  sim_output/output_emcal_electrons.root

deploy_results:
  stage: deploy
  needs:
    - ["zdc_benchmark"]
  tags:
    - silicon
  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


