Take editions into account when selecting test engine versions

Get candidates from moby/moby and docker/docker-ce repos

Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
Joffrey F 2017-06-05 19:26:37 -07:00 committed by Joffrey F
parent e8e2eb6e59
commit 821bd54663
2 changed files with 22 additions and 10 deletions

View File

@ -14,7 +14,7 @@ docker run --rm \
get_versions="docker run --rm get_versions="docker run --rm
--entrypoint=/code/.tox/py27/bin/python --entrypoint=/code/.tox/py27/bin/python
$TAG $TAG
/code/script/test/versions.py docker/docker" /code/script/test/versions.py docker/docker-ce,moby/moby"
if [ "$DOCKER_VERSIONS" == "" ]; then if [ "$DOCKER_VERSIONS" == "" ]; then
DOCKER_VERSIONS="$($get_versions default)" DOCKER_VERSIONS="$($get_versions default)"

View File

@ -37,14 +37,22 @@ import requests
GITHUB_API = 'https://api.github.com/repos' GITHUB_API = 'https://api.github.com/repos'
class Version(namedtuple('_Version', 'major minor patch rc')): class Version(namedtuple('_Version', 'major minor patch rc edition')):
@classmethod @classmethod
def parse(cls, version): def parse(cls, version):
edition = None
version = version.lstrip('v') version = version.lstrip('v')
version, _, rc = version.partition('-') version, _, rc = version.partition('-')
if rc:
if 'rc' not in rc:
edition = rc
rc = None
elif '-' in rc:
edition, rc = rc.split('-')
major, minor, patch = version.split('.', 3) major, minor, patch = version.split('.', 3)
return cls(major, minor, patch, rc) return cls(major, minor, patch, rc, edition)
@property @property
def major_minor(self): def major_minor(self):
@ -61,7 +69,8 @@ class Version(namedtuple('_Version', 'major minor patch rc')):
def __str__(self): def __str__(self):
rc = '-{}'.format(self.rc) if self.rc else '' rc = '-{}'.format(self.rc) if self.rc else ''
return '.'.join(map(str, self[:3])) + rc edition = '-{}'.format(self.edition) if self.edition else ''
return '.'.join(map(str, self[:3])) + edition + rc
def group_versions(versions): def group_versions(versions):
@ -94,6 +103,7 @@ def get_latest_versions(versions, num=1):
group. group.
""" """
versions = group_versions(versions) versions = group_versions(versions)
num = min(len(versions), num)
return [versions[index][0] for index in range(num)] return [versions[index][0] for index in range(num)]
@ -112,16 +122,18 @@ def get_versions(tags):
print("Skipping invalid tag: {name}".format(**tag), file=sys.stderr) print("Skipping invalid tag: {name}".format(**tag), file=sys.stderr)
def get_github_releases(project): def get_github_releases(projects):
"""Query the Github API for a list of version tags and return them in """Query the Github API for a list of version tags and return them in
sorted order. sorted order.
See https://developer.github.com/v3/repos/#list-tags See https://developer.github.com/v3/repos/#list-tags
""" """
versions = []
for project in projects:
url = '{}/{}/tags'.format(GITHUB_API, project) url = '{}/{}/tags'.format(GITHUB_API, project)
response = requests.get(url) response = requests.get(url)
response.raise_for_status() response.raise_for_status()
versions = get_versions(response.json()) versions.extend(get_versions(response.json()))
return sorted(versions, reverse=True, key=operator.attrgetter('order')) return sorted(versions, reverse=True, key=operator.attrgetter('order'))
@ -136,7 +148,7 @@ def parse_args(argv):
def main(argv=None): def main(argv=None):
args = parse_args(argv) args = parse_args(argv)
versions = get_github_releases(args.project) versions = get_github_releases(args.project.split(','))
if args.command == 'recent': if args.command == 'recent':
print(' '.join(map(str, get_latest_versions(versions, args.num)))) print(' '.join(map(str, get_latest_versions(versions, args.num))))