# Release status statistics

name: ReleaseHelper

trigger:
  branches:
    exclude:
    - '*'

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


schedules:
  - cron: "0,30 1-9 * * *"
    displayName: Daily release
    branches:
      include:
      - main
    always: true

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


jobs:
- job: ReleaseHelper
  displayName: ReleaseHelper Python 3.9
  timeoutInMinutes: 30
  strategy:
    maxParallel: 1
  pool:
    name: azsdk-pool
    vmImage: 'ubuntu-22.04'
  variables:
    Codeql.Enabled: false
  steps:
    - task: UsePythonVersion@0
      inputs:
        versionSpec: '3.9'
        addToPath: true
        architecture: 'x64'
    - bash: |
        script_path=$(pwd)/scripts/release_helper
        cd ..
        git config --global user.email "ReleaseHelper"
        git config --global user.name "ReleaseHelper"

        # clone(REPO: https://github.com/Azure/azure-sdk-for-python.git, USR_NAME: Azure, USR_TOKEN: xxxxxxxxxxxxx)
        mkdir file-storage
        git clone ${FILE_REPO:0:8}$(USR_NAME):$(Yuchao-GitToken)@${FILE_REPO:8} $(pwd)/file-storage

        mkdir azure-rest-api-specs
        git clone -b $(SPEC_BRANCH) https://github.com/Azure/azure-rest-api-specs.git $(pwd)/azure-rest-api-specs

        # import env variable
        export AZURESDK_BOT_TOKEN=$(azuresdk-github-pat)
        export PIPELINE_TOKEN=$(System.AccessToken)
        export LANGUAGE=$(RUN_LANGUAGE)
        export SPEC_REPO=$(pwd)/azure-rest-api-specs/specification
        export TYPESPEC_JSON=$(pwd)/file-storage/data/typespec.json
        export TEST_ISSUE_NUMBER=$(TEST_ISSUE_NUMBER)

        # create virtual env
        python -m venv venv-sdk
        source venv-sdk/bin/activate
        python -m pip install -r $script_path/requirement.txt

        # checkout the target branch
        cd file-storage
        git checkout release-helper

        # run
        python $script_path/main.py
