From 50dc813731f7b9d87fc1246a7248fb2e662283f4 Mon Sep 17 00:00:00 2001 From: Nick <10539313+ncapps@users.noreply.github.com> Date: Fri, 26 Jan 2024 15:12:39 -0800 Subject: [PATCH 01/10] 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 --- cmd/gorepomod/internal/git/runner.go | 3 +- releasing/create-release.sh | 55 +++++++++++++++++++++++++++- releasing/helpers.sh | 10 ++++- 3 files changed, 65 insertions(+), 3 deletions(-) diff --git a/cmd/gorepomod/internal/git/runner.go b/cmd/gorepomod/internal/git/runner.go index dac244d58e..5b49f9a5fe 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 26f00c403e..71e9fa24fd 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 4da68f1515..acec8eedc3 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 From 931f924189c06b9e421f5f07d01a4c1615bf76bd Mon Sep 17 00:00:00 2001 From: Kurnianto Trilaksono Date: Sun, 24 Mar 2024 15:22:04 +0800 Subject: [PATCH 02/10] add helper script for releasing --- releasing/check-release-helper.sh | 40 +++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100755 releasing/check-release-helper.sh diff --git a/releasing/check-release-helper.sh b/releasing/check-release-helper.sh new file mode 100755 index 0000000000..2ae9c7ca15 --- /dev/null +++ b/releasing/check-release-helper.sh @@ -0,0 +1,40 @@ +#!/usr/bin/env bash + +declare PATCH=false +declare MINOR=false +declare MAJOR=false +declare rc=0 + +git log $(git describe --tags --abbrev=0)..HEAD --oneline | tee /tmp/release-changelogs.txt + +if [[ $(cat /tmp/release-changelogs.txt | grep fix) || $(cat /tmp/release-changelogs.txt | grep patch) ]]; then + PATCH=true +fi + +if [[ $(cat /tmp/release-changelogs.txt | grep feat) ]]; then + MINOR=true +fi + +for f in $(find api); do + git diff --exit-code "${f}" + if [ $? -eq 1 ]; then + echo "Found changes on api dir at ${f}" + rc=1 + exit 1 + fi +done + +if [ $rc -eq 1 ]; then + MAJOR=true +fi + +echo -e "\n" +echo -e "=================================================================================" + +if [[ $MAJOR == false && $MINOR == false ]]; then + echo "Release type: patch" +elif [[ $MAJOR == false && $MINOR == true ]]; then + echo "Release type: minor" +else + echo "Release type: major" +fi \ No newline at end of file From a7de0cc8cd0aeae86c1d94cbe1f3cf757057fbd4 Mon Sep 17 00:00:00 2001 From: Kurnianto Trilaksono Date: Wed, 27 Mar 2024 00:11:53 +0800 Subject: [PATCH 03/10] edit printout --- releasing/check-release-helper.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/releasing/check-release-helper.sh b/releasing/check-release-helper.sh index 2ae9c7ca15..bcac82eec3 100755 --- a/releasing/check-release-helper.sh +++ b/releasing/check-release-helper.sh @@ -7,7 +7,7 @@ declare rc=0 git log $(git describe --tags --abbrev=0)..HEAD --oneline | tee /tmp/release-changelogs.txt -if [[ $(cat /tmp/release-changelogs.txt | grep fix) || $(cat /tmp/release-changelogs.txt | grep patch) ]]; then +if [[ $(cat /tmp/release-changelogs.txt | grep fix) || $(cat /tmp/release-changelogs.txt | grep patch) || $(cat /tmp/release-changelogs.txt | grep chore) ]]; then PATCH=true fi @@ -32,9 +32,9 @@ echo -e "\n" echo -e "=================================================================================" if [[ $MAJOR == false && $MINOR == false ]]; then - echo "Release type: patch" + echo "Recommended release type: patch" elif [[ $MAJOR == false && $MINOR == true ]]; then - echo "Release type: minor" + echo "Recommended release type: minor" else - echo "Release type: major" + echo "Recommended release type: major" fi \ No newline at end of file From fbc102dbd38cd4a2b9859a65378cb2a399adf97b Mon Sep 17 00:00:00 2001 From: Kurnianto Trilaksono Date: Wed, 27 Mar 2024 00:15:00 +0800 Subject: [PATCH 04/10] add change counter --- releasing/check-release-helper.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/releasing/check-release-helper.sh b/releasing/check-release-helper.sh index bcac82eec3..d902d3fe78 100755 --- a/releasing/check-release-helper.sh +++ b/releasing/check-release-helper.sh @@ -7,6 +7,8 @@ declare rc=0 git log $(git describe --tags --abbrev=0)..HEAD --oneline | tee /tmp/release-changelogs.txt +count=$(cat /tmp/release-changelogs.txt | wc -l) + if [[ $(cat /tmp/release-changelogs.txt | grep fix) || $(cat /tmp/release-changelogs.txt | grep patch) || $(cat /tmp/release-changelogs.txt | grep chore) ]]; then PATCH=true fi @@ -30,7 +32,7 @@ fi echo -e "\n" echo -e "=================================================================================" - +echo "Change counter: $(echo $count | tr -s ' ')" if [[ $MAJOR == false && $MINOR == false ]]; then echo "Recommended release type: patch" elif [[ $MAJOR == false && $MINOR == true ]]; then From 846d3c09ebf7bee7d22da8a2ddf87e79353f87dc Mon Sep 17 00:00:00 2001 From: Kurnianto Trilaksono Date: Wed, 27 Mar 2024 00:16:03 +0800 Subject: [PATCH 05/10] fix logic --- releasing/check-release-helper.sh | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/releasing/check-release-helper.sh b/releasing/check-release-helper.sh index d902d3fe78..f90effb7f2 100755 --- a/releasing/check-release-helper.sh +++ b/releasing/check-release-helper.sh @@ -21,15 +21,10 @@ for f in $(find api); do git diff --exit-code "${f}" if [ $? -eq 1 ]; then echo "Found changes on api dir at ${f}" - rc=1 - exit 1 + MAJOR=true fi done -if [ $rc -eq 1 ]; then - MAJOR=true -fi - echo -e "\n" echo -e "=================================================================================" echo "Change counter: $(echo $count | tr -s ' ')" From 3d840a65848fedc151089a6d2ae3141d08d682d4 Mon Sep 17 00:00:00 2001 From: Kurnianto Trilaksono Date: Wed, 27 Mar 2024 23:56:57 +0800 Subject: [PATCH 06/10] revert untouched files --- cmd/gorepomod/internal/git/runner.go | 3 +-- releasing/helpers.sh | 10 +--------- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/cmd/gorepomod/internal/git/runner.go b/cmd/gorepomod/internal/git/runner.go index 5b49f9a5fe..dac244d58e 100644 --- a/cmd/gorepomod/internal/git/runner.go +++ b/cmd/gorepomod/internal/git/runner.go @@ -258,8 +258,7 @@ func (gr *Runner) AssureOnMainBranch() error { // CheckoutMainBranch does that. func (gr *Runner) CheckoutMainBranch() error { gr.comment("checking out main branch") - fullBranchSpec := fmt.Sprintf("%s/%s", remoteOrigin, mainBranch) - return gr.runNoOut(noHarmDone, "checkout", fullBranchSpec) + return gr.runNoOut(noHarmDone, "checkout", mainBranch) } // FetchRemote does that. diff --git a/releasing/helpers.sh b/releasing/helpers.sh index acec8eedc3..4da68f1515 100644 --- a/releasing/helpers.sh +++ b/releasing/helpers.sh @@ -2,20 +2,12 @@ # 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\"" - # 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 branch -D $branch # delete if it exists git checkout -b $branch git commit -a -m "$title" git push -f origin $branch From f63e919e3e26f9fe2cb945806f1cab8ba38ae93f Mon Sep 17 00:00:00 2001 From: Kurnianto Trilaksono Date: Thu, 28 Mar 2024 00:01:40 +0800 Subject: [PATCH 07/10] revert untouched file --- releasing/create-release.sh | 55 +------------------------------------ 1 file changed, 1 insertion(+), 54 deletions(-) diff --git a/releasing/create-release.sh b/releasing/create-release.sh index 71e9fa24fd..26f00c403e 100755 --- a/releasing/create-release.sh +++ b/releasing/create-release.sh @@ -23,29 +23,14 @@ 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. @@ -96,39 +81,22 @@ 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" "HEAD" "$changelog_file" + ./releasing/compile-changelog.sh "$module" "$git_tag" "$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) @@ -154,27 +122,6 @@ 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" From 63329d175a0e09cecb79cc13b866893a918ff531 Mon Sep 17 00:00:00 2001 From: Kurnianto Trilaksono Date: Fri, 29 Mar 2024 16:49:10 +0800 Subject: [PATCH 08/10] fix logic and add license --- releasing/check-release-helper.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/releasing/check-release-helper.sh b/releasing/check-release-helper.sh index f90effb7f2..ae4e6ee68c 100755 --- a/releasing/check-release-helper.sh +++ b/releasing/check-release-helper.sh @@ -1,11 +1,17 @@ #!/usr/bin/env bash +# Copyright 2024 The Kubernetes Authors. +# SPDX-License-Identifier: Apache-2.0 + declare PATCH=false declare MINOR=false declare MAJOR=false declare rc=0 -git log $(git describe --tags --abbrev=0)..HEAD --oneline | tee /tmp/release-changelogs.txt +ORIGIN_MASTER="origin/master" +LATEST_TAG=$(git describe --tags --abbrev=0) + +git log "${LATEST_TAG}..HEAD" --oneline | tee /tmp/release-changelogs.txt count=$(cat /tmp/release-changelogs.txt | wc -l) @@ -18,7 +24,7 @@ if [[ $(cat /tmp/release-changelogs.txt | grep feat) ]]; then fi for f in $(find api); do - git diff --exit-code "${f}" + git diff "${LATEST_TAG}...${ORIGIN_MASTER}" --exit-code -- "${f}" if [ $? -eq 1 ]; then echo "Found changes on api dir at ${f}" MAJOR=true From 25c7e17fb81610ddb5d3bc959aaa2eb2c6d92619 Mon Sep 17 00:00:00 2001 From: Kurnianto Trilaksono Date: Wed, 24 Apr 2024 20:30:34 +0800 Subject: [PATCH 09/10] add pr rules, fix script --- CONTRIBUTING.md | 27 ++++++++++++++++++++++++++- releasing/check-release-helper.sh | 9 ++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ae8af9b58c..09e42469fc 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -75,14 +75,39 @@ cd kustomize git push origin myfeature ``` +### Pull Request Rules + +We are using [Conventional Commits v1.0.0](https://www.conventionalcommits.org/en/v1.0.0/) as the main guideline of making PR. This guideline serves to help contributor and maintainer to classify their changes, thus providing better insight on type of release will be covered on each Kustomize release cycle. + +1. Please add these keywords on your PR titles accordingly + +| Keyword | Description | Example | +| ------------- | ------------- | ------------- | +| fix | Patching or fixing bugs or improvements introduction from previous release. This type of change will mark a `PATCH` release. | fix: fix null value when generating yaml | +| feat | New features. This change will mark a `MINOR` release. | feat: new transformer and generator for ACME API CRD. | +| chore | Minor improvement outside main code base | chore: add exclusion for transformer test. | +| ci | CI/CD related changes (e.g. github workflow, scripts, CI steps). | ci: remove blocking tests | +| docs | Changes related to documentation. | docs: add rules documentation for PR. | + + +2. Add `BREAKING CHANGE:` on your commit message as footer to signify breaking changes. This will help maintainer to justify `MAJOR` releases. + +Example: + +``` +feat: change YAML parser from `yaml/v1` to `yaml/v2` + +BREAKING CHANGE: parse() function now works with 2 arguments. +``` + ### Create a Pull Request + 1. Visit your fork at `https://github.com//kustomize` 2. Click the **Compare & Pull Request** button next to your `myfeature` branch. 3. Check out the pull request [process](https://github.com/kubernetes/community/blob/master/contributors/guide/pull-requests.md) for more details and advice. If you ran `git push` in the previous step, GitHub will return a useful link to create a Pull Request. - ### Build Kustomize The [Kustomize Architecture] document describes the respository organization and the kustomize build process. ```bash diff --git a/releasing/check-release-helper.sh b/releasing/check-release-helper.sh index ae4e6ee68c..f481b381aa 100755 --- a/releasing/check-release-helper.sh +++ b/releasing/check-release-helper.sh @@ -15,7 +15,7 @@ git log "${LATEST_TAG}..HEAD" --oneline | tee /tmp/release-changelogs.txt count=$(cat /tmp/release-changelogs.txt | wc -l) -if [[ $(cat /tmp/release-changelogs.txt | grep fix) || $(cat /tmp/release-changelogs.txt | grep patch) || $(cat /tmp/release-changelogs.txt | grep chore) ]]; then +if [[ $(cat /tmp/release-changelogs.txt | grep fix) || $(cat /tmp/release-changelogs.txt | grep patch) || $(cat /tmp/release-changelogs.txt | grep chore) || $(cat /tmp/release-changelogs.txt | grep docs) ]]; then PATCH=true fi @@ -23,6 +23,13 @@ if [[ $(cat /tmp/release-changelogs.txt | grep feat) ]]; then MINOR=true fi +for commit in $(cut -d' ' -f1 /tmp/release-changelogs.txt); do + git log --format=%B -n 1 $commit | grep "BREAKING CHANGE" + if [ $? -eq 0 ]; then + MAJOR=true + fi +done + for f in $(find api); do git diff "${LATEST_TAG}...${ORIGIN_MASTER}" --exit-code -- "${f}" if [ $? -eq 1 ]; then From b1a9bffd8b201158ce9fab1a6752f2b0ba93a021 Mon Sep 17 00:00:00 2001 From: Kurnianto Trilaksono Date: Sun, 28 Apr 2024 23:28:48 +0700 Subject: [PATCH 10/10] Update CONTRIBUTING.md - change breaking change notes Co-authored-by: Mauren <698465+stormqueen1990@users.noreply.github.com> --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 09e42469fc..8bc3b80db9 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -90,7 +90,7 @@ We are using [Conventional Commits v1.0.0](https://www.conventionalcommits.org/e | docs | Changes related to documentation. | docs: add rules documentation for PR. | -2. Add `BREAKING CHANGE:` on your commit message as footer to signify breaking changes. This will help maintainer to justify `MAJOR` releases. +2. Add `BREAKING CHANGE:` on your commit message as footer to signify breaking changes. This will help maintainers identify `MAJOR` releases. Example: