parameters:
  name: ''
  vmImage: ''
  matrix: []
  dependsOn: []
  condition: ne(variables['Build.Reason'], 'Schedule')

jobs:
- job: ${{ parameters.name }}
  dependsOn: ${{ parameters.dependsOn }}
  condition: ${{ parameters.condition }}
  pool:
    vmImage: ${{ parameters.vmImage }}
  variables:
    TEST_DIR: '$(Agent.WorkFolder)/tmp_folder'
    JUNITXML: 'test-data.xml'
    OMP_NUM_THREADS: '2'
    OPENBLAS_NUM_THREADS: '2'
    CPU_COUNT: '2'
    NUMPY_VERSION: 'latest'
    SCIPY_VERSION: 'latest'
    SKLEARN_VERSION: 'latest'
    TENSORFLOW_VERSION: 'none'
    KERAS_VERSION: 'none'
    JOBLIB_VERSION: 'latest'
    PANDAS_VERSION: 'latest'
    MATPLOTLIB_VERSION: 'latest'
    PYTEST_VERSION: 'latest'
    PYTEST_XDIST_VERSION: 'latest'
    THREADPOOLCTL_VERSION: 'latest'
    COVERAGE: 'false'
    TEST_DOCSTRINGS: 'false'
    CHECK_WARNINGS: 'false'
    BLAS: 'openblas'
    # Set in azure-pipelines.yml
    DISTRIB: ''
    DOCKER_CONTAINER: ''
    SHOW_SHORT_SUMMARY: 'false'
  strategy:
    matrix:
      ${{ insert }}: ${{ parameters.matrix }}

  steps:
    # Container is detached and sleeping, allowing steps to run commands
    # in the container. The TEST_DIR is mapped allowing the host to access
    # the JUNITXML file
    - script: >
        docker container run --rm
        --volume $TEST_DIR:/temp_dir
        --volume $PWD:/io
        -w /io
        --detach
        --name skcontainer
        -e DISTRIB=$DISTRIB
        -e TEST_DIR=/temp_dir
        -e JUNITXML=$JUNITXML
        -e VIRTUALENV=testvenv
        -e NUMPY_VERSION=$NUMPY_VERSION
        -e SCIPY_VERSION=$SCIPY_VERSION
        -e SKLEARN_VERSION=$SKLEARN_VERSION
        -e TENSORFLOW_VERSION=$TENSORFLOW_VERSION
        -e KERAS_VERSION=$KERAS_VERSION
        -e JOBLIB_VERSION=$JOBLIB_VERSION
        -e PANDAS_VERSION=$PANDAS_VERSION
        -e PILLOW_VERSION=$PILLOW_VERSION
        -e MATPLOTLIB_VERSION=$MATPLOTLIB_VERSION
        -e PYTEST_VERSION=$PYTEST_VERSION
        -e PYTEST_XDIST_VERSION=$PYTEST_XDIST_VERSION
        -e THREADPOOLCTL_VERSION=$THREADPOOLCTL_VERSION
        -e OMP_NUM_THREADS=$OMP_NUM_THREADS
        -e OPENBLAS_NUM_THREADS=$OPENBLAS_NUM_THREADS
        -e SKLEARN_SKIP_NETWORK_TESTS=$SKLEARN_SKIP_NETWORK_TESTS
        -e BLAS=$BLAS
        -e CPU_COUNT=$CPU_COUNT
        $DOCKER_CONTAINER
        sleep 1000000
      displayName: 'Start container'
    - script: >
        docker exec skcontainer ./build_tools/azure/install.sh
      displayName: 'Install'
    - script: >
        docker exec skcontainer ./build_tools/azure/test_script.sh
      displayName: 'Test Library'
    - task: PublishTestResults@2
      inputs:
        testResultsFiles: '$(TEST_DIR)/$(JUNITXML)'
        testRunTitle: ${{ format('{0}-$(Agent.JobName)', parameters.name) }}
      displayName: 'Publish Test Results'
      condition: succeededOrFailed()
    - script: >
        docker container stop skcontainer
      displayName: 'Stop container'
      condition: always()
