From 9c0a3b5bc6296ba34ccb2b6bdbcaf9cbb255ecb9 Mon Sep 17 00:00:00 2001 From: Michael Kriese Date: Tue, 27 Jun 2023 17:51:27 +0200 Subject: [PATCH] Remove `charts_repo_url` from readme (#144) Signed-off-by: Michael Kriese --- README.md | 2 -- action.yml | 8 +++++++ cr.sh | 65 +++++++++++++++++++++++++++++++++++++++++++++--------- 3 files changed, 62 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index a1c9067..ab7b791 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,6 @@ A GitHub action to turn a GitHub project into a self-hosted Helm chart repo, usi - `version`: The chart-releaser version to use (default: v1.4.1) - `config`: Optional config file for chart-releaser. For more information on the config file, see the [documentation](https://github.com/helm/chart-releaser#config-file) - `charts_dir`: The charts directory -- `charts_repo_url`: The GitHub Pages URL to the charts repo (default: `https://.github.io/`) - `skip_packaging`: This option, when populated, will skip the packaging step. This allows you to do more advanced packaging of your charts (for example, with the `helm package` command) before this action runs. This action will only handle the indexing and publishing steps. - `mark_as_latest`: When you set this to `false`, it will mark the created GitHub release not as 'latest'. @@ -80,7 +79,6 @@ It does this – during every push to `main` – by checking each chart in your with: charts_dir: charts config: cr.yaml - charts_repo_url: xxxxxx env: CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}" ``` diff --git a/action.yml b/action.yml index 83ec6d3..9f0516a 100644 --- a/action.yml +++ b/action.yml @@ -32,6 +32,10 @@ inputs: description: Mark the created GitHub release as 'latest' required: false default: true + distribute_charts: + description: "Push charts to a remote registry (OCI)" + required: false + default: false runs: using: composite @@ -76,5 +80,9 @@ runs: args+=(--mark-as-latest "${{ inputs.mark_as_latest }}") fi + if [[ -n "${{ inputs.distribute_charts }}" ]]; then + args+=(--distribute-charts "${{ inputs.distribute_charts }}") + fi + "$GITHUB_ACTION_PATH/cr.sh" "${args[@]}" shell: bash diff --git a/cr.sh b/cr.sh index fc2d437..ed84e49 100755 --- a/cr.sh +++ b/cr.sh @@ -24,17 +24,18 @@ show_help() { cat << EOF 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) - -o, --owner The repo owner - -r, --repo The repo name - -n, --install-dir The Path to install the cr tool - -i, --install-only Just install the cr tool - -s, --skip-packaging Skip the packaging step (run your own packaging before using the releaser) - --skip-existing Skip package upload if release exists - -l, --mark-as-latest Mark the created GitHub release as 'latest' (default: true) + -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) + -o, --owner The repo owner + -r, --repo The repo name + -n, --install-dir The Path to install the cr tool + -i, --install-only Just install the cr tool + -s, --skip-packaging Skip the packaging step (run your own packaging before using the releaser) + --skip-existing Skip package upload if release exists + -l, --mark-as-latest Mark the created GitHub release as 'latest' (default: true) + --distribute-charts Push charts to a remote registry (OCI) EOF } @@ -49,6 +50,7 @@ main() { local skip_packaging= local skip_existing= local mark_as_latest=true + local distribute_charts= parse_command_line "$@" @@ -76,9 +78,14 @@ main() { rm -rf .cr-index mkdir -p .cr-index + if [[ $distribute_charts ]]; then + remote_registry_login + fi + for chart in "${changed_charts[@]}"; do if [[ -d "$chart" ]]; then package_chart "$chart" + remote_registry_push "$chart" else echo "Chart '$chart' no longer exists in repo. Skipping it..." fi @@ -187,6 +194,12 @@ parse_command_line() { shift fi ;; + --distribute-charts) + if [[ -n "${2:-}" ]]; then + distribute_charts="$2" + shift + fi + ;; *) break ;; @@ -218,6 +231,15 @@ parse_command_line() { install_chart_releaser exit 0 fi + + if [[ -n "$distribute_charts" ]]; then + echo "Will connect to remote registry with environment variables 'REMOTE_REGISTRY_URL', 'REMOTE_REGISTRY_USERNAME', 'REMOTE_REGISTRY_PASSWORD'" + [[ -n "${REMOTE_REGISTRY_URL:?Error: Environment variable REMOTE_REGISTRY_URL must be set}" ]] || exit 1 + REMOTE_REGISTRY_URL="${REMOTE_REGISTRY_URL#*://}" + [[ -n "${REMOTE_REGISTRY_USERNAME:?Error: Environment variable REMOTE_REGISTRY_USERNAME must be set}" ]] || exit 1 + [[ -n "${REMOTE_REGISTRY_PASSWORD:?Error: Environment variable REMOTE_REGISTRY_PASSWORD must be set}" ]] || exit 1 + remote_registry_login + fi } install_chart_releaser() { @@ -308,5 +330,26 @@ update_index() { echo 'Updating charts repo index...' cr index "${args[@]}" } +remote_registry_login() { + echo "Logging in to the remote registry '$REMOTE_REGISTRY_URL'..." + if helm registry login "$REMOTE_REGISTRY_URL" --username "$REMOTE_REGISTRY_USERNAME " --password "$REMOTE_REGISTRY_PASSWORD"; then + echo "Login to the remote registry successful." + else + echo "Failed to login to the remote registry." + exit 1 + fi +} +remote_registry_push() { + local chart="$1" + local registry_url="$REMOTE_REGISTRY_URL" + local chart_file=$(ls $(pwd)/.cr-release-packages/$(basename "$chart")-*.tgz) + if [[ ! -e $chart_file ]]; then + echo "ERROR: Chart file '$chart_file' not found." >&2 + exit 1 + fi + + echo "Pushing chart '$chart_file' to remote registry oci://'$registry_url'/helm..." + helm push "$chart_file" "oci://$registry_url/helm" +} main "$@"