Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions sdk_lib/sdk_container_common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,19 @@ function yell() {
# Guess the SDK version from the current git commit.
#
function get_git_version() {
local tag="$(git tag --points-at HEAD)"
# A single commit can carry more than one tag (e.g. two ACL releases cut
# from the same commit). Callers expect a single-line version string -- a
# multi-line one leaks into the versionfile and into derived docker
# container names, which docker then rejects. Pick the highest version tag
# deterministically.
# 'git for-each-ref' does the selection itself, so no pipeline is needed and
# a git failure is not masked by the exit status of a trailing 'tail'.
local tag
tag="$(git for-each-ref --count=1 --sort='-v:refname' \
--format='%(refname:short)' --points-at=HEAD 'refs/tags/*')"
if [ -z "$tag" ] ; then
# 'git describe' always prints a single line; leave it unpiped so its
# exit status still propagates to the caller.
git describe --tags
else
Comment thread
jiria marked this conversation as resolved.
echo "$tag"
Expand Down Expand Up @@ -89,7 +100,9 @@ function build_id_from_version() {
local version="$1"

# support vernums and versions ("alpha-"... is optional)
echo "${version}" | sed -n 's/^\([a-z]\+-\)\?[0-9.]\+[-+]\(.*\)$/\2/p'
# 'sed -n ...p' prints one line per match, so clamp to a single line to
# guarantee callers never get a multi-line version fragment.
echo "${version}" | sed -n 's/^\([a-z]\+-\)\?[0-9.]\+[-+]\(.*\)$/\2/p' | head -n 1
}
# --

Expand Down Expand Up @@ -118,7 +131,9 @@ function vernum_from_version() {
local version="$1"

# support vernums and versions ("alpha-"... is optional)
echo "${version}" | sed -n 's/^\([a-z]\+-\)\?\([0-9.]\+\).*/\2/p'
# 'sed -n ...p' prints one line per match, so clamp to a single line to
# guarantee callers never get a multi-line version fragment.
echo "${version}" | sed -n 's/^\([a-z]\+-\)\?\([0-9.]\+\).*/\2/p' | head -n 1
}
# --

Expand Down
Loading