Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add generate-release-pr to /hack/release-scripts #1794

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 139 additions & 0 deletions hack/release-scripts/generate-release-pr
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
#!/bin/bash
# Copyright 2023 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ---

# This script generates (most of) the file changes needed for a new aws-ebs-csi-driver release

# --- Script Tools
set -euo pipefail # Exit on any error

log() {
printf "%s [INFO] - %s\n" "$(date +"%Y-%m-%d %H:%M:%S")" "${*}" >&2
}

check_dependencies() {
local readonly dependencies=("yq" "git" "vi" "sed")

for cmd in "${dependencies[@]}"; do
if ! command -v "${cmd}" &>/dev/null; then
log "${cmd} could not be found, please install it."
exit 1
fi
done

# Force macOS users to use gsed due to -i incompatibility
export SED="sed"
if [[ $(uname) = "Darwin" ]]; then
if ! command -v "gsed" &>/dev/null; then
log "gsed could not be found, please install it."
exit 1
fi
SED="gsed"
fi
}

error_handler() {
printf "Error occurred in script: %s, at line: %s. Command: %s. Error: %s\n" "$1" "$2" "$BASH_COMMAND" "$3" >&2
exit 1
}

trap 'error_handler ${LINENO} $? "$BASH_COMMAND"' ERR

# --- Script
usage () {
echo "Usage: $0 [PREV_DRIVER_VERSION] [NEW_DRIVER_VERSION]"
echo "example: $0 v1.23.1 v1.24.0"
exit 1
}

setup_vars () {
export PREV_DRIVER_VERSION=$1
export NEW_DRIVER_VERSION=$2

# Paths
export SCRIPT_PATH
SCRIPT_PATH=$(dirname "$(realpath $0)")
export ROOT_DIRECTORY="$SCRIPT_PATH/../.."
export README_PATH="$ROOT_DIRECTORY/README.md"
export MAKEFILE_PATH="$ROOT_DIRECTORY/Makefile"
export INSTALL_MD_PATH="$ROOT_DIRECTORY/docs/install.md"
export CHART_PATH="$ROOT_DIRECTORY/charts/aws-ebs-csi-driver/Chart.yaml"
}

parse_args () {
# Confirm 2 parameters
[[ $# -ne 2 ]] && usage

# Confirm new driver version > prev driver version
AndrewSirenko marked this conversation as resolved.
Show resolved Hide resolved
log "Confirming $1 < $2"
sort -C -V <(echo "$1"; echo "$2") || usage

setup_vars "$@"
}

update_readme () {
log "Updating README.md"
# vi macro that adds new driver version 'Container Images' row to README.md
vi -s <(echo "gg/## Container Images
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we use sed here for consistency? it would let us remove vi from the dependencies list.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that using sed is preferable to vi, but I was not able to figure out a way to use sed for this operation (after quite some time...).

jjjjyy:%s/${PREV_DRIVER_VERSION}/${NEW_DRIVER_VERSION}/g
jjjjjjp:wq") "$README_PATH"
}

update_makefile () {
log "Updating Makefile"
$SED "s/VERSION?=$PREV_DRIVER_VERSION/VERSION?=$NEW_DRIVER_VERSION/g" -i "$MAKEFILE_PATH"
}

update_installmd () {
log "Updating docs/install.md"
prev_major_minor_version=$(echo "$PREV_DRIVER_VERSION" | sed 's/v\([0-9]*\.[0-9]*\).*/\1/')
new_major_minor_version=$(echo "$NEW_DRIVER_VERSION" | sed 's/v\([0-9]*\.[0-9]*\).*/\1/')
$SED "s/?ref=release-$prev_major_minor_version/?ref=release-$new_major_minor_version/g" -i "$INSTALL_MD_PATH"
}

update_chart_and_overlays () {
log "Updating helm chart and generates kustomize"
prev_minor_patch_version=$(echo "$PREV_DRIVER_VERSION" | sed 's/v[0-9]*\.//')
new_minor_patch_version=$(echo "$NEW_DRIVER_VERSION" | sed 's/v[0-9]*\.//')

$SED "s/$prev_minor_patch_version$/$new_minor_patch_version/g" -i "$CHART_PATH"

(cd "$ROOT_DIRECTORY"; make generate-kustomize) > "/dev/null"
}

update_upstream_repo () {
update_readme
update_makefile
update_installmd
update_chart_and_overlays
}

print_rest_of_release_steps () {
echo "SUCCESS!
Before you submit the release PR, you must also:
1. Check that 'git diff' produces what you expected.
2. Update CHANGELOG.md
3. Update charts/aws-ebs-csi-driver/CHANGELOG.md"
Comment on lines +127 to +128
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idea: It might help to list all the relevant commits that a maintainer has to consider when crafting the CHANGELOG for a particular release.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea!

I actually showcased a script that does this during a demo a few months ago (and have been using it during releases). I should clean that script up and commit it to our repo, but I think that should be a separate PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found it! Here

}

main () {
check_dependencies
parse_args "$@"

update_upstream_repo
print_rest_of_release_steps
}

main "$@" # Must pass all args from script with $@
Loading