diff --git a/hack/release/create-release.sh b/hack/release/create-release.sh index 3738fa020f..63a57bd40e 100755 --- a/hack/release/create-release.sh +++ b/hack/release/create-release.sh @@ -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 @@ -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 diff --git a/hack/release/release/release.go b/hack/release/release/release.go index a147f2cfa8..e881a5a50c 100644 --- a/hack/release/release/release.go +++ b/hack/release/release/release.go @@ -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 @@ -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") @@ -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++ @@ -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 @@ -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 @@ -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 } }