Skip to content

Instantly share code, notes, and snippets.

@scottrigby
Created October 30, 2020 17:13
Show Gist options
  • Save scottrigby/6693aec2b2bd814545d7d554a0469aa0 to your computer and use it in GitHub Desktop.
Save scottrigby/6693aec2b2bd814545d7d554a0469aa0 to your computer and use it in GitHub Desktop.
#!/bin/bash
# See https://github.com/helm/charts/issues/23971
settings() {
set -eu
if [ "${DEBUG:-}" = 1 ]; then
export PS4='+ ($LINENO) '
set -x
fi
}
requirements() {
for c in git gh; do
if ! command -v $c > /dev/null 2>&1; then
echo "$c could not be found"
exit 1
fi
done
}
validate_input() {
if [ -z "$1" ] || [ ! -f "$1"/Chart.yaml ]; then
echo "You must supply a chart path"
ecit 1
fi
}
checkout_branch() {
git checkout -b 23971-$(echo "$1" | tr '/' '-')
}
add_commit() {
git add -p "$1"
git commit -s -m "[$1] update chart repo dependency references"
}
pr() {
# gh pr create -w -b 'See #23971'
gh pr create -b 'See #23971'
}
stash() {
git stash
}
master() {
git checkout master
}
pop() {
git stash pop
}
settings
requirements
validate_input "$@"
checkout_branch "$@"
add_commit "$@"
pr
stash
master
pop
#!/bin/bash
# See https://github.com/helm/charts/issues/23971
settings() {
set -eu
if [ "${DEBUG:-}" = 1 ]; then
export PS4='+ ($LINENO) '
set -x
fi
}
validate_input() {
# shellcheck disable=SC2235
if [ -z "${1:-}" ] || ([ "$1" != 'stable' ] && [ "$1" != 'incubator' ]); then
echo "You must specify the repo: stable or incubator"
exit 1
fi
}
requirements() {
for c in helm git sed grep; do
if ! command -v $c > /dev/null 2>&1; then
echo "$c could not be found"
exit 1
fi
done
}
find_deprecated() {
deprecated=$(grep -e 'deprecated: true' "$1"/*/Chart.yaml | cut -d'/' -f1-2 | uniq)
export deprecated="$deprecated"
}
find_parent_charts() {
parent_charts=$(grep -e kubernetes-charts.storage.googleapis.com -e kubernetes-charts-incubator.storage.googleapis.com "$1"/*/requirements.yaml | cut -d'/' -f1-2 | uniq)
# Remove deprecated charts
parent_charts=$(comm -13 <(echo "$deprecated") <(echo "$parent_charts"))
export parent_charts="$parent_charts"
}
replace_url() {
for c in $parent_charts; do
sed -i '' 's,https://kubernetes-charts.storage.googleapis.com.*,https://charts.helm.sh/stable,g' "$c"/requirements.yaml
sed -i '' 's,https://kubernetes-charts-incubator.storage.googleapis.com.*,https://charts.helm.sh/incubator,g' "$c"/requirements.yaml
done
}
build_lock_files() {
for c in $parent_charts; do
echo "building $c"
[ -f "$c"/requirements.lock ] && rm "$c"/requirements.lock
helm2 dependency update --skip-refresh "$c"
done
}
bump_versions() {
for c in $parent_charts; do
old=$(sed -n -e 's/^version: //p' "$c"/Chart.yaml | sed s/\"//g)
# Bump PATCH. See https://github.com/tomologic/bump-semver/blob/master/bump.sh
new=$(echo $old | awk -F. -v a="0" -v b="0" -v c="1" '{printf("%d.%d.%d", $1+a, $2+b , $3+c)}')
sed -i '' "s,$old,$new,g" "$c"/Chart.yaml
done
}
settings
validate_input "$@"
requirements
find_deprecated "$@"
find_parent_charts "$@"
replace_url "$@"
build_lock_files
bump_versions
@scottrigby
Copy link
Author

usage:

First make local changes for either incubator or stable:

$ ./helm-charts-23971.sh incubator

Then one chart at a time, create the local branch, interactive add, commit, and create PR:

$ ./helm-charts-23971-pr.sh incubator/druid

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment