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

Feature/scripts #3

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 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
2 changes: 1 addition & 1 deletion .helmignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
# Others
starter/
.github/
scripts/
gcloud_auth_key.json
create.sh
README.md
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
16 changes: 0 additions & 16 deletions create.sh

This file was deleted.

42 changes: 42 additions & 0 deletions scripts/bump-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env bash
Copy link
Contributor

Choose a reason for hiding this comment

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

想問 scripts/bump-version.sh 會是誰在用?更改 chart 的人?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yap,之後看能不能透過 CD 自動升(但要配合一套完整的 git branching 流程


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]\+\)$/\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)

UPDATED_PART_VAR=$(echo $UPDATED_PART | tr '[:lower:]' '[:upper:]')_VERSION
eval $UPDATED_PART_VAR'=$(($'$UPDATED_PART_VAR' + 1))'
NEW_VERSION=$MAJOR_VERSION.$MINOR_VERSION.$PATCH_VERSION
Copy link
Contributor

Choose a reason for hiding this comment

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

這邊不太合理?bump 大阪好時小版號應該要歸零吧?


echo "Bumping Version $CURRENT_VERSION => $NEW_VERSION..."

echo "Updating starter/Chart.yaml..."
sed -i"" "s/^ version: \"$CURRENT_VERSION\"$/ version: \"$NEW_VERSION\"/" $ROOT_PATH/starter/Chart.yaml

echo "Updating README.md..."
sed -i"" "/^### Adding Dependency$/,/^### Using Starter$/s;version: $CURRENT_VERSION;version: $NEW_VERSION;" $ROOT_PATH/README.md
Copy link
Contributor

Choose a reason for hiding this comment

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

我的 macbook 原生的 sed -i"" 直接連著會 invalid command code,要改成 sed -i ""

附上版本資訊 /usr/bin/sed BSD May 10, 2005

Screen Shot 2020-04-30 at 09 19 51

Copy link
Contributor Author

Choose a reason for hiding this comment

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

換成 BSD sed 的寫法了 🙇

Copy link
Contributor

Choose a reason for hiding this comment

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

我們以後會有 Linux user 嗎 😈


echo "Updating Chart.yaml..."
sed -i"" "s/^version: $CURRENT_VERSION$/version: $NEW_VERSION/" $ROOT_PATH/Chart.yaml
20 changes: 20 additions & 0 deletions scripts/create-chart.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash

set -eu

if [[ $# -eq 0 ]]
then
echo "Usage: create-chart.sh <chartname>"
exit 1
fi

CHART_NAME=$1

echo "Creating chart..."
mkdir "$CHART_NAME"
curl --proto '=https' --tlsv1.2 -sSf https://codeload.github.com/hahow/common-chart/tar.gz/master | \
Copy link
Contributor

Choose a reason for hiding this comment

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

codeload.github.com 是最後 redirect 到的網址沒錯吧?我不確定他不是不是 public facing 的網址,以後可能會被改掉?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

確實有可能以後會改,但目前看來這個網址是滿普遍的用法,等被改掉再換?

tar -xz -C "$CHART_NAME" --strip=2 common-chart-master/starter
find "$CHART_NAME" -type f | xargs sed -i"" "s/<CHARTNAME>/$CHART_NAME/g"

echo "Building dependencies..."
helm dep build "$CHART_NAME"