Last active
June 25, 2020 15:42
-
-
Save ced0ps/ab4c56b63adcce9f78213aed414680aa to your computer and use it in GitHub Desktop.
prometheus-operator-helm-upstream-sync.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -o errexit | |
set -o nounset | |
set -o pipefail | |
LAST_SYNC_COMMIT=$(git log -n1 --grep '^\[upstream-sync\]' --pretty='format:%h' helm/) | |
TMPDIR=$(mktemp -d) | |
UPSTREAM_ZIP_URL=${UPSTREAM_ZIP_URL:-"https://github.com/helm/charts/archive/master.zip"} | |
UPSTREAM_CHART_DIR=${UPSTREAM_CHART_DIR:-"charts-master/stable"} | |
UPSTREAM_CHART_NAME=${UPSTREAM_CHART_NAME:-"prometheus-operator"} | |
KEEP_TMPDIR=${KEEP_TMPDIR:-''} | |
clean_on_exit() { | |
[[ -z "${KEEP_TMPDIR}" ]] && rm -rf ${TMPDIR} | |
} | |
if [ -z "${LAST_SYNC_COMMIT}" ] | |
then | |
echo "Didn't find a commit with [upstream-sync]" | |
exit 1 | |
fi | |
curl -sL -o ${TMPDIR}/master.zip ${UPSTREAM_ZIP_URL} | |
unzip -d ${TMPDIR}/ ${TMPDIR}/master.zip ${UPSTREAM_CHART_DIR}/${UPSTREAM_CHART_NAME}/* | |
UPSTREAM_VERSION=$(cat ${TMPDIR}/${UPSTREAM_CHART_DIR}/${UPSTREAM_CHART_NAME}/Chart.yaml | awk '/^version:/ { print $2 }') | |
cp -a ${TMPDIR}/${UPSTREAM_CHART_DIR}/${UPSTREAM_CHART_NAME}/* helm/${UPSTREAM_CHART_NAME}-app/ | |
git add helm/${UPSTREAM_CHART_NAME}-app/ | |
git commit -m "[upstream-sync] Version ${UPSTREAM_VERSION}" | |
git rev-list --no-merges --reverse ${LAST_SYNC_COMMIT}..HEAD~1 -- helm/${UPSTREAM_CHART_NAME}-app/ | git cherry-pick -X theirs -n --stdin | |
git commit -m "Cherry picked commits ${LAST_SYNC_COMMIT}..HEAD~1" | |
trap clean_on_exit EXIT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment