Skip to content

Commit

Permalink
Fix git branch detection in release scripts
Browse files Browse the repository at this point in the history
Previously the code failed when the repository was in detached HEAD state (e.g. on CI).
  • Loading branch information
fweikert committed May 16, 2024
1 parent 3fddc7f commit 4c32232
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions scripts/release/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function __git_commit_subject() {

# Returns the branch name of the current git repository
function git_get_branch() {
git symbolic-ref --short HEAD
git symbolic-ref --short HEAD 2>/dev/null || git branch --remote --contains | cut -d "/" -f2
}

# Returns the tag name of the current git repository
Expand All @@ -57,14 +57,14 @@ function git_commit_msg() {
# Extract the release candidate number from the git branch name
function get_release_candidate() {
# Match rcX and return X
git_get_branch 2>/dev/null | grep -Po "(?<=rc)([0-9]|\.)*$" || true
git_get_branch | grep -Po "(?<=rc)([0-9]|\.)*$" || true
}

# Extract the release name from the git branch name
function get_release_name() {
# Match branch name release-X.X.X[-pre.XXXXXXXX.X]rcY and return X.X.X[-pre.XXXXXXXX.X]
# or match tag name X.X.X[-pre.XXXXXXXX.X] and return X.X.X[-pre.XXXXXXXX.X]
git_get_branch 2>/dev/null | grep -Po "(?<=release-)([0-9]|\.)*(-pre\.[0-9]{8}(\.[0-9]+){1,2})?(?=rc)?" || git_get_tag | grep -Po "^([0-9]|\.)*(-pre\.[0-9]{8}(\.[0-9]+){1,2})?$" || true
git_get_branch | grep -Po "(?<=release-)([0-9]|\.)*(-pre\.[0-9]{8}(\.[0-9]+){1,2})?(?=rc)?" || git_get_tag | grep -Po "^([0-9]|\.)*(-pre\.[0-9]{8}(\.[0-9]+){1,2})?$" || true
}

# Returns whether this is a rolling release (or an RCs of one)
Expand Down

0 comments on commit 4c32232

Please sign in to comment.