|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +set -e |
| 4 | + |
| 5 | +usage() { |
| 6 | + printf "%s\n" "Usage:" >&2 ; |
| 7 | + printf -- "%s\n" '---' >&2 ; |
| 8 | + printf "%s %s\n" "$0" "INPUT_DIR OUTPUT_DIR TMP_DIR [DEPENDENCY_DIR]" >&2 ; |
| 9 | + printf -- "%s\n" '---' >&2 ; |
| 10 | + printf "%s\n" "Takes a helm repository from INPUT_DIR, with an optional library repository in" >&2 ; |
| 11 | + printf "%s\n" "DEPENDENCY_DIR, prepares a view of the git archive at select points in history" >&2 ; |
| 12 | + printf "%s\n" "in TMP_DIR and packages helm charts, outputting the tarballs to OUTPUT_DIR" >&2 ; |
| 13 | +} |
| 14 | + |
| 15 | +if [ "x$(basename $PWD)" != "xpackages" ] |
| 16 | +then |
| 17 | + echo "Error: This script must run from the ./packages/ directory" >&2 |
| 18 | + echo >&2 |
| 19 | + usage |
| 20 | + exit 1 |
| 21 | +fi |
| 22 | + |
| 23 | +if [ "x$#" != "x3" ] && [ "x$#" != "x4" ] |
| 24 | +then |
| 25 | + echo "Error: This script takes 3 or 4 arguments" >&2 |
| 26 | + echo "Got $# arguments:" "$@" >&2 |
| 27 | + echo >&2 |
| 28 | + usage |
| 29 | + exit 1 |
| 30 | +fi |
| 31 | + |
| 32 | +input_dir=$1 |
| 33 | +output_dir=$2 |
| 34 | +tmp_dir=$3 |
| 35 | + |
| 36 | +if [ "x$#" = "x4" ] |
| 37 | +then |
| 38 | + dependency_dir=$4 |
| 39 | +fi |
| 40 | + |
| 41 | +rm -rf "${output_dir:?}" |
| 42 | +mkdir -p "${output_dir}" |
| 43 | +while read package _ commit |
| 44 | +do |
| 45 | + # this lets devs build the packages from a dirty repo for quick local testing |
| 46 | + if [ "x$commit" = "xHEAD" ] |
| 47 | + then |
| 48 | + helm package "${input_dir}/${package}" -d "${output_dir}" |
| 49 | + continue |
| 50 | + fi |
| 51 | + git archive --format tar "${commit}" "${input_dir}/${package}" | tar -xf- -C "${tmp_dir}/" |
| 52 | + |
| 53 | + # the library chart is not present in older commits and git archive doesn't fail gracefully if the path is not found |
| 54 | + if [ "x${dependency_dir}" != "x" ] && git ls-tree --name-only "${commit}" "${dependency_dir}" | grep -qx "${dependency_dir}" |
| 55 | + then |
| 56 | + git archive --format tar "${commit}" "${dependency_dir}" | tar -xf- -C "${tmp_dir}/" |
| 57 | + fi |
| 58 | + helm package "${tmp_dir}/${input_dir}/${package}" -d "${output_dir}" |
| 59 | + rm -rf "${tmp_dir:?}/${input_dir:?}/${package:?}" |
| 60 | + if [ "x${dependency_dir}" != "x" ] |
| 61 | + then |
| 62 | + rm -rf "${tmp_dir:?}/${dependency_dir:?}" |
| 63 | + fi |
| 64 | +done < "${input_dir}/versions_map" |
| 65 | +helm repo index "${output_dir}" |
0 commit comments