helm-pages/src/entrypoint.sh
Steven Sheehy 8551b0d273 Filter non-chart files and directories
Signed-off-by: Steven Sheehy <steven.sheehy@hedera.com>
2020-08-06 10:48:49 -05:00

117 lines
2.1 KiB
Bash

#!/usr/bin/env bash
set -o errexit
set -o pipefail
GITHUB_TOKEN=$1
CHARTS_DIR=$2
CHARTS_URL=$3
OWNER=$4
REPOSITORY=$5
BRANCH=$6
HELM_VERSION=$7
CHARTS=()
CHARTS_TMP_DIR=$(mktemp -d)
REPO_ROOT=$(git rev-parse --show-toplevel)
REPO_URL=""
main() {
if [[ -z "$HELM_VERSION" ]]; then
HELM_VERSION="3.2.1"
fi
if [[ -z "$CHARTS_DIR" ]]; then
CHARTS_DIR="charts"
fi
if [[ -z "$OWNER" ]]; then
OWNER=$(cut -d '/' -f 1 <<< "$GITHUB_REPOSITORY")
fi
if [[ -z "$REPOSITORY" ]]; then
REPOSITORY=$(cut -d '/' -f 2 <<< "$GITHUB_REPOSITORY")
fi
if [[ -z "$BRANCH" ]]; then
BRANCH="gh-pages"
fi
if [[ -z "$CHARTS_URL" ]]; then
CHARTS_URL="https://${OWNER}.github.io/${REPOSITORY}"
fi
if [[ -z "$REPO_URL" ]]; then
REPO_URL="https://x-access-token:${GITHUB_TOKEN}@github.com/${OWNER}/${REPOSITORY}"
fi
locate
download
dependencies
lint
package
upload
}
locate() {
for dir in $(find "${CHARTS_DIR}" -type d -mindepth 1 -maxdepth 1); do
if [[ -f "${dir}/Chart.yaml" ]]; then
CHARTS+=("${dir}")
echo "Found chart directory ${dir}"
else
echo "Ignoring non-chart directory ${dir}"
fi
done
}
download() {
tmpDir=$(mktemp -d)
pushd $tmpDir >& /dev/null
curl -sSL https://get.helm.sh/helm-v${HELM_VERSION}-linux-amd64.tar.gz | tar xz
cp linux-amd64/helm /usr/local/bin/helm
popd >& /dev/null
rm -rf $tmpDir
}
dependencies() {
for chart in ${CHARTS[@]}; do
helm dependency update "${chart}"
done
}
lint() {
helm lint ${CHARTS[*]}
}
package() {
helm package ${CHARTS[*]} --destination ${CHARTS_TMP_DIR}
}
upload() {
tmpDir=$(mktemp -d)
pushd $tmpDir >& /dev/null
git clone ${REPO_URL}
cd ${REPOSITORY}
git config user.name "${GITHUB_ACTOR}"
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
git remote set-url origin ${REPO_URL}
git checkout gh-pages
charts=$(cd ${CHARTS_TMP_DIR} && ls *.tgz | xargs)
mv -f ${CHARTS_TMP_DIR}/*.tgz .
helm repo index . --url ${CHARTS_URL}
git add .
git commit -m "Publish $charts"
git push origin gh-pages
popd >& /dev/null
rm -rf $tmpDir
}
main