diff options
author | James Falcon <james.falcon@canonical.com> | 2022-11-21 14:13:14 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-21 13:13:14 -0700 |
commit | 47174014c09e454b452c234a118756e981f95a01 (patch) | |
tree | cabefafcc8068aae6e9cf2af0f51228cc73d93bc | |
parent | 5c1bd34e36dbce6b378e8c59d8bd105e285ddb33 (diff) | |
download | cloud-init-git-47174014c09e454b452c234a118756e981f95a01.tar.gz |
Update read-version
Use 'git describe <branch>' as the version number, even if the version
differs from what is in version.py. This means that if the most recent
commit is a tag, we'll get the tag number, otherwise we'll also show
the number of commits since the last tag on the branch.
Fix setup.py to align with PEP 440 versioning replacing trailing
hyphen beyond major.minor.patch-g<HASH> with a "+".
Additionally, did some cleanup and typing fixes on the script.
-rw-r--r-- | setup.py | 8 | ||||
-rwxr-xr-x | tools/read-version | 54 |
2 files changed, 28 insertions, 34 deletions
@@ -73,7 +73,13 @@ def in_virtualenv(): def get_version(): cmd = [sys.executable, "tools/read-version"] ver = subprocess.check_output(cmd) - return ver.decode("utf-8").strip() + version = ver.decode("utf-8").strip() + # read-version can spit out something like 22.4-15-g7f97aee24 + # which is invalid under PEP440. If we replace the first - with a + + # that should give us a valid version. + if "-" in version: + version = version.replace("-", "+", 1) + return version def read_requires(): diff --git a/tools/read-version b/tools/read-version index 9eaecb33..50f91b5d 100755 --- a/tools/read-version +++ b/tools/read-version @@ -5,10 +5,10 @@ import json import subprocess import sys -if "avoid-pep8-E402-import-not-top-of-file": - _tdir = os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) - sys.path.insert(0, _tdir) - from cloudinit import version as ci_version +_tdir = os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) +sys.path.insert(0, _tdir) + +from cloudinit import version as ci_version # noqa: E402 def tiny_p(cmd): @@ -55,13 +55,17 @@ use_tags = "--tags" in sys.argv or os.environ.get("CI_RV_TAGS") output_json = "--json" in sys.argv src_version = ci_version.version_string() -version_long = None +# upstream/MM.NN.x tracks our patch level releases so ignore trailing '.x' +major_minor_version = ".".join(src_version.split(".")[:2]) +version_long = "" # If we're performing CI for a new release branch (which our tooling creates # with an "upstream/" prefix), then we don't want to enforce strict version # matching because we know it will fail. github_ci_release_br = bool( - os.environ.get("GITHUB_HEAD_REF", "").startswith(f"upstream/{src_version}") + os.environ.get("GITHUB_HEAD_REF", "").startswith( + f"upstream/{major_minor_version}" + ) ) travis_ci_release_br = bool( os.environ.get("TRAVIS_PULL_REQUEST_BRANCH", "").startswith("upstream/") @@ -72,39 +76,25 @@ if is_gitdir(_tdir) and which("git") and not is_release_branch_ci: # This cmd can be simplified to ["git", "branch", "--show-current"] # after bionic EOL. branch_name = tiny_p(["git", "rev-parse", "--abbrev-ref", "HEAD"]).strip() - if branch_name.startswith(f"upstream/{src_version}"): + if branch_name.startswith(f"upstream/{major_minor_version}"): version = src_version - version_long = None + version_long = "" else: flags = [] if use_tags: flags = ["--tags"] - cmd = ["git", "describe", "--abbrev=8", "--match=[0-9]*"] + flags - - try: - version = tiny_p(cmd).strip() - except RuntimeError: - version = None - - if version is None or not version.startswith(src_version): - sys.stderr.write( - f"git describe version ({version}) differs from " - f"cloudinit.version ({src_version})\n" - ) - sys.stderr.write( - "Please get the latest upstream tags.\n" - "As an example, this can be done with the following:\n" - "$ git remote add upstream https://git.launchpad.net/" - "cloud-init\n" - "$ git fetch upstream --tags\n" - ) - sys.exit(1) + cmd = [ + "git", + "describe", + branch_name, + ] + flags + version = tiny_p(cmd).strip() version_long = tiny_p(cmd + ["--long"]).strip() else: version = src_version - version_long = None + version_long = "" # version is X.Y.Z[+xxx.gHASH] # version_long is None or X.Y.Z-xxx-gHASH @@ -115,7 +105,7 @@ distance = None if version_long: info = version_long.partition("-")[2] - extra = "-" + info + extra = f"-{info}" distance, commit = info.split("-") # remove the 'g' from gHASH commit = commit[1:] @@ -133,8 +123,6 @@ data = { if output_json: sys.stdout.write(json.dumps(data, indent=1) + "\n") else: - sys.stdout.write(release + "\n") + sys.stdout.write(version + "\n") sys.exit(0) - -# vi: ts=4 expandtab |