Skip to content

Commit

Permalink
[CICD] Fix cmdcov bug (Azure#410)
Browse files Browse the repository at this point in the history
* update

* update

* update

* update

* update
  • Loading branch information
wangzelin007 authored Jul 14, 2023
1 parent 65c5e9c commit 9375065
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 65 deletions.
4 changes: 4 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
Release History
===============
0.1.56
++++++
* Fix cmdcov issue(#410): Get config from github when get_cli_repo_path failed

0.1.55
++++++
* `azdev command-change meta-diff`: Fix data/meta_change_whitelist.txt pkg building
Expand Down
2 changes: 1 addition & 1 deletion azdev/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
# license information.
# -----------------------------------------------------------------------------

__VERSION__ = '0.1.55'
__VERSION__ = '0.1.56'
11 changes: 7 additions & 4 deletions azdev/operations/cmdcov/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import os
import time
import requests
import yaml

from knack.log import get_logger
Expand All @@ -20,10 +21,12 @@
try:
with open(os.path.join(get_cli_repo_path(), 'scripts', 'ci', 'cmdcov.yml'), 'r') as file:
config = yaml.safe_load(file)
EXCLUDE_MODULES = config['EXCLUDE_MODULES']
except CLIError as ex:
logger.warning('Failed to load cmdcov.yml: %s, please make sure your repo contains the following file '
'https://github.com/Azure/azure-cli/blob/dev/scripts/ci/cmdcov.yml', str(ex))
# pylint: disable=broad-exception-caught
except Exception:
url = "https://raw.githubusercontent.com/Azure/azure-cli/dev/scripts/ci/cmdcov.yml"
response = requests.get(url)
config = yaml.safe_load(response.text)
EXCLUDE_MODULES = config['EXCLUDE_MODULES']


# pylint:disable=too-many-locals, too-many-statements, too-many-branches, duplicate-code
Expand Down
44 changes: 23 additions & 21 deletions azdev/operations/cmdcov/cmdcov.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
import shutil
import sys
import time
import requests
import yaml

from jinja2 import FileSystemLoader, Environment
from knack.log import get_logger
from knack.util import CLIError
from tqdm import tqdm
from azdev.operations.regex import get_all_tested_commands_from_regex
from azdev.utilities.path import get_azdev_repo_path, get_cli_repo_path, find_files
Expand All @@ -22,26 +22,28 @@
try:
with open(os.path.join(get_cli_repo_path(), 'scripts', 'ci', 'cmdcov.yml'), 'r') as file:
config = yaml.safe_load(file)
ENCODING = config['ENCODING']
GLOBAL_PARAMETERS = config['GLOBAL_PARAMETERS']
GENERIC_UPDATE_PARAMETERS = config['GENERIC_UPDATE_PARAMETERS']
WAIT_CONDITION_PARAMETERS = config['WAIT_CONDITION_PARAMETERS']
OTHER_PARAMETERS = config['OTHER_PARAMETERS']
RED = config['RED']
ORANGE = config['ORANGE']
GREEN = config['GREEN']
BLUE = config['BLUE']
GOLD = config['GOLD']
RED_PCT = config['RED_PCT']
ORANGE_PCT = config['ORANGE_PCT']
GREEN_PCT = config['GREEN_PCT']
BLUE_PCT = config['BLUE_PCT']
CLI_OWN_MODULES = config['CLI_OWN_MODULES']
EXCLUDE_COMMANDS = config['EXCLUDE_COMMANDS']
GLOBAL_EXCLUDE_COMMANDS = config['GLOBAL_EXCLUDE_COMMANDS']
except CLIError as ex:
logger.warning('Failed to load cmdcov.yml: %s, please make sure your repo contains the following file '
'https://github.com/Azure/azure-cli/blob/dev/scripts/ci/cmdcov.yml', str(ex))
# pylint: disable=broad-exception-caught
except Exception:
url = "https://raw.githubusercontent.com/Azure/azure-cli/dev/scripts/ci/cmdcov.yml"
response = requests.get(url)
config = yaml.safe_load(response.text)
ENCODING = config['ENCODING']
GLOBAL_PARAMETERS = config['GLOBAL_PARAMETERS']
GENERIC_UPDATE_PARAMETERS = config['GENERIC_UPDATE_PARAMETERS']
WAIT_CONDITION_PARAMETERS = config['WAIT_CONDITION_PARAMETERS']
OTHER_PARAMETERS = config['OTHER_PARAMETERS']
RED = config['RED']
ORANGE = config['ORANGE']
GREEN = config['GREEN']
BLUE = config['BLUE']
GOLD = config['GOLD']
RED_PCT = config['RED_PCT']
ORANGE_PCT = config['ORANGE_PCT']
GREEN_PCT = config['GREEN_PCT']
BLUE_PCT = config['BLUE_PCT']
CLI_OWN_MODULES = config['CLI_OWN_MODULES']
EXCLUDE_COMMANDS = config['EXCLUDE_COMMANDS']
GLOBAL_EXCLUDE_COMMANDS = config['GLOBAL_EXCLUDE_COMMANDS']


# pylint: disable=too-many-instance-attributes
Expand Down
22 changes: 12 additions & 10 deletions azdev/operations/regex.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,28 @@
import json
import os
import re
import requests
import yaml

from knack.log import get_logger
from knack.util import CLIError
from azdev.utilities.path import get_cli_repo_path

logger = get_logger(__name__)

try:
with open(os.path.join(get_cli_repo_path(), 'scripts', 'ci', 'cmdcov.yml'), 'r') as file:
config = yaml.safe_load(file)
CMD_PATTERN = config['CMD_PATTERN']
QUO_PATTERN = config['QUO_PATTERN']
END_PATTERN = config['END_PATTERN']
DOCS_END_PATTERN = config['DOCS_END_PATTERN']
NOT_END_PATTERN = config['NOT_END_PATTERN']
NUMBER_SIGN_PATTERN = config['NUMBER_SIGN_PATTERN']
except CLIError as ex:
logger.warning('Failed to load cmdcov.yml: %s, please make sure your repo contains the following file '
'https://github.com/Azure/azure-cli/blob/dev/scripts/ci/cmdcov.yml', str(ex))
# pylint: disable=broad-exception-caught
except Exception:
url = "https://raw.githubusercontent.com/Azure/azure-cli/dev/scripts/ci/cmdcov.yml"
response = requests.get(url)
config = yaml.safe_load(response.text)
CMD_PATTERN = config['CMD_PATTERN']
QUO_PATTERN = config['QUO_PATTERN']
END_PATTERN = config['END_PATTERN']
DOCS_END_PATTERN = config['DOCS_END_PATTERN']
NOT_END_PATTERN = config['NOT_END_PATTERN']
NUMBER_SIGN_PATTERN = config['NUMBER_SIGN_PATTERN']


def get_all_tested_commands_from_regex(lines):
Expand Down
60 changes: 31 additions & 29 deletions azdev/operations/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
# -----------------------------------------------------------------------------

import os
import requests
import yaml

from knack.log import get_logger
from knack.util import CLIError
from azdev.utilities.path import get_cli_repo_path
from azdev.operations.constant import (
ENCODING, GLOBAL_PARAMETERS, GENERIC_UPDATE_PARAMETERS, WAIT_CONDITION_PARAMETERS, OTHER_PARAMETERS,
Expand All @@ -21,31 +21,33 @@
try:
with open(os.path.join(get_cli_repo_path(), 'scripts', 'ci', 'cmdcov.yml'), 'r') as file:
config = yaml.safe_load(file)
print(config)
assert config['ENCODING'] == ENCODING
assert config['GLOBAL_PARAMETERS'] == GLOBAL_PARAMETERS
assert config['GENERIC_UPDATE_PARAMETERS'] == GENERIC_UPDATE_PARAMETERS
assert config['WAIT_CONDITION_PARAMETERS'] == WAIT_CONDITION_PARAMETERS
assert config['OTHER_PARAMETERS'] == OTHER_PARAMETERS
assert config['RED'] == RED
assert config['ORANGE'] == ORANGE
assert config['GREEN'] == GREEN
assert config['BLUE'] == BLUE
assert config['GOLD'] == GOLD
assert config['RED_PCT'] == RED_PCT
assert config['ORANGE_PCT'] == ORANGE_PCT
assert config['GREEN_PCT'] == GREEN_PCT
assert config['BLUE_PCT'] == BLUE_PCT
assert config['CLI_OWN_MODULES'] == CLI_OWN_MODULES
assert config['EXCLUDE_COMMANDS'] == EXCLUDE_COMMANDS
assert config['GLOBAL_EXCLUDE_COMMANDS'] == GLOBAL_EXCLUDE_COMMANDS
assert config['EXCLUDE_MODULES'] == EXCLUDE_MODULES
assert config['CMD_PATTERN'] == CMD_PATTERN
assert config['QUO_PATTERN'] == QUO_PATTERN
assert config['END_PATTERN'] == END_PATTERN
assert config['DOCS_END_PATTERN'] == DOCS_END_PATTERN
assert config['NOT_END_PATTERN'] == NOT_END_PATTERN
assert config['NUMBER_SIGN_PATTERN'] == NUMBER_SIGN_PATTERN
except CLIError as ex:
logger.warning('Failed to load cmdcov.yml: %s, please make sure your repo contains the following file '
'https://github.com/Azure/azure-cli/blob/dev/scripts/ci/cmdcov.yml', str(ex))
# pylint: disable=broad-exception-caught
except Exception:
url = "https://raw.githubusercontent.com/Azure/azure-cli/dev/scripts/ci/cmdcov.yml"
response = requests.get(url)
config = yaml.safe_load(response.text)
print(config)
assert config['ENCODING'] == ENCODING
assert config['GLOBAL_PARAMETERS'] == GLOBAL_PARAMETERS
assert config['GENERIC_UPDATE_PARAMETERS'] == GENERIC_UPDATE_PARAMETERS
assert config['WAIT_CONDITION_PARAMETERS'] == WAIT_CONDITION_PARAMETERS
assert config['OTHER_PARAMETERS'] == OTHER_PARAMETERS
assert config['RED'] == RED
assert config['ORANGE'] == ORANGE
assert config['GREEN'] == GREEN
assert config['BLUE'] == BLUE
assert config['GOLD'] == GOLD
assert config['RED_PCT'] == RED_PCT
assert config['ORANGE_PCT'] == ORANGE_PCT
assert config['GREEN_PCT'] == GREEN_PCT
assert config['BLUE_PCT'] == BLUE_PCT
assert config['CLI_OWN_MODULES'] == CLI_OWN_MODULES
assert config['EXCLUDE_COMMANDS'] == EXCLUDE_COMMANDS
assert config['GLOBAL_EXCLUDE_COMMANDS'] == GLOBAL_EXCLUDE_COMMANDS
assert config['EXCLUDE_MODULES'] == EXCLUDE_MODULES
assert config['CMD_PATTERN'] == CMD_PATTERN
assert config['QUO_PATTERN'] == QUO_PATTERN
assert config['END_PATTERN'] == END_PATTERN
assert config['DOCS_END_PATTERN'] == DOCS_END_PATTERN
assert config['NOT_END_PATTERN'] == NOT_END_PATTERN
assert config['NUMBER_SIGN_PATTERN'] == NUMBER_SIGN_PATTERN

0 comments on commit 9375065

Please sign in to comment.