Skip to content

Commit

Permalink
Merge pull request #2359 from reubenmiller/feat-build-version-on-prs
Browse files Browse the repository at this point in the history
build: use fallback version when git describe only returns a hash
  • Loading branch information
reubenmiller authored Oct 23, 2023
2 parents f96086d + 8ede8f0 commit e9dd11d
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions ci/build_scripts/version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,6 @@ next_base_version() {
echo "${major}.${minor}.${patch}"
}

parse_version() {
git describe --always --tags --abbrev=7 2>/dev/null || true
}

set_version_variables() {

BUILD_COMMITS_SINCE=
Expand All @@ -84,9 +80,23 @@ set_version_variables() {

if [ -z "$GIT_SEMVER" ]; then
GIT_DESCRIBE_RAW=$(git describe --always --tags --abbrev=7 2>/dev/null || true)
BASE_VERSION=$(echo "$GIT_DESCRIBE_RAW" | cut -d- -f1)
BUILD_COMMITS_SINCE=$(echo "$GIT_DESCRIBE_RAW" | cut -d- -f2)
BUILD_COMMIT_HASH=$(echo "$GIT_DESCRIBE_RAW" | cut -d- -f3)

if [[ "$GIT_DESCRIBE_RAW" =~ ^[a-z0-9]+$ ]]; then
# Note: Sometimes git describe only prints out the git hash when run on a PR branch
# from someone else. In such instances this causes the version to be incompatible with
# linux package types. For instance, debian versions must start with a digit.
# When this situation is detected, git describe is run on the main branch however the
# git hash is replaced with the current git hash of the current branch.
echo "Using git describe from origin/main as detec" >&2
BUILD_COMMIT_HASH="g$GIT_DESCRIBE_RAW"
GIT_DESCRIBE_RAW=$(git describe --always --tags --abbrev=7 origin/main 2>/dev/null || true)
BASE_VERSION=$(echo "$GIT_DESCRIBE_RAW" | cut -d- -f1)
BUILD_COMMITS_SINCE=$(echo "$GIT_DESCRIBE_RAW" | cut -d- -f2)
else
BASE_VERSION=$(echo "$GIT_DESCRIBE_RAW" | cut -d- -f1)
BUILD_COMMITS_SINCE=$(echo "$GIT_DESCRIBE_RAW" | cut -d- -f2)
BUILD_COMMIT_HASH=$(echo "$GIT_DESCRIBE_RAW" | cut -d- -f3)
fi
BUMP_VERSION=1
else
echo "Using version set by user: $GIT_SEMVER" >&2
Expand Down

1 comment on commit e9dd11d

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Robot Results

✅ Passed ❌ Failed ⏭️ Skipped Total Pass % ⏱️ Duration
321 0 3 321 100 51m37.109s

Please sign in to comment.