diff options
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/make-tarball | 59 | ||||
-rwxr-xr-x | tools/read-version | 81 |
2 files changed, 115 insertions, 25 deletions
diff --git a/tools/make-tarball b/tools/make-tarball index 4828a622..bd7399c1 100755 --- a/tools/make-tarball +++ b/tools/make-tarball @@ -1,16 +1,53 @@ #!/bin/sh set -e +TEMP_D="" +cleanup() { + [ -z "$TEMP_D" ] || rm -Rf "${TEMP_D}" +} +trap cleanup EXIT + +Usage() { + cat <<EOF +Usage: ${0##*/} [revision] + create a tarball of revision (default HEAD) + + options: + -o | --output FILE write to file +EOF +} + +short_opts="ho:v" +long_opts="help,output:,long,verbose" +getopt_out=$(getopt --name "${0##*/}" \ + --options "${short_opts}" --long "${long_opts}" -- "$@") && + eval set -- "${getopt_out}" || { Usage 1>&2; exit 1; } + +long_opt="" +while [ $# -ne 0 ]; do + cur=$1; next=$2 + case "$cur" in + -o|--output) output=$next; shift;; + --long) long_opt="--long";; + --) shift; break;; + esac + shift; +done + rev=${1:-HEAD} -revname=$(git describe $rev) +git_describe=$(git describe ${long_opt} $rev) -# revname could be 0.7.5 or 0.7.5-NNN-gHASH +# git_describe could be 0.7.5 or 0.7.5-NNN-gHASH # turn that into 0.7.5 or 0.7.5+NNN.gHASH -case "$revname" in - *-*) revname=$(echo "$revname" | sed -e 's/-/+/' -e 's/-/./') +case "$git_describe" in + *-*) version=$(echo "$git_describe" | sed -e 's/-/+/' -e 's/-/./');; + *) version=${git_describe};; esac -archive_base="cloud-init-$revname" +archive_base="cloud-init-$version" +if [ -z "$output" ]; then + output="$archive_base.tar.gz" +fi # when building an archiving from HEAD, ensure that there aren't any # uncomitted changes in the working directory (because these would not @@ -25,9 +62,11 @@ if [ "$rev" = HEAD ] && ! git diff-index --quiet HEAD --; then fi fi -git archive \ - --format=tar.gz \ - --prefix="$archive_base/" "$rev" \ - "--output=$archive_base.tar.gz" +git archive --format=tar --prefix="$archive_base/" "$rev" | + ( cd "$TEMP_D" && tar xpf - ) + +sed -i "s,@@EXPORT_VERSION@@,$version," "$archive_base/cloudinit/version.py" + +( cd "$TEMP_D" && tar cpzf - "$archive_base/" ) > "$output" -echo "${archive_base}.tar.gz" +echo "$output" diff --git a/tools/read-version b/tools/read-version index d02651e9..e585ab2e 100755 --- a/tools/read-version +++ b/tools/read-version @@ -1,26 +1,77 @@ #!/usr/bin/env python import os -import re +import json import sys -if 'CLOUD_INIT_TOP_D' in os.environ: - topd = os.path.realpath(os.environ.get('CLOUD_INIT_TOP_D')) -else: - topd = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) +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 + from cloudinit import util + + +use_long = '--long' in sys.argv or os.environ.get('CI_RV_LONG') +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 + +if os.path.isdir(os.path.join(_tdir, ".git")): + def fix_git_version(ver): + ver = ver.strip() + if "-" in ver: + # change X.Y.Z-1023-gHASH to X.Y.Z+1023.ghash + return "{0}+{1}.{2}".format(*ver.split("-")) + return ver + + flags = [] + if use_tags: + flags = ['--tags'] + cmd = ['git', 'describe'] + flags -for fname in ("setup.py", "ChangeLog"): - if not os.path.isfile(os.path.join(topd, fname)): - sys.stderr.write("Unable to locate '%s' file that should " - "exist in cloud-init root directory." % fname) + version = fix_git_version(util.subp(cmd)[0]) + + if not version.startswith(src_version): + sys.stderr.write("git describe version (%s) differs from " + "cloudinit.version (%s)\n" % (version, src_version)) sys.exit(1) -vermatch = re.compile(r"^[0-9]+[.][0-9]+[.][0-9]+:$") + version_long = fix_git_version(util.subp(cmd + ["--long"])[0]) +else: + version = src_version + try: + version_long = ci_version.full_version_string() + except ValueError: + pass + +# version is X.Y.Z[+xxx.gHASH] +# version_long is None or X.Y.Z+xxx.gHASH +release = version.partition("+")[0] +extra = None +commit = None +distance = None -with open(os.path.join(topd, "ChangeLog"), "r") as fp: - for line in fp: - if vermatch.match(line): - sys.stdout.write(line.strip()[:-1] + "\n") - break +if version_long: + info = version_long.partition("+")[2] + extra = "+" + info + distance, commit = info.split(".") + # remove the 'g' from gHASH + commit = commit[1:] + +data = { + 'release': release, + 'version': version, + 'version_long': version_long, + 'extra': extra, + 'commit': commit, + 'distance': distance, +} + +if output_json: + sys.stdout.write(json.dumps(data, indent=1) + "\n") +else: + sys.stdout.write(release + "\n") sys.exit(0) |