image: lofareosc/lofar-pipeline-ci:latest

variables:
  TEST_DATASET_NAME: "L570745_uv_first10.MS.tar.xz"
  PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"

stages:
  - build_docker
  - push_docker
  - validate_cwl_scripts
  - test_steps
  - integration_test

before_script:
   - mkdir workdir
   - mkdir logs

after_script:
  - echo "All done"

build_docker:
  image: docker:latest
  stage: build_docker
  only:
    - tags
  script:
    - apk add git subversion git-lfs bash
    - cd Docker
    - bash build_docker.sh

push_docker_tags:
  image: docker:latest
  allow_failure: true
  stage: push_docker
  only:
    - tags
  script:
    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
    - docker tag lofareosc/prefactor-ci:latest $CI_REGISTRY/prefactor-ci:$CI_COMMIT_REF_NAME
    - docker push $CI_REGISTRY/prefactor-ci:$CI_COMMIT_REF_NAME

validate_scripts:
  stage: validate_cwl_scripts
  script:
    - for file in `find . -name 'steps/*.cwl'`; do cwltool --validate $file; done

average_step_generator:
  stage: test_steps
  allow_failure: true
  script:
    - cwl-runner steps/DP3.AveragerStepGenerator.cwl test_jobs/averager_step_generator.json
    - ! cwl-runner steps/DP3.AveragerStepGenerator.cwl test_jobs/averager_step_generator_error.json

applycal_step_generator:
  stage: test_steps
  allow_failure: true
  script:
    - cwl-runner steps/DP3.ApplyCalStepGenerator.cwl test_jobs/applycal_step_generator.json

aoflagger_step_generator:
  stage: test_steps
  allow_failure: true
  script:
    - cwl-runner steps/DP3.AOFlaggerStepGenerator.cwl test_jobs/aoflagger_step_generator.json

preflagger_step_generator:
  stage: test_steps
  allow_failure: true
  script:
    - cwl-runner steps/DP3.PreflaggerStepGenerator.cwl test_jobs/preflagger_step_generator.json

losoto_abs:
  stage: test_steps
  allow_failure: true
  script:
    - cwl-runner --no-container steps/LoSoTo.Abs.cwl test_jobs/losoto_abs.json

losoto_duplicate:
  stage: test_steps
  allow_failure: true
  script:
    - cwl-runner --no-container steps/LoSoTo.Duplicate.cwl test_jobs/losoto_duplicate.json

losoto_plot:
  stage: test_steps
  allow_failure: true
  script:
    - cwl-runner --no-container steps/LoSoTo.Plot.cwl test_jobs/losoto_plot.json
losoto_flag:
  stage: test_steps
  allow_failure: true
  script:
    - cwl-runner --no-container steps/LoSoTo.Flag.cwl test_jobs/losoto_flag.json
losoto_norm:
  stage: test_steps
  allow_failure: true
  script:
    - cwl-runner --no-container steps/LoSoTo.Norm.cwl test_jobs/losoto_norm.json

losoto_replicateonaxis:
  stage: test_steps
  allow_failure: true
  script:
    - cwl-runner --no-container steps/LoSoTo.Replicateonaxis.cwl test_jobs/losoto_replicateonaxis.json

losoto_reset:
  stage: test_steps
  allow_failure: true
  script:
    - cwl-runner --no-container steps/LoSoTo.Reset.cwl test_jobs/losoto_reset.json

losoto_clip:
  stage: test_steps
  allow_failure: true
  script:
    - cwl-runner --no-container steps/LoSoTo.Clip.cwl test_jobs/losoto_clip.json
losoto_flagextend:
  stage: test_steps
  allow_failure: true
  script:
    - cwl-runner --no-container steps/LoSoTo.Flagextend.cwl test_jobs/losoto_flagextend.json
losoto_flagstation:
  stage: test_steps
  allow_failure: true
  script:
    - cwl-runner --no-container steps/LoSoTo.FlagStation.cwl test_jobs/losoto_flagstation.json
losoto_faraday:
  stage: test_steps
  allow_failure: true
  script:
    - cwl-runner --no-container steps/LoSoTo.Faraday.cwl test_jobs/losoto_faraday.json

losoto_interpolate:
  stage: test_steps
  allow_failure: true
  script:
    - cwl-runner --no-container steps/LoSoTo.Interpolate.cwl test_jobs/losoto_interpolate.json
losoto_residual:
  stage: test_steps
  allow_failure: true
  script:
    - cwl-runner --no-container steps/LoSoTo.Residual.cwl test_jobs/losoto_residual.json

losoto_polalign:
  stage: test_steps
  allow_failure: true
  script:
    - cwl-runner --no-container steps/LoSoTo.Polalign.cwl test_jobs/losoto_polalign.json


parset_selector:
  stage: test_steps
  allow_failure: true
  script:
    - cwl-runner steps/DP3.Selector.cwl test_jobs/selector.json

file_selector:
  stage: test_steps
  allow_failure: true
  script:
    - cwl-runner steps/FileSelector.cwl test_jobs/file_selector.json


NDPPP:
  stage: test_steps
  allow_failure: true
  script:
    - cwltool --no-container --preserve-environment LD_LIBRARY_PATH --preserve-environment PATH steps/DPPP.cwl test_jobs/NDPPP.json

DP3.Execute:
  stage: test_steps
  allow_failure: true
  script:
    - cwltool --no-container --preserve-environment LD_LIBRARY_PATH --preserve-environment PATH steps/DP3.Execute.cwl test_jobs/dp3_execute.json

h5parm_collector:
  stage: test_steps
  allow_failure: true
  script:
    - cwltool --no-container --preserve-environment LD_LIBRARY_PATH --preserve-environment PATH --preserve-environment PYTHONPATH steps/H5ParmCollector.cwl test_jobs/h5parm_collector.json

aoflagger:
  stage: test_steps
  allow_failure: true
  script:
    - cwltool --no-container --preserve-environment LD_LIBRARY_PATH --preserve-environment PATH steps/AOFlagger.cwl test_jobs/aoflagger.json

interpolate_visibilities:
  stage: test_steps
  allow_failure: true
  script:
    - cwltool --no-container --preserve-environment LD_LIBRARY_PATH --preserve-environment PATH --preserve-environment PYTHONPATH steps/interpolate_visibilities.cwl test_jobs/interpolate_visibilities.json

h5parm_collector:
  stage: test_steps
  allow_failure: true
  script:
    - cwltool --no-container --preserve-environment LD_LIBRARY_PATH --preserve-environment PATH --preserve-environment PYTHONPATH steps/H5ParmCollector.cwl test_jobs/h5parm_collector.json

ddecal:
  stage: test_steps
  allow_failure: true
  script:
    - cwltool --no-container --preserve-environment LD_LIBRARY_PATH --preserve-environment PATH --preserve-environment PYTHONPATH steps/ddecal.cwl test_jobs/ddecal.json

gaincal:
  stage: test_steps
  allow_failure: true
  script:
    - cwltool --no-container --preserve-environment LD_LIBRARY_PATH --preserve-environment PATH --preserve-environment PYTHONPATH steps/gaincal.cwl test_jobs/gaincal.json

predict:
  stage: test_steps
  allow_failure: true
  script:
    - cwltool --no-container --preserve-environment LD_LIBRARY_PATH --preserve-environment PATH --preserve-environment PYTHONPATH steps/predict.cwl test_jobs/predict.json