Skip to content

Commit

Permalink
Verify package versions with last CLI release (as well as pyPI) (#6066)
Browse files Browse the repository at this point in the history
* Use appropriate git revision range to prevent asking users to rebase

* Check version using last released tag as well

* Change clone url

* Add TEST code change that should fail CI

* Verified that it works

* test

* Use git diff instead

* make change

* Fix revision now that we are using diff instead of log
  • Loading branch information
derekbekoe authored Apr 10, 2018
1 parent 7888fad commit 44771ac
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 25 deletions.
8 changes: 6 additions & 2 deletions scripts/ci/precheck_header.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

set -e
set -ex

pip install -e ./tools

Expand All @@ -16,6 +16,10 @@ python -m automation.tests.verify_readme_history
# Only verify package version or PRs to Azure/azure-cli (not other forks)
if [ $TRAVIS_EVENT_TYPE == "pull_request" ] && [ $TRAVIS_REPO_SLUG == "Azure/azure-cli" ]; then
echo "Verify package versions"
python -m automation.tests.verify_package_versions
latestCliReleaseTag=$(git describe --tags `git rev-list --tags='azure-cli-*' --max-count=1`)
latestCliReleaseDir=$(mktemp -d)
echo "Latest CLI release tag $latestCliReleaseTag"
git clone -c advice.detachedHead=False https://github.com/$TRAVIS_REPO_SLUG --branch $latestCliReleaseTag $latestCliReleaseDir
python -m automation.tests.verify_package_versions --base-repo $latestCliReleaseDir --base-tag $latestCliReleaseTag
fi

65 changes: 42 additions & 23 deletions tools/automation/tests/verify_package_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import argparse
import subprocess

from ..utilities.path import get_all_module_paths
from ..utilities.path import get_all_module_paths, get_repo_root
from ..utilities.display import print_heading
from ..utilities.pypi import is_available_on_pypi

Expand All @@ -31,41 +31,57 @@ def contains_no_plus_dev(mod_version):
return True


def changes_require_version_bump(mod_name, mod_version, mod_path):
def changes_require_version_bump(mod_name, mod_version, mod_path, base_repo=None, base_tag=None):
revision_range = os.environ.get('TRAVIS_COMMIT_RANGE', None)
if revision_range:
cmd = ["git", "log", "--pretty=format:* %s", revision_range, "--", mod_path, ":(exclude)*/tests/*"]
cmd = ["git", "diff", revision_range, "--", mod_path, ":(exclude)*/tests/*"]
print('Executing: {}'.format(' '.join(cmd)))
changes = subprocess.check_output(cmd, cwd=mod_path, universal_newlines=True).strip()
if changes and is_available_on_pypi(mod_name, mod_version):
print("There are changes to {} and the current version {} is already available on PyPI! "
"Bump the version.".format(mod_name, mod_version))
print("Changes are as follows:")
print(changes)
return False
else:
return True
else:
# There's no revision range so we'll ignore this check
if changes:
if is_available_on_pypi(mod_name, mod_version):
print("There are changes to {} and the current version {} is already available on PyPI! "
"Bump the version.".format(mod_name, mod_version))
print("Changes are as follows:")
print(changes)
return False
elif base_repo and version_in_base_repo(base_repo, mod_path, mod_name, mod_version):
print("There are changes to {} and the current version {} is already used at tag {}. "
"Bump the version.".format(mod_name, mod_version, base_tag))
print("Changes are as follows:")
print(changes)
return False
return True


def version_in_base_repo(base_repo, mod_path, mod_name, mod_version):
base_repo_mod_path = mod_path.replace(get_repo_root(), base_repo)
if mod_version == _get_mod_version(base_repo_mod_path):
print('Version {} of {} is already used on in the base repo.'.format(mod_version, mod_name))
return True
return False


def _get_mod_version(mod_path):
return subprocess.check_output(['python', 'setup.py', '--version'], cwd=mod_path,
universal_newlines=True).strip()


def check_package_version(mod_name, mod_path):
mod_version = subprocess.check_output('python setup.py --version'.split(), cwd=mod_path,
universal_newlines=True).strip()
def check_package_version(mod_name, mod_path, base_repo=None, base_tag=None):
mod_version = _get_mod_version(mod_path)
checks = []
if mod_name in ['azure-cli', 'azure-cli-core']:
checks.append(is_unreleased_version(mod_name, mod_version))
checks.append(contains_no_plus_dev(mod_version))
checks.append(changes_require_version_bump(mod_name, mod_version, mod_path))
checks.append(changes_require_version_bump(mod_name, mod_version, mod_path, base_repo=base_repo, base_tag=base_tag))
return all(checks)


def verify_all():
def verify_all(base_repo=None, base_tag=None):
all_paths = get_all_module_paths()
all_ok = []
failed_mods = []
for p in all_paths:
res = check_package_version(p[0], p[1])
res = check_package_version(p[0], p[1], base_repo=base_repo, base_tag=base_tag)
if not res:
failed_mods.append(p[0])
print('Error(s) on {}'.format(p[0]))
Expand All @@ -79,12 +95,12 @@ def verify_all():
print('Verified versions of all modules successfully.', file=sys.stderr)


def verify_one(mod_name):
def verify_one(mod_name, base_repo=None, base_tag=None):
p = [path for name, path in get_all_module_paths() if name == mod_name]
if not p:
print('Module not found.', file=sys.stderr)
sys.exit(1)
res = check_package_version(mod_name, p[0])
res = check_package_version(mod_name, p[0], base_repo=base_repo, base_tag=base_tag)
if not res:
print_heading('Error whilst verifying version of {}!'.format(mod_name))
print('See above for the full warning/errors.')
Expand All @@ -95,8 +111,11 @@ def verify_one(mod_name):
parser = argparse.ArgumentParser(
description="Verify package versions")
parser.add_argument('--module', '-m', required=False, help="The module you want to verify.")
parser.add_argument('--base-repo', required=False, help="Path to directory containing the CLI repo with "\
"the base versions to compare against.")
parser.add_argument('--base-tag', required=False, help="A tag that represents the base repo (e.g. the Git tag)")
args = parser.parse_args()
if args.module:
verify_one(args.module)
verify_one(args.module, base_repo=args.base_repo, base_tag=args.base_tag)
else:
verify_all()
verify_all(base_repo=args.base_repo, base_tag=args.base_tag)

0 comments on commit 44771ac

Please sign in to comment.