From de303ee205b886e1d26443867809e090eb5f8105 Mon Sep 17 00:00:00 2001 From: Cole Arendt Date: Thu, 23 Dec 2021 15:07:50 -0500 Subject: [PATCH] add scripts folder for rebuliding the repo --- scripts/README.md | 21 +++++++++++++++++ scripts/rebuild.sh | 56 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 scripts/README.md create mode 100755 scripts/rebuild.sh diff --git a/scripts/README.md b/scripts/README.md new file mode 100644 index 0000000..9d01261 --- /dev/null +++ b/scripts/README.md @@ -0,0 +1,21 @@ +# Rebuilding Index + +The Helm `index.yaml` is hosted on the `gh-pages` branch of this repo. If this +index becomes out-of-sync with the releases, you can rebuild it by using a +GitHub Actions Workflow. + +## Prerequisites + +- To use the `rebuild.sh` script with our workflow, the `rebuild.sh` + script must be checked in to the `gh-pages` branch. If you make any changes + to the script in this directory, make sure you also commit the same changes + to the `gh-pages` branch. +- You must have permission to run GitHub Actions Workflows for this repo. + +## Running the Action + +- Navigate to + https://github.com/colearendt/helm/actions/workflows/chart-rebuild.yaml. +- Use the `Run Workflow` button to run the workflow. +- Review the Pull Request created by the workflow. +- When approved, merge the Pull Request into the `gh-pages` branch. diff --git a/scripts/rebuild.sh b/scripts/rebuild.sh new file mode 100755 index 0000000..89f346f --- /dev/null +++ b/scripts/rebuild.sh @@ -0,0 +1,56 @@ +#!/usr/bin/env bash + +# Run this script from the root of the helm repo, e.g., +# ./scripts/rebuild.sh. You must have curl and cr installed. See +# https://github.com/helm/chart-releaser#installation. + +# Set this to a valid URL *without* an index.yaml if you want to regenerate +# a new index.html. If you want to append to an existing one, you can +# use a real address like `https://helm.rstudio.com`. If an existing +# index.yaml is found at this URL, then any packages we generate will +# be appended, which can result in duplicates. +HELM_REPO=${HELM_REPO:-https://rstudio.com} + +# Create a temporary directory and clean it up when we're done. +TMP_DIR=$(mktemp -d) +function cleanup() +{ + echo "Removing temporary directory ${TMP_DIR}." + rm -rf $TMP_DIR +} +trap cleanup EXIT + +# Optional variables you can define in your env +PACKAGE_DIR=${PACKAGE_DIR:-${TMP_DIR}} +CHARTS_DIR=${CHARTS_DIR:-charts} +INDEX=${INDEX:-index.yaml} +GITHUB_OWNER=${GITHUB_OWNER:-rstudio} +GITHUB_REPO=${GITHUB_REPO:-helm} + +# Calculated variables +DOWNLOADS_BASE="https://github.com/${GITHUB_OWNER}/${GITHUB_REPO}/releases/download" + +# List all tags oldest to newest, followed by the 'main' branch. +tags="$(git tag -l --sort=creatordate) main" + +# Clean the packages release directory that `cr` uses. +mkdir -p ${PACKAGE_DIR} +rm -rf ${PACKAGE_DIR}/* + +# Download existing assets from Github +for tag in $tags; do + dl_url="${DOWNLOADS_BASE}/${tag}/${tag}.tgz" + cd ${PACKAGE_DIR} + curl -LOs --fail ${dl_url} + result=$? + if [[ ${result} -eq 0 ]]; then + echo "Downloaded $dl_url". + else + echo "Could not download $dl_url". + fi + cd - +done + +echo "Writing index to ${INDEX}" +rm ${INDEX} +cr index --owner ${GITHUB_OWNER} --git-repo ${GITHUB_REPO} --charts-repo ${HELM_REPO} -p ${PACKAGE_DIR} -i ${INDEX}