diff --git a/cmd/gorepomod/internal/git/runner.go b/cmd/gorepomod/internal/git/runner.go index dac244d58e9..5b49f9a5fef 100644 --- a/cmd/gorepomod/internal/git/runner.go +++ b/cmd/gorepomod/internal/git/runner.go @@ -258,7 +258,8 @@ func (gr *Runner) AssureOnMainBranch() error { // CheckoutMainBranch does that. func (gr *Runner) CheckoutMainBranch() error { gr.comment("checking out main branch") - return gr.runNoOut(noHarmDone, "checkout", mainBranch) + fullBranchSpec := fmt.Sprintf("%s/%s", remoteOrigin, mainBranch) + return gr.runNoOut(noHarmDone, "checkout", fullBranchSpec) } // FetchRemote does that. diff --git a/releasing/create-release.sh b/releasing/create-release.sh index 26f00c403ee..71e9fa24fdc 100755 --- a/releasing/create-release.sh +++ b/releasing/create-release.sh @@ -23,14 +23,29 @@ set -o errexit set -o nounset set -o pipefail +declare -a RELEASE_TYPES=("major" "minor" "patch") +upstream_master="master" +origin_master="master" + if [[ -z "${1-}" ]]; then echo "Usage: $0 TAG" echo " TAG: the tag to build or release, e.g. api/v1.2.3" exit 1 fi +if [[ -z "${2-}" ]]; then + echo "Release type not specified, using default value: patch" + release_type="patch" +elif [[ ! "${RELEASE_TYPES[*]}" =~ "${2}" ]]; then + echo "Unsupported release type, only input these values: major, minor, patch." + exit 1 +fi + git_tag=$1 +release_type=$2 + echo "release tag: $git_tag" +echo "release type: $release_type" # Build the release binaries for every OS/arch combination. # It builds compressed artifacts on $release_dir. @@ -81,22 +96,39 @@ function build_kustomize_binary { } function create_release { + source ./releasing/helpers.sh + git_tag=$1 # Take everything before the last slash. # This is expected to match $module. module=${git_tag%/*} + module_slugified=$(echo $module | iconv -t ascii//TRANSLIT | sed -E -e 's/[^[:alnum:]]+/-/g' -e 's/^-+|-+$//g' | tr '[:upper:]' '[:lower:]') # Take everything after the last slash. version=${git_tag##*/} + determineNextVersion $@ + + release_branch="release-${module}/${nextVersion}" + + # Create release branch release-{module}/{version} + echo "Creating release branch $release_branch..." + git fetch --tags upstream $upstream_master + git branch $release_branch $origin_master + git commit -a -m "create release branch $release_branch" || true + git push -f origin $release_branch + # Generate the changelog for this release # using the last two tags for the module changelog_file=$(mktemp) - ./releasing/compile-changelog.sh "$module" "$git_tag" "$changelog_file" + ./releasing/compile-changelog.sh "$module" "HEAD" "$changelog_file" additional_release_artifacts_arg="" + # Trigger workflow for respective modeule release + gh workflow run "release-${module_slugified}.yml" -f "release_type=${release_type}" -f "release_branch=${release_branch}" + # build `kustomize` binary if [[ "$module" == "kustomize" ]]; then release_artifact_dir=$(mktemp -d) @@ -122,6 +154,27 @@ function create_release { --notes-file "$changelog_file" } +function determineNextVersion { + currentTag=$(git tag --list "${module}*" --sort=-creatordate | head -n1) + currentVersion=$(echo ${currentTag##*/} | cut -d'v' -f2) + majorVer=$(echo $currentVersion | cut -d'.' -f1) + minorVer=$(echo $currentVersion | cut -d'.' -f2) + patchVer=$(echo $currentVersion | cut -d'.' -f3) + + if [[ ${release_type} == "major" ]]; then + majorVer="$(($majorVer + 1))" + elif [[ ${release_type} == "minor" ]]; then + minorVer="$(($minorVer + 1))" + elif [[ ${release_type} == "patch" ]]; then + patchVer="$(($patchVer + 1))" + else + echo "Error: release_type not supported. Available values 'major', 'minor', 'patch'" + exit 1 + fi + + nextVersion="$majorVer.$minorVer.$patchVer" + return +} ## create release create_release "$git_tag" diff --git a/releasing/helpers.sh b/releasing/helpers.sh index 4da68f15158..acec8eedc35 100644 --- a/releasing/helpers.sh +++ b/releasing/helpers.sh @@ -2,12 +2,20 @@ # Copyright 2022 The Kubernetes Authors. # SPDX-License-Identifier: Apache-2.0 +ORIGIN_MASTER="feat/5449-add-release-automation" +UPSTREAM_REPO="upstream" +UPSTREAM_MASTER="master" function createBranch { branch=$1 title=$2 echo "Making branch $branch : \"$title\"" - git branch -D $branch # delete if it exists + # Check if release branch exists + if git show-ref --quiet "refs/heads/${branch}"; then + git fetch --tags upstream master + git checkout $ORIGIN_MASTER + git branch -D $branch # delete if it exists + fi git checkout -b $branch git commit -a -m "$title" git push -f origin $branch