Skip to content

Commit 50dc813

Browse files
ncappsantoooks
authored andcommitted
Add buildMetadata task and ref (#5511)
* Add buildMetadata task and ref Move build metadata tasks, draft buildMetadata reference Clean up buildMetadata ref Add managed by label task Add local non-generated task Add local generated resource Add remote generator task Clean up tasks and ref Add local transformer annotation example Add local and remote transformer example * Address PR feedback and general cleanup cherrypick updates from feature branch fix script fix release script
1 parent d514df3 commit 50dc813

File tree

3 files changed

+65
-3
lines changed

3 files changed

+65
-3
lines changed

cmd/gorepomod/internal/git/runner.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,8 @@ func (gr *Runner) AssureOnMainBranch() error {
258258
// CheckoutMainBranch does that.
259259
func (gr *Runner) CheckoutMainBranch() error {
260260
gr.comment("checking out main branch")
261-
return gr.runNoOut(noHarmDone, "checkout", mainBranch)
261+
fullBranchSpec := fmt.Sprintf("%s/%s", remoteOrigin, mainBranch)
262+
return gr.runNoOut(noHarmDone, "checkout", fullBranchSpec)
262263
}
263264

264265
// FetchRemote does that.

releasing/create-release.sh

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,29 @@ set -o errexit
2323
set -o nounset
2424
set -o pipefail
2525

26+
declare -a RELEASE_TYPES=("major" "minor" "patch")
27+
upstream_master="master"
28+
origin_master="master"
29+
2630
if [[ -z "${1-}" ]]; then
2731
echo "Usage: $0 TAG"
2832
echo " TAG: the tag to build or release, e.g. api/v1.2.3"
2933
exit 1
3034
fi
3135

36+
if [[ -z "${2-}" ]]; then
37+
echo "Release type not specified, using default value: patch"
38+
release_type="patch"
39+
elif [[ ! "${RELEASE_TYPES[*]}" =~ "${2}" ]]; then
40+
echo "Unsupported release type, only input these values: major, minor, patch."
41+
exit 1
42+
fi
43+
3244
git_tag=$1
45+
release_type=$2
46+
3347
echo "release tag: $git_tag"
48+
echo "release type: $release_type"
3449

3550
# Build the release binaries for every OS/arch combination.
3651
# It builds compressed artifacts on $release_dir.
@@ -81,22 +96,39 @@ function build_kustomize_binary {
8196
}
8297

8398
function create_release {
99+
source ./releasing/helpers.sh
100+
84101
git_tag=$1
85102

86103
# Take everything before the last slash.
87104
# This is expected to match $module.
88105
module=${git_tag%/*}
106+
module_slugified=$(echo $module | iconv -t ascii//TRANSLIT | sed -E -e 's/[^[:alnum:]]+/-/g' -e 's/^-+|-+$//g' | tr '[:upper:]' '[:lower:]')
89107

90108
# Take everything after the last slash.
91109
version=${git_tag##*/}
92110

111+
determineNextVersion $@
112+
113+
release_branch="release-${module}/${nextVersion}"
114+
115+
# Create release branch release-{module}/{version}
116+
echo "Creating release branch $release_branch..."
117+
git fetch --tags upstream $upstream_master
118+
git branch $release_branch $origin_master
119+
git commit -a -m "create release branch $release_branch" || true
120+
git push -f origin $release_branch
121+
93122
# Generate the changelog for this release
94123
# using the last two tags for the module
95124
changelog_file=$(mktemp)
96-
./releasing/compile-changelog.sh "$module" "$git_tag" "$changelog_file"
125+
./releasing/compile-changelog.sh "$module" "HEAD" "$changelog_file"
97126

98127
additional_release_artifacts_arg=""
99128

129+
# Trigger workflow for respective modeule release
130+
gh workflow run "release-${module_slugified}.yml" -f "release_type=${release_type}" -f "release_branch=${release_branch}"
131+
100132
# build `kustomize` binary
101133
if [[ "$module" == "kustomize" ]]; then
102134
release_artifact_dir=$(mktemp -d)
@@ -122,6 +154,27 @@ function create_release {
122154
--notes-file "$changelog_file"
123155
}
124156

157+
function determineNextVersion {
158+
currentTag=$(git tag --list "${module}*" --sort=-creatordate | head -n1)
159+
currentVersion=$(echo ${currentTag##*/} | cut -d'v' -f2)
160+
majorVer=$(echo $currentVersion | cut -d'.' -f1)
161+
minorVer=$(echo $currentVersion | cut -d'.' -f2)
162+
patchVer=$(echo $currentVersion | cut -d'.' -f3)
163+
164+
if [[ ${release_type} == "major" ]]; then
165+
majorVer="$(($majorVer + 1))"
166+
elif [[ ${release_type} == "minor" ]]; then
167+
minorVer="$(($minorVer + 1))"
168+
elif [[ ${release_type} == "patch" ]]; then
169+
patchVer="$(($patchVer + 1))"
170+
else
171+
echo "Error: release_type not supported. Available values 'major', 'minor', 'patch'"
172+
exit 1
173+
fi
174+
175+
nextVersion="$majorVer.$minorVer.$patchVer"
176+
return
177+
}
125178

126179
## create release
127180
create_release "$git_tag"

releasing/helpers.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,20 @@
22
# Copyright 2022 The Kubernetes Authors.
33
# SPDX-License-Identifier: Apache-2.0
44

5+
ORIGIN_MASTER="feat/5449-add-release-automation"
6+
UPSTREAM_REPO="upstream"
7+
UPSTREAM_MASTER="master"
58

69
function createBranch {
710
branch=$1
811
title=$2
912
echo "Making branch $branch : \"$title\""
10-
git branch -D $branch # delete if it exists
13+
# Check if release branch exists
14+
if git show-ref --quiet "refs/heads/${branch}"; then
15+
git fetch --tags upstream master
16+
git checkout $ORIGIN_MASTER
17+
git branch -D $branch # delete if it exists
18+
fi
1119
git checkout -b $branch
1220
git commit -a -m "$title"
1321
git push -f origin $branch

0 commit comments

Comments
 (0)