diff --git a/.helmignore b/.helmignore index 6156b21..4cb42dc 100644 --- a/.helmignore +++ b/.helmignore @@ -24,6 +24,6 @@ # Others starter/ .github/ +scripts/ gcloud_auth_key.json -create.sh README.md diff --git a/README.md b/README.md index 59a778b..0a80091 100644 --- a/README.md +++ b/README.md @@ -66,20 +66,20 @@ $ helm dep build ### Using Starter -The best way to get started is to use the [`create` script](create.sh) to generate a new chart. +The best way to get started is to use the [`create-chart` script](scripts/create-chart.sh) to generate a new chart. You can fetch that script, and then execute it locally: ```shell -$ curl -fsSL -o create.sh https://raw.githubusercontent.com/hahow/common-chart/master/create.sh -$ chmod 700 create.sh -$ ./create.sh mychart +$ curl -fsSL -o create.sh https://raw.githubusercontent.com/hahow/common-chart/master/scripts/create-chart.sh +$ chmod 700 create-chart.sh +$ ./create-chart.sh mychart ``` or simply ```shell -$ curl https://raw.githubusercontent.com/hahow/common-chart/master/create.sh | bash -s -- mychart +$ curl https://raw.githubusercontent.com/hahow/common-chart/master/scripts/create-chart.sh | bash -s -- mychart ``` Now, there is a chart in `./mychart`. You can edit it and create your own templates. diff --git a/create.sh b/create.sh deleted file mode 100755 index df28493..0000000 --- a/create.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env bash - -set -exu - -if [[ $# -eq 0 ]] -then - echo "No argument supplied" - exit 1 -fi - -mkdir "$1" -curl --proto '=https' --tlsv1.2 -sSf https://codeload.github.com/hahow/common-chart/tar.gz/master | \ - tar -xz -C "$1" --strip=2 common-chart-master/starter -find "$1" -type f | xargs sed -i "" "s//$1/g" - -helm dep build "$1" diff --git a/scripts/bump-version.sh b/scripts/bump-version.sh new file mode 100755 index 0000000..66655b4 --- /dev/null +++ b/scripts/bump-version.sh @@ -0,0 +1,63 @@ +#!/usr/bin/env bash + +set -eu + +printusage() { + echo "Usage: bump-version.sh [patch|minor|major]" +} + +ROOT_PATH=$(dirname "$0")/.. + +if [[ $# -eq 0 ]] +then + printusage + exit 1 +fi + +UPDATED_PART=$1 +if [[ ! ($UPDATED_PART == "patch" || $UPDATED_PART == "minor" || $UPDATED_PART == "major") ]] +then + printusage + exit 1 +fi + +CURRENT_VERSION=$(sed -ne 's/^version: \([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\)$/\1/p' $ROOT_PATH/Chart.yaml) +MAJOR_VERSION=$(echo $CURRENT_VERSION | cut -d '.' -f 1) +MINOR_VERSION=$(echo $CURRENT_VERSION | cut -d '.' -f 2) +PATCH_VERSION=$(echo $CURRENT_VERSION | cut -d '.' -f 3) + +if [[ $UPDATED_PART = 'patch' ]] +then + (( PATCH_VERSION++ )) +elif [[ $UPDATED_PART = 'minor' ]] +then + (( MINOR_VERSION++ )) + PATCH_VERSION=0 +elif [[ $UPDATED_PART = 'major' ]] +then + (( MAJOR_VERSION ++ )) + MINOR_VERSION=0 + PATCH_VERSION=0 +fi + +NEW_VERSION=$MAJOR_VERSION.$MINOR_VERSION.$PATCH_VERSION +echo "Bumping Version $CURRENT_VERSION => $NEW_VERSION..." + +case $(sed --help 2>&1) in + *GNU*) + SED=(sed -i) + ;; + + *) + SED=(sed -i "") + ;; +esac + +echo "Updating starter/Chart.yaml..." +"${SED[@]}" "s/^ version: \"$CURRENT_VERSION\"$/ version: \"$NEW_VERSION\"/" $ROOT_PATH/starter/Chart.yaml + +echo "Updating README.md..." +"${SED[@]}" "/^### Adding Dependency$/,/^### Using Starter$/s;version: $CURRENT_VERSION;version: $NEW_VERSION;" $ROOT_PATH/README.md + +echo "Updating Chart.yaml..." +"${SED[@]}" "s/^version: $CURRENT_VERSION$/version: $NEW_VERSION/" $ROOT_PATH/Chart.yaml diff --git a/scripts/create-chart.sh b/scripts/create-chart.sh new file mode 100755 index 0000000..71d4f15 --- /dev/null +++ b/scripts/create-chart.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +set -eu + +if [[ $# -eq 0 ]] +then + echo "Usage: create-chart.sh " + exit 1 +fi + +CHART_NAME=$1 + +case $(sed --help 2>&1) in + *GNU*) + SED=(sed -i) + ;; + + *) + SED=(sed -i "") + ;; +esac + +echo "Creating chart..." +mkdir "$CHART_NAME" +curl --proto '=https' --tlsv1.2 -sSf https://codeload.github.com/hahow/common-chart/tar.gz/master | \ + tar -xz -C "$CHART_NAME" --strip=2 common-chart-master/starter +find "$CHART_NAME" -type f | xargs "${SED[@]}" "s//$CHART_NAME/g" + +echo "Building dependencies..." +helm dep build "$CHART_NAME"