Skip to content

Commit

Permalink
Add buildMetadata task and ref (kubernetes-sigs#5511)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ncapps authored and antoooks committed Mar 24, 2024
1 parent 4b3c0f1 commit 3443e19
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 3 deletions.
3 changes: 2 additions & 1 deletion cmd/gorepomod/internal/git/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
55 changes: 54 additions & 1 deletion releasing/create-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand All @@ -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"
10 changes: 9 additions & 1 deletion releasing/helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3443e19

Please sign in to comment.