diff --git a/hack/boilerplate.go.txt b/hack/boilerplate.go.txt index 45dbbbbc..65b86227 100644 --- a/hack/boilerplate.go.txt +++ b/hack/boilerplate.go.txt @@ -1,5 +1,5 @@ /* -Copyright 2021. +Copyright 2023. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/scripts/lib.sh b/scripts/lib.sh new file mode 100755 index 00000000..50049396 --- /dev/null +++ b/scripts/lib.sh @@ -0,0 +1,22 @@ +#!/bin/sh + +NEXT_VERSION="" + +next_minor_version() { + local RE='[^0-9]*\([0-9]*\)[.]\([0-9]*\)[.]\([0-9]*\)\([0-9A-Za-z-]*\)' + + local MINOR=$(echo $CURRENT_VERSION | sed -e "s#$RE#\2#") + + local NEXT_VERSION_PARTS=() + for i in {1..3} + do + local PART=$(echo $CURRENT_VERSION | sed -e "s#$RE#\\$i#") + if [ $i == 2 ] + then + let PART+=1 + fi + NEXT_VERSION_PARTS+=($PART) + done + + NEXT_VERSION=${NEXT_VERSION_PARTS[0]}.${NEXT_VERSION_PARTS[1]}.0 +} diff --git a/scripts/post-release-process.sh b/scripts/post-release-process.sh index 8797be16..640e4110 100755 --- a/scripts/post-release-process.sh +++ b/scripts/post-release-process.sh @@ -1,4 +1,9 @@ #!/bin/sh +if [[ ! $0 == scripts/* ]]; then + echo "This script must be run from the root directory" + exit 1 +fi + IMG=k8ssandra/cass-operator:latest KUSTOMIZE=$(pwd)/bin/kustomize diff --git a/scripts/postprocess-bundle.sh b/scripts/postprocess-bundle.sh index 7437f58f..5cfb9068 100755 --- a/scripts/postprocess-bundle.sh +++ b/scripts/postprocess-bundle.sh @@ -1,4 +1,8 @@ #!/bin/sh +if [[ ! $0 == scripts/* ]]; then + echo "This script must be run from the root directory" + exit 1 +fi # These labels are required to be in the bundle.Dockerfile, but can't be added by the operator-sdk automatically cat <> bundle.Dockerfile diff --git a/scripts/pre-release-process.sh b/scripts/pre-release-process.sh index 8e267cd9..fd0a0714 100755 --- a/scripts/pre-release-process.sh +++ b/scripts/pre-release-process.sh @@ -1,4 +1,8 @@ #!/bin/sh +if [[ ! $0 == scripts/* ]]; then + echo "This script must be run from the root directory" + exit 1 +fi if [ "$#" -ne 1 ]; then echo "Usage: scripts/pre-release-process.sh newTag" @@ -16,10 +20,10 @@ make kustomize KUSTOMIZE=$(pwd)/bin/kustomize # Modify CHANGELOG automatically to match the tag -sed -i -e "s/## unreleased/## $TAG/" CHANGELOG.md +sed -i '' -e "s/## unreleased/## $TAG/" CHANGELOG.md # Modify README to include proper installation refs -sed -i -e "s/$PREVTAG/$TAG/g" README.md +sed -i '' -e "s/$PREVTAG/$TAG/g" README.md # Modify config/manager/kustomization.yaml to have proper newTag for cass-operator cd config/manager && $KUSTOMIZE edit set image controller=$IMG && cd - diff --git a/scripts/release-certified-bundles.sh b/scripts/release-certified-bundles.sh index 61a43026..8704fe44 100755 --- a/scripts/release-certified-bundles.sh +++ b/scripts/release-certified-bundles.sh @@ -1,4 +1,8 @@ #!/bin/sh +if [[ ! $0 == scripts/* ]]; then + echo "This script must be run from the root directory" + exit 1 +fi if [ "$#" -ne 4 ]; then echo "Usage: scripts/release-certified-bundles.sh version sha256: sha256: sha256:" diff --git a/scripts/release-community-bundles.sh b/scripts/release-community-bundles.sh index f649f739..5f4300f7 100755 --- a/scripts/release-community-bundles.sh +++ b/scripts/release-community-bundles.sh @@ -1,4 +1,8 @@ #!/bin/sh +if [[ ! $0 == scripts/* ]]; then + echo "This script must be run from the root directory" + exit 1 +fi if [ "$#" -ne 1 ]; then echo "Usage: scripts/release-community-bundles.sh version" diff --git a/scripts/release-helm-chart.sh b/scripts/release-helm-chart.sh index 5d537f3a..326274f6 100755 --- a/scripts/release-helm-chart.sh +++ b/scripts/release-helm-chart.sh @@ -1,5 +1,10 @@ #!/bin/sh +if [[ ! $0 == scripts/* ]]; then + echo "This script must be run from the root directory" + exit 1 +fi + # This script assumes k8ssandra is checked out at ../k8ssandra and is checked out at main if [ "$#" -ne 1 ]; then echo "Usage: scripts/release-helm-chart.sh version" @@ -8,9 +13,12 @@ if [ "$#" -ne 1 ]; then exit fi +# This should work with BSD/MacOS mktemp and GNU one +CRD_TMP_DIR=$(mktemp -d 2>/dev/null || mktemp -d -t 'crd') + VERSION=$1 CHART_HOME=../k8ssandra/charts/cass-operator -CRD_TARGET_PATH=$CHART_HOME/crds +CRD_TARGET_PATH=$CRD_TMP_DIR TEMPLATE_HOME=$CHART_HOME/templates # Checkout tag @@ -25,4 +33,41 @@ for f in $CRD_TARGET_PATH/*; do mv $f $CRD_TARGET_PATH/$TARGET_FILENAME done -# TODO Update all the necessary fields also (Chart.yaml, values.yaml, configmap.yaml) +# Add Helm conditionals to the end and beginning of CRDs before applying them to the templates path +echo "Updating CRDs in" $TEMPLATE_HOME +CRD_FILE_NAME=$TEMPLATE_HOME/crds.yaml +echo '{{- if .Values.updateCRDs }}' > $CRD_FILE_NAME + +declare -a files +files=($CRD_TARGET_PATH/*) +for i in ${!files[@]}; do + echo "Processing " ${files[$i]} + cat ${files[$i]} >> $CRD_FILE_NAME + if [[ $i -lt ${#files[@]}-1 ]]; then + echo "---" >> $CRD_FILE_NAME + fi +done +echo '{{- end }}' >> $CRD_FILE_NAME + +rm -fr $CRD_TMP_DIR + +# Update version of the Chart.yaml automatically (to next minor one) +CURRENT_VERSION=$(yq '.version' $CHART_HOME/Chart.yaml) +. scripts/lib.sh +next_minor_version +echo "Updating Chart.yaml version to next minor version" $NEXT_VERSION +yq -i '.version = "'"$NEXT_VERSION"'"' $CHART_HOME/Chart.yaml + +# Update appVersion to the same as version +echo "Setting appVersion to" $VERSION +yq -i '.appVersion = "'"$VERSION"'"' $CHART_HOME/Chart.yaml + +# Update imageConfig settings to the current one +echo "Updating .Values.imageConfig to match config/manager/image_config.yaml" +SYSTEM_LOGGER_IMAGE=$(yq '.images.system-logger' config/manager/image_config.yaml) +K8SSANDRA_CLIENT_IMAGE=$(yq '.images.k8ssandra-client' config/manager/image_config.yaml) +CONFIG_BUILDER_IMAGE=$(yq '.images.config-builder' config/manager/image_config.yaml) + +yq -i '.imageConfig.systemLogger = "cr.k8ssandra.io" + "/" + "'"$SYSTEM_LOGGER_IMAGE"'"' $CHART_HOME/values.yaml +yq -i '.imageConfig.k8ssandraClient = "cr.k8ssandra.io" + "/" + "'"$K8SSANDRA_CLIENT_IMAGE"'"' $CHART_HOME/values.yaml +yq -i '.imageConfig.configBuilder = "cr.dtsx.io" + "/" + "'"$CONFIG_BUILDER_IMAGE"'"' $CHART_HOME/values.yaml \ No newline at end of file diff --git a/scripts/update-makefile-version.sh b/scripts/update-makefile-version.sh index 336989e4..aa9c18ed 100755 --- a/scripts/update-makefile-version.sh +++ b/scripts/update-makefile-version.sh @@ -1,21 +1,11 @@ #!/bin/bash +if [[ ! $0 == scripts/* ]]; then + echo "This script must be run from the root directory" + exit 1 +fi -RE='[^0-9]*\([0-9]*\)[.]\([0-9]*\)[.]\([0-9]*\)\([0-9A-Za-z-]*\)' +. scripts/lib.sh CURRENT_VERSION=$(gawk 'match($0, /^VERSION \?= /) { print substr($0, RLENGTH+1)}' Makefile) -MINOR=$(echo $CURRENT_VERSION | sed -e "s#$RE#\2#") - -NEXT_VERSION_PARTS=() -for i in {1..3} -do - PART=$(echo $CURRENT_VERSION | sed -e "s#$RE#\\$i#") - if [ $i == 2 ] - then - let PART+=1 - fi - NEXT_VERSION_PARTS+=($PART) -done - -NEXT_VERSION=${NEXT_VERSION_PARTS[0]}.${NEXT_VERSION_PARTS[1]}.${NEXT_VERSION_PARTS[2]} - -sed -i -e "s/VERSION ?= $CURRENT_VERSION/VERSION ?= $NEXT_VERSION/" Makefile +next_minor_version +sed -i '' -e "s/VERSION ?= $CURRENT_VERSION/VERSION ?= $NEXT_VERSION/" Makefile