Skip to content
This repository has been archived by the owner on Jun 28, 2023. It is now read-only.

Commit

Permalink
Fix next tag to be used when cutting a release on a release branch (#…
Browse files Browse the repository at this point in the history
…4519)

Co-authored-by: github-actions <github-actions@github.com>
  • Loading branch information
davidvonthenen and github-actions authored May 17, 2022
1 parent 7e0c6f3 commit 0acd275
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
8 changes: 7 additions & 1 deletion hack/release/create-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ git config user.email github-actions@github.com
# both main and this new branch because the commit is the same

# first test the release branch because it gets priority
IS_RELEASE_BRANCH=true
WHICH_BRANCH=$(git branch -a --contains "${ACTUAL_COMMIT_SHA}" | grep remotes | grep -v -e detached -e HEAD | grep -E "\brelease-[0-9]+\.[0-9]+\b" | cut -d "/" -f3)
echo "branch: ${WHICH_BRANCH}"
if [[ "${WHICH_BRANCH}" == "" ]]; then
# now try main since the release branch doesnt exist
IS_RELEASE_BRANCH=false
WHICH_BRANCH=$(git branch -a --contains "${ACTUAL_COMMIT_SHA}" | grep remotes | grep -v -e detached -e HEAD | grep -E "\bmain\b" | cut -d "/" -f3)
echo "branch: ${WHICH_BRANCH}"
if [[ "${WHICH_BRANCH}" == "" ]]; then
Expand All @@ -58,7 +60,11 @@ git pull origin "${WHICH_BRANCH}"
pushd "./hack/release/release" || exit 1

PREVIOUS_VERSION=$(cat ../../PREVIOUS_VERSION)
go run ./release.go -previous "${PREVIOUS_VERSION}" -tag "${BUILD_VERSION}"
if [[ "${IS_RELEASE_BRANCH}" == true ]]; then
go run ./release.go -previous "${PREVIOUS_VERSION}" -tag "${BUILD_VERSION}" -relbranch
else
go run ./release.go -previous "${PREVIOUS_VERSION}" -tag "${BUILD_VERSION}"
fi

popd || exit 1

Expand Down
15 changes: 9 additions & 6 deletions hack/release/release/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ func getDraftRelease(client *github.Client, tag string) (*github.RepositoryRelea
}

// update Release version
func newRelease(current string) error {
func newRelease(current string, relbranch bool) error {
fmt.Printf("tag: %s\n", current)

newVersion, err := incrementRelease(current)
newVersion, err := incrementRelease(current, relbranch)
if err != nil {
fmt.Printf("incrementRelease failed. Err: %v\n", err)
return err
Expand Down Expand Up @@ -187,7 +187,7 @@ func bumpRelease(current string) error {
}

// helper Release functions
func incrementRelease(tag string) (string, error) {
func incrementRelease(tag string, relbranch bool) (string, error) {
items := strings.Split(tag, ".")
if len(items) != NumberOfSemVerSeparators {
fmt.Printf("Split version failed\n")
Expand All @@ -208,7 +208,7 @@ func incrementRelease(tag string) (string, error) {

// are we on a release branch (ie vX.Y.[0-9]+)? then increment the patch version
// otherwise, this is a minor release and increment the minor version
if iPatch > 0 {
if relbranch {
iPatch++
} else {
iMinor++
Expand Down Expand Up @@ -344,6 +344,9 @@ func main() {
var skip bool
flag.BoolVar(&skip, "skip", false, "Skip making changes to draft release")

var relbranch bool
flag.BoolVar(&relbranch, "relbranch", false, "We are on a release branch")

flag.Parse()
// flags

Expand All @@ -366,7 +369,7 @@ func main() {
return
}

err = newRelease(tag)
err = newRelease(tag, relbranch)
if err != nil {
fmt.Printf("newRelease failed. Err: %v\n", err)
return
Expand All @@ -381,7 +384,7 @@ func main() {

err = bumpRelease(tag)
if err != nil {
fmt.Printf("newRelease failed. Err: %v\n", err)
fmt.Printf("bumpRelease failed. Err: %v\n", err)
return
}
}
Expand Down

0 comments on commit 0acd275

Please sign in to comment.