From bbd78f45da7505614bbf1cdf4885d20d1c77b6eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reinhard=20N=C3=A4gele?= Date: Fri, 23 Oct 2020 11:23:10 +0200 Subject: [PATCH 1/2] Use built-in package and upload functionality MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit chart-releaser is now able to package charts and to push the index.yaml to the configured branch. Signed-off-by: Reinhard Nägele --- cr.sh | 36 ++++++++---------------------------- 1 file changed, 8 insertions(+), 28 deletions(-) diff --git a/cr.sh b/cr.sh index f087555..fafb81d 100755 --- a/cr.sh +++ b/cr.sh @@ -18,16 +18,14 @@ set -o errexit set -o nounset set -o pipefail -DEFAULT_CHART_RELEASER_VERSION=v1.0.0 - -: "${CR_TOKEN:?Environment variable CR_TOKEN must be set}" +DEFAULT_CHART_RELEASER_VERSION=v1.1.0 show_help() { cat << EOF Usage: $(basename "$0") -h, --help Display help - -v, --version The chart-releaser version to use (default: v1.0.0)" + -v, --version The chart-releaser version to use (default: $DEFAULT_CHART_RELEASER_VERSION)" -d, --charts-dir The charts directory (default: charts) -u, --charts-repo-url The GitHub Pages URL to the charts repo (default: https://.github.io/) -o, --owner The repo owner @@ -44,7 +42,8 @@ main() { parse_command_line "$@" - echo "$repo" + : "${CR_TOKEN:?Environment variable CR_TOKEN must be set}" + local repo_root repo_root=$(git rev-parse --show-toplevel) pushd "$repo_root" > /dev/null @@ -182,11 +181,11 @@ lookup_latest_tag() { } filter_charts() { - while read chart; do + while read -r chart; do [[ ! -d "$chart" ]] && continue local file="$chart/Chart.yaml" if [[ -f "$file" ]]; then - echo $chart + echo "$chart" else echo "WARNING: $file is missing, assuming that '$chart' is not a Helm chart. Skipping." 1>&2 fi @@ -213,7 +212,7 @@ package_chart() { local chart="$1" echo "Packaging chart '$chart'..." - helm package "$chart" --destination .cr-release-packages --dependency-update + cr package --package-path .cr-release-packages } release_charts() { @@ -223,26 +222,7 @@ release_charts() { update_index() { echo 'Updating charts repo index...' - - set -x - - cr index -o "$owner" -r "$repo" -c "$charts_repo_url" - - gh_pages_worktree=$(mktemp -d) - - git worktree add "$gh_pages_worktree" gh-pages - - cp --force .cr-index/index.yaml "$gh_pages_worktree/index.yaml" - - pushd "$gh_pages_worktree" > /dev/null - - git add index.yaml - git commit --message="Update index.yaml" --signoff - - local repo_url="https://x-access-token:$CR_TOKEN@github.com/$owner/$repo" - git push "$repo_url" gh-pages - - popd > /dev/null + cr index -o "$owner" -r "$repo" -c "$charts_repo_url" --push } main "$@" From 3e2f46c22dd33b98a35f6d0f19fb052484119a66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reinhard=20N=C3=A4gele?= Date: Sun, 25 Oct 2020 17:08:17 +0100 Subject: [PATCH 2/2] Add config option MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Reinhard Nägele --- README.md | 1 + cr.sh | 33 ++++++++++++++++++++++++++++++--- main.sh | 4 ++++ 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ecc1a97..10a2706 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ A GitHub action to turn a GitHub project into a self-hosted Helm chart repo, usi For more information on inputs, see the [API Documentation](https://developer.github.com/v3/repos/releases/#input) - `version`: The chart-releaser version to use (default: v1.0.0) +- `config`: Optional config file for chart-releaser - `charts_dir`: The charts directory - `charts_repo_url`: The GitHub Pages URL to the charts repo (default: `https://.github.io/`) diff --git a/cr.sh b/cr.sh index fafb81d..434c67f 100755 --- a/cr.sh +++ b/cr.sh @@ -26,6 +26,7 @@ Usage: $(basename "$0") -h, --help Display help -v, --version The chart-releaser version to use (default: $DEFAULT_CHART_RELEASER_VERSION)" + --config The path to the chart-releaser config file -d, --charts-dir The charts directory (default: charts) -u, --charts-repo-url The GitHub Pages URL to the charts repo (default: https://.github.io/) -o, --owner The repo owner @@ -35,6 +36,7 @@ EOF main() { local version="$DEFAULT_CHART_RELEASER_VERSION" + local config= local charts_dir=charts local owner= local repo= @@ -89,6 +91,16 @@ parse_command_line() { show_help exit ;; + --config) + if [[ -n "${2:-}" ]]; then + config="$2" + shift + else + echo "ERROR: '--config' cannot be empty." >&2 + show_help + exit 1 + fi + ;; -v|--version) if [[ -n "${2:-}" ]]; then version="$2" @@ -211,18 +223,33 @@ lookup_changed_charts() { package_chart() { local chart="$1" + local args=(--package-path .cr-release-packages) + if [[ -n "$config" ]]; then + args+=(--config "$config") + fi + echo "Packaging chart '$chart'..." - cr package --package-path .cr-release-packages + cr package "${args[@]}" } release_charts() { + local args=(-o "$owner" -r "$repo" -c "$(git rev-parse HEAD)") + if [[ -n "$config" ]]; then + args+=(--config "$config") + fi + echo 'Releasing charts...' - cr upload -o "$owner" -r "$repo" -c "$(git rev-parse HEAD)" + cr upload "${args[@]}" } update_index() { + local args=(-o "$owner" -r "$repo" -c "$charts_repo_url" --push) + if [[ -n "$config" ]]; then + args+=(--config "$config") + fi + echo 'Updating charts repo index...' - cr index -o "$owner" -r "$repo" -c "$charts_repo_url" --push + cr index "${args[@]}" } main "$@" diff --git a/main.sh b/main.sh index 6032f01..5ce9c2c 100755 --- a/main.sh +++ b/main.sh @@ -31,6 +31,10 @@ main() { args+=(--version "${INPUT_VERSION}") fi + if [[ -n "${INPUT_CONFIG:-}" ]]; then + args+=(--config "${INPUT_CONFIG}") + fi + if [[ -n "${INPUT_CHARTS_REPO_URL:-}" ]]; then args+=(--charts-repo-url "${INPUT_CHARTS_REPO_URL}") fi