# Live Test For Python SDK

name: AUTO RELEASE

trigger:
  branches:
    exclude:
    - '*'

# avoid being triggered as part of CI check
pr:
  branches:
    exclude:
    - '*'


variables:
  - group: Release Secrets for GitHub
  - group: Azure SDK Auto Release Pipeline Secrets

jobs:
- job: LiveTestPython
  displayName: Live Test Python
  timeoutInMinutes: 1500
  strategy:
    maxParallel: 5
  pool:
    name: azsdk-pool
    vmImage: 'ubuntu-22.04'
  variables:
    Codeql.Enabled: false
  steps:
    - task: UsePythonVersion@0
      inputs:
        versionSpec: '3.10'
        addToPath: true
        architecture: 'x64'
    - task: NodeTool@0
      displayName: Install Node.js
      inputs:
        versionSpec: 22.x
    - bash: |
        cd ..
        git config --global user.email "PythonSdkPipelines"
        git config --global user.name "$(USR_NAME)"

        # clone(REPO: https://github.com/Azure/azure-sdk-for-python.git, USR_NAME: Azure, USR_TOKEN: xxxxxxxxxxxxx)
        mkdir azure-sdk-for-python
        git clone ${REPO:0:8}$(USR_NAME):$(azuresdk-github-pat)@${REPO:8} $(pwd)/azure-sdk-for-python
    - template: /eng/common/testproxy/test-proxy-tool.yml
      parameters:
        rootFolder: ../azure-sdk-for-python
    - bash: |
        root_path=$(pwd)
        script_path=$(pwd)/scripts/auto_release
        cd ..

        # prepare env if need to generate SDK code
        if [ "$(SPEC_README)" ]; then
          mkdir azure-rest-api-specs
          git clone https://github.com/Azure/azure-rest-api-specs.git $(pwd)/azure-rest-api-specs

          if [ "$(REST_REPO_HASH)" ]; then
            cd azure-rest-api-specs
            git reset --hard $(REST_REPO_HASH)
            cd ../
          fi

          # install autorest
          sudo npm init -f
          sudo npm install -g autorest --save

          mkdir temp_folder

          export SPEC_README=$(SPEC_README)
          export SPEC_REPO=$(pwd)/azure-rest-api-specs
          export TEMP_FOLDER=$(pwd)/temp_folder
          export DEBUG_REST_BRANCH=$(DEBUG_REST_BRANCH)
        fi


        # import env variable
        export AZURE_TEST_RUN_LIVE=$(AZURE_TEST_RUN_LIVE)
        export TENANT_ID=$(ENV-TENANT-ID)
        export SUBSCRIPTION_ID=$(ENV-SUBSCRIPTION-ID)
        export AZURE_TENANT_ID=$(ENV-TENANT-ID)
        export AZURE_SUBSCRIPTION_ID=$(ENV-SUBSCRIPTION-ID)
        export ISSUE_LINK=$(ISSUE_LINK)
        export SCRIPT_PATH=$script_path
        export BOT_TOKEN=$(azuresdk-github-pat)
        export GIT_TOKEN=$(Yuchao-GitToken)
        export PYTHON_TAG=$(PYTHON_TAG)
        export DEBUG_SDK_BRANCH=$(DEBUG_SDK_BRANCH)
        export TARGET_DATE=$(TARGET_DATE)
        export TEST_FOLDER=$(TEST_FOLDER)
        export ISSUE_OWNER=$(ISSUE_OWNER)

        # install azure-sdk-tools
        python -m pip install $root_path/eng/tools/azure-sdk-tools[build,ghtools,sdkgenerator]

        # install requirements
        python -m pip install -r $script_path/requirement.txt

        # install tsp-client
        cd azure-sdk-for-python/eng/common/tsp-client
        npm ci
        cd ../../..

        # run
        python $script_path/main.py
