# ---------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# ---------------------------------------------------------

parameters:
- name: pythonVersion
  displayName: Python Version
  type: string
  default: 3.9
  values:
    - 3.7
    - 3.8
    - 3.9
# Defines workspace lifetime
# Workspaces are used for workspaceWindowSeconds
# and optionally deleted after another
# workspaceWindowSeconds have elapsed
- name: workspaceWindowSeconds
  displayName: Workspace Active Window (seconds)
  type: number
  default: 432000 # 5 days for trobleshooting
  # Specifies whether to remove workspaces
  # older than 2*worksapceWindowSeconds
- name: oldWorkspaceHandling
  displayName: How to handle old workspaces
  type: string
  default: Cull
  values:
    - Cull
    - Keep
  # Specifies the region in which to create
  # any new workspace
- name: workspaceLocation
  displayName: Workspace Location
  type: string
  default: WestUS
  values:
    - CentralUSEUAP
    - EastUS
    - EastUS2EUAP
    - WestCentralUS
    - WestUS
    - UKSouth
- name: cliSource
  displayName: Installation source for CLI
  type: string
  default: LatestDev
  values:
    - LatestRelease
    - LatestDev
    - LatestTest
- name: sdkSource
  displayName: Installation source for Python SDK
  type: string
  default: LatestDev
  values:
    - LatestRelease
    - LatestDev
    - LatestTest

variables:
- name: SubscriptionName
  value: "Interpretability - Automation"
- name: ConfigFileArtifact
  value: WorkspaceConfiguration

pr:
  - current_release

trigger: none # No CI build

schedules:
  - cron: "20 1 * * *" # Time is UTC
    displayName: Nightly Build
    branches:
      include:
        - main
    always: true

pool:
  vmImage: "ubuntu-latest"

# =========================================================================

stages:
- stage: ObtainPrepareWorkspace
  displayName: Obtain and prepare workspace
  pool:
    vmImage: ubuntu-latest

  jobs:
  - template: templates/obtain-prepare-workspace-job-template.yaml
    parameters:
      pythonVersion: ${{parameters.pythonVersion}}
      workspaceWindowSeconds: ${{parameters.workspaceWindowSeconds}}
      oldWorkspaceHandling: ${{parameters.oldWorkspaceHandling}}
      workspaceLocation: ${{parameters.workspaceLocation}}
      cliSource: ${{parameters.cliSource}}
      sdkSource: ${{parameters.sdkSource}}
      subscriptionName: $(SubscriptionName)
      configFileDirectory: configFiles
      configFileArtifact: $(ConfigFileArtifact)
        
# =========================================================================

- stage: RunPythonTests
  displayName: Run Python tests
  dependsOn: ObtainPrepareWorkspace
  pool:
    vmImage: ubuntu-latest

  jobs:
  - template: templates/run-python-tests-job-template.yaml
    parameters:
      pythonVersion: ${{parameters.pythonVersion}}
      cliSource: ${{parameters.cliSource}}
      sdkSource: ${{parameters.sdkSource}}
      subscriptionName: $(SubscriptionName)
      configFileArtifact: $(ConfigFileArtifact)

  - template: templates/run-python-tests-job-template.yaml
    parameters:
      pythonVersion: ${{parameters.pythonVersion}}
      cliSource: ${{parameters.cliSource}}
      sdkSource: ${{parameters.sdkSource}}
      subscriptionName: $(SubscriptionName)
      configFileArtifact: $(ConfigFileArtifact)
      testRunType: Notebooks