This reverts commit cfc2eeb532
.
This commit is contained in:
Родитель
5c4c538af6
Коммит
4d39e587d8
|
@ -1,26 +0,0 @@
|
|||
parameters:
|
||||
- name: CLIRepoPath
|
||||
type: string
|
||||
default: './azure-cli'
|
||||
- name: CLIExtensionRepoPath
|
||||
type: string
|
||||
default: './s'
|
||||
steps:
|
||||
- bash: |
|
||||
set -ev
|
||||
|
||||
python -m venv env
|
||||
chmod +x env/bin/activate
|
||||
. env/bin/activate
|
||||
cd ..
|
||||
# clone azure-cli
|
||||
git clone https://github.com/Azure/azure-cli.git ./azure-cli
|
||||
python -m pip install -U pip
|
||||
pip install azdev
|
||||
azdev --version
|
||||
azdev setup -c $CLI_REPO_PATH -r $CLI_EXT_REPO_PATH --debug
|
||||
az --version
|
||||
displayName: 'azdev setup'
|
||||
env:
|
||||
CLI_REPO_PATH: ${{ parameters.CLIRepoPath }}
|
||||
CLI_EXT_REPO_PATH: ${{ parameters.CLIExtensionRepoPath }}
|
|
@ -12,15 +12,6 @@ pr:
|
|||
include:
|
||||
- '*'
|
||||
|
||||
parameters:
|
||||
- name: versions
|
||||
type: object
|
||||
default:
|
||||
python37: "3.7"
|
||||
python38: "3.8"
|
||||
python39: "3.9"
|
||||
python311: "3.11"
|
||||
|
||||
jobs:
|
||||
- job: CredScan
|
||||
displayName: "Credential Scan"
|
||||
|
@ -147,91 +138,6 @@ jobs:
|
|||
ADO_PULL_REQUEST_LATEST_COMMIT: HEAD
|
||||
ADO_PULL_REQUEST_TARGET_BRANCH: $(System.PullRequest.TargetBranch)
|
||||
|
||||
- job: getPythonVersion
|
||||
displayName: "get Python Version"
|
||||
pool:
|
||||
name: 'pool-ubuntu-2004'
|
||||
steps:
|
||||
- task: UsePythonVersion@0
|
||||
displayName: 'Use Python 3.10'
|
||||
inputs:
|
||||
versionSpec: '3.10'
|
||||
- template: .azure-pipelines/templates/azdev_setup.yml
|
||||
- bash: pip install wheel==0.30.0
|
||||
displayName: 'Install wheel==0.30.0'
|
||||
- bash: |
|
||||
#!/usr/bin/env bash
|
||||
set -ev
|
||||
|
||||
source env/bin/activate
|
||||
az --version
|
||||
python scripts/ci/get_python_version.py
|
||||
pythonVersion=`cat python_version.txt`
|
||||
echo $pythonVersion
|
||||
echo "##vso[task.setvariable variable=pythonVersion;isoutput=true]$pythonVersion"
|
||||
name: CustomParas
|
||||
displayName: 'get Python Version'
|
||||
env:
|
||||
ADO_PULL_REQUEST_LATEST_COMMIT: HEAD
|
||||
ADO_PULL_REQUEST_TARGET_BRANCH: $(System.PullRequest.TargetBranch)
|
||||
|
||||
- ${{each version in parameters.versions}}:
|
||||
- job: MinVersionTests${{version.key}}
|
||||
dependsOn: getPythonVersion
|
||||
variables:
|
||||
PythonVersion: $[ dependencies.getPythonVersion.outputs['CustomParas.pythonVersion'] ]
|
||||
condition: and(succeeded(), contains(variables.PythonVersion, ${{version.value}}))
|
||||
displayName: "Min Version Tests ${{version.key}}"
|
||||
pool:
|
||||
name: 'pool-ubuntu-2004'
|
||||
steps:
|
||||
- task: UsePythonVersion@0
|
||||
displayName: 'Use ${{version.key}}'
|
||||
inputs:
|
||||
versionSpec: '${{version.value}}'
|
||||
addToPath: true
|
||||
- template: .azure-pipelines/templates/azdev_setup.yml
|
||||
- bash: pip install wheel==0.30.0
|
||||
displayName: 'Install wheel==0.30.0'
|
||||
- bash: |
|
||||
set -ev
|
||||
|
||||
. env/bin/activate
|
||||
az --version
|
||||
python scripts/ci/test_min_version.py -v
|
||||
displayName: 'Run min version test ${{version.key}}'
|
||||
env:
|
||||
ADO_PULL_REQUEST_LATEST_COMMIT: HEAD
|
||||
ADO_PULL_REQUEST_TARGET_BRANCH: $(System.PullRequest.TargetBranch)
|
||||
|
||||
- job: MinVersionTestsPython310
|
||||
dependsOn: getPythonVersion
|
||||
variables:
|
||||
PythonVersion: $[ dependencies.getPythonVersion.outputs['CustomParas.pythonVersion'] ]
|
||||
condition: and(succeeded(), contains(variables.PythonVersion, '3.10'))
|
||||
displayName: "Min Version Tests python310"
|
||||
pool:
|
||||
name: 'pool-ubuntu-2004'
|
||||
steps:
|
||||
- task: UsePythonVersion@0
|
||||
displayName: 'Use python310'
|
||||
inputs:
|
||||
versionSpec: '3.10'
|
||||
addToPath: true
|
||||
- template: .azure-pipelines/templates/azdev_setup.yml
|
||||
- bash: pip install wheel==0.30.0
|
||||
displayName: 'Install wheel==0.30.0'
|
||||
- bash: |
|
||||
set -ev
|
||||
|
||||
. env/bin/activate
|
||||
az --version
|
||||
python scripts/ci/test_min_version.py -v
|
||||
displayName: 'Run min version test python310'
|
||||
env:
|
||||
ADO_PULL_REQUEST_LATEST_COMMIT: HEAD
|
||||
ADO_PULL_REQUEST_TARGET_BRANCH: $(System.PullRequest.TargetBranch)
|
||||
|
||||
- job: LintModifiedExtensions
|
||||
displayName: "CLI Linter on Modified Extensions"
|
||||
condition: and(succeeded(), eq(variables['Build.Reason'], 'PullRequest'))
|
||||
|
|
|
@ -1,140 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
# --------------------------------------------------------------------------------------------
|
||||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
# Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
# --------------------------------------------------------------------------------------------
|
||||
|
||||
from subprocess import check_output
|
||||
from util import SRC_PATH
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import shlex
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
logger.setLevel(logging.DEBUG)
|
||||
ch = logging.StreamHandler()
|
||||
ch.setLevel(logging.DEBUG)
|
||||
logger.addHandler(ch)
|
||||
|
||||
|
||||
def get_all_tests():
|
||||
all_tests = []
|
||||
for src_d in os.listdir(SRC_PATH):
|
||||
src_d_full = os.path.join(SRC_PATH, src_d)
|
||||
if not os.path.isdir(src_d_full):
|
||||
continue
|
||||
pkg_name = next((d for d in os.listdir(src_d_full) if d.startswith('azext_')), None)
|
||||
|
||||
# If running in Travis CI, only run tests for edited extensions
|
||||
commit_range = os.environ.get('TRAVIS_COMMIT_RANGE')
|
||||
if commit_range and not check_output(
|
||||
['git', '--no-pager', 'diff', '--name-only', commit_range, '--', src_d_full]):
|
||||
continue
|
||||
|
||||
# Running in Azure DevOps
|
||||
cmd_tpl = 'git --no-pager diff --name-only origin/{commit_start} {commit_end} -- {code_dir}'
|
||||
ado_branch_last_commit = os.environ.get('ADO_PULL_REQUEST_LATEST_COMMIT')
|
||||
ado_target_branch = os.environ.get('ADO_PULL_REQUEST_TARGET_BRANCH')
|
||||
if ado_branch_last_commit and ado_target_branch:
|
||||
if ado_branch_last_commit == '$(System.PullRequest.SourceCommitId)':
|
||||
# default value if ADO_PULL_REQUEST_LATEST_COMMIT not set in ADO
|
||||
continue
|
||||
elif ado_target_branch == '$(System.PullRequest.TargetBranch)':
|
||||
# default value if ADO_PULL_REQUEST_TARGET_BRANCH not set in ADO
|
||||
continue
|
||||
else:
|
||||
cmd = cmd_tpl.format(commit_start=ado_target_branch, commit_end=ado_branch_last_commit,
|
||||
code_dir=src_d_full)
|
||||
if not check_output(shlex.split(cmd)):
|
||||
continue
|
||||
|
||||
# Find the package and check it has tests
|
||||
test_dir = os.path.isdir(os.path.join(src_d_full, pkg_name, 'tests'))
|
||||
if pkg_name and test_dir:
|
||||
# [('azext_healthcareapis', '/mnt/vss/_work/1/s/src/healthcareapis'),
|
||||
# ('azext_firewall', '/mnt/vss/_work/1/s/src/azure-firewall')]
|
||||
all_tests.append((pkg_name, src_d_full))
|
||||
# /mnt/vss/_work/1/s/src/healthcareapis -> healthcareapis
|
||||
# /mnt/vss/_work/1/s/src/azure-firewall -> azure-firewall
|
||||
extension_name = src_d_full.split('/')[-1]
|
||||
logger.info(f'ado_branch_last_commit: {ado_branch_last_commit}, '
|
||||
f'ado_target_branch: {ado_target_branch}, '
|
||||
f'detect which extension need to test: {all_tests}.')
|
||||
return pkg_name, extension_name
|
||||
else:
|
||||
logger.error(f'can not any test')
|
||||
with open('python_version.txt', 'w') as f:
|
||||
f.write('false')
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
def get_min_version(pkg_name, extension_name):
|
||||
try:
|
||||
with open(os.path.join(SRC_PATH, extension_name, pkg_name, 'azext_metadata.json'), 'r') as f:
|
||||
min_version = json.load(f)['azext.minCliCoreVersion']
|
||||
logger.info(f'find minCliCoreVersion: {min_version}')
|
||||
return min_version
|
||||
except Exception as e:
|
||||
logger.error(f'can not get minCliCoreVersion: {e}')
|
||||
with open('python_version.txt', 'w') as f:
|
||||
f.write('false')
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
def get_python_version(min_version):
|
||||
logger.info(f'checkout to minCliCoreVersion: {min_version}')
|
||||
az_min_version = 'azure-cli-' + min_version
|
||||
azure_cli_path = os.path.join(os.path.abspath(os.path.dirname(os.path.dirname(SRC_PATH))), 'azure-cli')
|
||||
# checkout to min cli version
|
||||
cmd = ['git', 'checkout', az_min_version]
|
||||
run_command(cmd, check_return_code=True, cwd=azure_cli_path)
|
||||
# display cli version
|
||||
cmd = ['az', '--version']
|
||||
run_command(cmd, check_return_code=True)
|
||||
try:
|
||||
core_path = os.path.join(azure_cli_path, 'src', 'azure-cli-core')
|
||||
versions = ''
|
||||
with open(os.path.join(core_path, 'setup.py'), 'r') as f:
|
||||
for line in f.readlines():
|
||||
# 'Programming Language :: Python :: 3.8',\n
|
||||
if 'Programming Language :: Python :: ' in line:
|
||||
# 3.8',\n
|
||||
_, _, python_version = line.split(' :: ')
|
||||
# 3.8
|
||||
python_version = python_version.split('\'')[0]
|
||||
# 3.6 3.7 3.8 3.9 3.10 3.11
|
||||
versions += python_version + ' '
|
||||
logger.info(f'return python verisons: {versions}')
|
||||
with open('python_version.txt', 'w') as f:
|
||||
f.write(versions)
|
||||
except Exception as e:
|
||||
logger.error(f'can not get any python versions: {e}')
|
||||
with open('python_version.txt', 'w') as f:
|
||||
f.write('false')
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
def run_command(cmd, check_return_code=False, cwd=None):
|
||||
error_flag = False
|
||||
logger.info(f'cmd: {cmd}')
|
||||
try:
|
||||
out = subprocess.run(cmd, check=True, cwd=cwd)
|
||||
if check_return_code and out.returncode:
|
||||
raise RuntimeError(f"{cmd} failed")
|
||||
except subprocess.CalledProcessError:
|
||||
error_flag = True
|
||||
return error_flag
|
||||
|
||||
|
||||
def main():
|
||||
pkg_name, extension_name = get_all_tests()
|
||||
min_version = get_min_version(pkg_name, extension_name)
|
||||
get_python_version(min_version)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
|
@ -1,53 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
# --------------------------------------------------------------------------------------------
|
||||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
# Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
# --------------------------------------------------------------------------------------------
|
||||
|
||||
from get_python_version import get_all_tests, get_min_version, run_command
|
||||
from util import SRC_PATH
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
logger.setLevel(logging.DEBUG)
|
||||
ch = logging.StreamHandler()
|
||||
ch.setLevel(logging.DEBUG)
|
||||
logger.addHandler(ch)
|
||||
|
||||
|
||||
def prepare_for_min_version(min_version, extension_name):
|
||||
logger.info(f'checkout to minCliCoreVersion: {min_version}')
|
||||
az_min_version = 'azure-cli-' + min_version
|
||||
azure_cli_path = os.path.join(os.path.abspath(os.path.dirname(os.path.dirname(SRC_PATH))), 'azure-cli')
|
||||
# checkout to min cli version
|
||||
cmd = ['git', 'checkout', az_min_version]
|
||||
run_command(cmd, check_return_code=True, cwd=azure_cli_path)
|
||||
# display cli version
|
||||
cmd = ['az', '--version']
|
||||
run_command(cmd, check_return_code=True)
|
||||
logger.info('installing old testsdk')
|
||||
testsdk_path = os.path.join(azure_cli_path, 'src', 'azure-cli-testsdk')
|
||||
cmd = ['python', 'setup.py', 'install']
|
||||
run_command(cmd, check_return_code=True, cwd=testsdk_path)
|
||||
logger.info(f'installing extension: {extension_name}')
|
||||
cmd = ['azdev', 'extension', 'add', extension_name]
|
||||
run_command(cmd, check_return_code=True)
|
||||
|
||||
|
||||
def run_tests(extension_name):
|
||||
cmd = ['azdev', 'test', extension_name, '--no-exitfirst', '--verbose']
|
||||
return run_command(cmd, check_return_code=True)
|
||||
|
||||
|
||||
def main():
|
||||
pkg_name, extension_name = get_all_tests()
|
||||
min_version = get_min_version(pkg_name, extension_name)
|
||||
prepare_for_min_version(min_version, extension_name)
|
||||
sys.exit(1) if run_tests(extension_name) else sys.exit(0)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
Загрузка…
Ссылка в новой задаче