Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix git branch detection in release scripts #22405

Closed
wants to merge 2 commits into from
Closed
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
9 changes: 6 additions & 3 deletions scripts/release/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ function __git_commit_subject() {

# Returns the branch name of the current git repository
function git_get_branch() {
git symbolic-ref --short HEAD
# Case 1 works when a release branch was checked out,
# whereas the second case works if we're in "detached HEAD" state,
# which can happen on CI.
git symbolic-ref --short HEAD 2>/dev/null || git branch --remote --contains | cut -d "/" -f2
fweikert marked this conversation as resolved.
Show resolved Hide resolved
}

# Returns the tag name of the current git repository
Expand All @@ -57,14 +60,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
Loading