Skip to content

Commit

Permalink
build: INFENG-926: Fix version.sh version string output (#10085)
Browse files Browse the repository at this point in the history
This fixes a bug in version.sh that would cause an invalid local version
string to be output under certain circumstances; specifically, if a tag
were made on a commit that was not on the current branch (i.e. reachable
with git-describe). This took a code path in version.sh that did not
properly remove any existing tag +metadata with grep, leading to version
strings like 0.751.0+dryrun+27a014b44. Note the extra plus sign
(+). This causes downstream tools, like helm, to fail.

Now, we remove any existing version metadata from the final for all code
paths.

This also changes all instances of \d character classes to [0-9]. This
fixes a cross-platform issue where BSD grep's -E includes \d classes,
while GNU grep's -E does not. This means the script worked fine on
macOS, but broke subtly in CI (and I suppose on anyone's work machine
that uses Linux). We avoid this entirely by falling back to standard
character sets.
  • Loading branch information
davidfluck-hpe authored Oct 21, 2024
1 parent 04861dd commit 4afc15f
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ fi
if [[ -z ${VERSION} ]]; then
# Check if this branch has any tags (typically, only release branches will
# have tags).
MAYBE_TAG=$(git describe --tags --abbrev=0 2>/dev/null | grep -Eo 'v?\d+\.\d+\.\d+')
MAYBE_TAG=$(git describe --tags --abbrev=0 2>/dev/null)
SHA=$(git rev-parse --short HEAD)

# No tag on current branch.
Expand All @@ -92,6 +92,16 @@ if [[ -z ${VERSION} ]]; then
)
fi

# Filter out additional +metadata from the tag, should it
# exist. This prevents version strings like
# 0.751.0+dryrun+27a014b44.
# Note: we use [0-9] instead of \d here, because while BSD grep's
# -E includes the \d character class, GNU grep's -E does not. This
# means using \d on macOS will work fine, but it will break on
# Linux (and thus, CI). To avoid this, we fall back to standard
# character sets.
MAYBE_TAG=$(grep -Eo 'v?[0-9]+\.[0-9]+\.[0-9]+' <(printf "%s" "$MAYBE_TAG"))

# Munge the tag into the form we want. Note: we always append a SHA hash,
# even if we're on the commit with the tag. This is partially because I feel
# like it will be more consistent and result in fewer surprises, but also it
Expand Down

0 comments on commit 4afc15f

Please sign in to comment.