charts/.circleci/release.sh

111 lines
2.8 KiB
Bash
Raw Normal View History

2019-08-05 00:40:59 +00:00
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
: "${CH_TOKEN:?Environment variable CH_TOKEN must be set}"
: "${GIT_REPOSITORY_URL:?Environment variable GIT_REPO_URL must be set}"
: "${GIT_USERNAME:?Environment variable GIT_USERNAME must be set}"
: "${GIT_EMAIL:?Environment variable GIT_EMAIL must be set}"
: "${GIT_REPOSITORY_NAME:?Environment variable GIT_REPOSITORY_NAME must be set}"
readonly REPO_ROOT="${REPO_ROOT:-$(git rev-parse --show-toplevel)}"
main() {
pushd "$REPO_ROOT" > /dev/null
echo "Fetching tags..."
git fetch --tags
local latest_tag
latest_tag=$(find_latest_tag)
local latest_tag_rev
latest_tag_rev=$(git rev-parse --verify "$latest_tag")
echo "$latest_tag_rev $latest_tag (latest tag)"
local head_rev
head_rev=$(git rev-parse --verify HEAD)
echo "$head_rev HEAD"
if [[ "$latest_tag_rev" == "$head_rev" ]]; then
echo "No code changes. Nothing to release."
exit
fi
rm -rf .deploy
mkdir -p .deploy
echo "Identifying changed charts since tag '$latest_tag'..."
2019-08-05 05:17:14 +00:00
local packaged=false
2019-08-05 05:07:09 +00:00
git diff --find-renames --name-only "$latest_tag_rev" -- . | cut -d '/' -f 1 | uniq > /tmp/modified_dirs.txt
2019-08-05 04:52:34 +00:00
while read -r dir; do
if find "$dir" -type f -iname "Chart.yaml" | grep -E -q 'Chart.yaml'; then
2019-08-05 05:07:09 +00:00
echo "Packaging chart '$dir'..."
package_chart "$dir"
2019-08-05 05:15:14 +00:00
packaged=true
2019-08-05 04:52:34 +00:00
fi
done < /tmp/modified_dirs.txt
rm /tmp/modified_dirs.txt
2019-08-05 00:40:59 +00:00
2019-08-05 05:15:14 +00:00
if [ $packaged ]; then
2019-08-05 03:53:45 +00:00
release_charts
sleep 5
update_index
2019-08-05 00:40:59 +00:00
else
2019-08-05 05:15:14 +00:00
echo "Nothing to do. No chart changes detected."
2019-08-05 00:40:59 +00:00
fi
popd > /dev/null
}
find_latest_tag() {
if ! git describe --tags --abbrev=0 2> /dev/null; then
git rev-list --max-parents=0 --first-parent HEAD
fi
}
package_chart() {
local chart="$1"
2019-08-05 01:25:01 +00:00
helm dependency build "$chart"
helm package "$chart" --destination .deploy
2019-08-05 00:40:59 +00:00
}
release_charts() {
chart-releaser upload -o "$GIT_USERNAME" -r "$GIT_REPOSITORY_NAME" -p .deploy
}
update_index() {
chart-releaser index -o "$GIT_USERNAME" -r "$GIT_REPOSITORY_NAME" -p .deploy/index.yaml
git config user.email "$GIT_EMAIL"
git config user.name "$GIT_USERNAME"
for file in */*.md; do
2019-08-05 00:40:59 +00:00
if [[ -e $file ]]; then
mkdir -p ".deploy/docs/$(dirname "$file")"
cp --force "$file" ".deploy/docs/$(dirname "$file")"
fi
done
git checkout gh-pages
cp --force .deploy/index.yaml index.yaml
if [[ -e ".deploy/docs" ]]; then
# mkdir -p charts
cp --force --recursive .deploy/docs/* .
2019-08-05 00:40:59 +00:00
fi
git checkout master -- README.md
if ! git diff --quiet; then
git add .
git commit --message="[ci skip] Update index.yaml" --signoff
2019-08-05 00:40:59 +00:00
git push "$GIT_REPOSITORY_URL" gh-pages
fi
}
main