From 22d8d2f9af2567da4952c8dd68ec4e19edf2e934 Mon Sep 17 00:00:00 2001 From: Rob Kaufman Date: Fri, 16 Feb 2024 00:22:31 -0800 Subject: [PATCH] more dots --- .github/actions/chart-releaser/action.yaml | 117 ------- .github/actions/chart-releaser/cr.sh | 384 --------------------- .github/workflows/release.yaml | 2 +- 3 files changed, 1 insertion(+), 502 deletions(-) delete mode 100644 .github/actions/chart-releaser/action.yaml delete mode 100755 .github/actions/chart-releaser/cr.sh diff --git a/.github/actions/chart-releaser/action.yaml b/.github/actions/chart-releaser/action.yaml deleted file mode 100644 index 592b680..0000000 --- a/.github/actions/chart-releaser/action.yaml +++ /dev/null @@ -1,117 +0,0 @@ -name: "Helm OCI Charts Releaser" -description: "Publish multiple Helm charts into an OCI registry" -author: "dennybaa" -branding: - color: blue - icon: anchor -inputs: - version: - description: "The chart-releaser version to use (default: v3.13.2)" - required: false - default: v3.13.2 - charts_dir: - description: The chart(s) directory - required: false - oci_registry: - description: The OCI registry host - required: true - oci_username: - description: The username used to login to the OCI registry - required: true - oci_password: - description: The OCI user's password - required: true - oci_name: - description: "Specifies name of the released helm chart. Defaults to the name from Chart.yaml" - required: false - github_token: - description: Github Actions token must be provided to manage release creation and update - required: true - install_dir: - description: "Helm installation directory" - required: false - skip_helm_install: - description: "Just install helm tool and don't release any charts" - required: false - skip_dependencies: - description: "Skip dependency update during packaging" - required: false - skip_upload: - description: "Skip the chart package upload if the GithHub release exists" - required: false - mark_as_latest: - description: "Mark the created GitHub release as 'latest'" - required: false - default: true - tag_name_pattern: - description: "Specifies GitHub repository release naming pattern (ex. '{chartName}-chart')" - required: false -outputs: - changed_charts: - description: "A comma-separated list of charts that were released on this run. Will be an empty string if no updates were detected, will be unset if `--skip_packaging` is used: in the latter case your custom packaging step is responsible for setting its own outputs if you need them." - value: ${{ steps.release.outputs.changed_charts }} - chart_version: - description: "The version of the most recently generated charts; will be set even if no charts have been updated since the last run." - value: ${{ steps.release.outputs.chart_version }} - -runs: - using: composite - steps: - - id: release - run: | - if [[ -n "${{ inputs.version }}" ]]; then - args+=(--version "${{ inputs.version }}") - fi - - if [[ -n "${{ inputs.charts_dir }}" ]]; then - args+=(--charts-dir "${{ inputs.charts_dir }}") - fi - - if [[ -n "${{ inputs.oci_registry }}" ]]; then - args+=(--oci-registry "${{ inputs.oci_registry }}") - fi - - if [[ -n "${{ inputs.oci_username }}" ]]; then - args+=(--oci-username "${{ inputs.oci_username }}") - fi - - if [[ -n "${{ inputs.oci_name }}" ]]; then - args+=(--oci-name "${{ inputs.oci_name }}") - fi - - if [[ -n "${{ inputs.install_dir }}" ]]; then - args+=(--install-dir "${{ inputs.install_dir }}") - fi - - if [[ -n "${{ inputs.skip_helm_install }}" ]]; then - args+=(--skip-helm-install "${{ inputs.skip_helm_install }}") - fi - - if [[ -n "${{ inputs.skip_dependencies }}" ]]; then - args+=(--skip-dependencies "${{ inputs.skip_dependencies }}") - fi - - if [[ -n "${{ inputs.skip_existing }}" ]]; then - args+=(--skip-existing "${{ inputs.skip_existing }}") - fi - - if [[ -n "${{ inputs.mark_as_latest }}" ]]; then - args+=(--mark-as-latest "${{ inputs.mark_as_latest }}") - fi - - if [[ -n "${{ inputs.tag_name_pattern }}" ]]; then - args+=(--tag-name-pattern "${{ inputs.tag_name_pattern }}") - fi - - export GITHUB_TOKEN="${{ inputs.github_token }}" - export OCI_PASSWORD="${{ inputs.oci_password }}" - "$GITHUB_ACTION_PATH/cr.sh" "${args[@]}" - - if [[ -f changed_charts.txt ]]; then - cat changed_charts.txt >> "$GITHUB_OUTPUT" - fi - if [[ -f chart_version.txt ]]; then - cat chart_version.txt >> "$GITHUB_OUTPUT" - fi - rm -f changed_charts.txt chart_version.txt - shell: bash diff --git a/.github/actions/chart-releaser/cr.sh b/.github/actions/chart-releaser/cr.sh deleted file mode 100755 index 41f3370..0000000 --- a/.github/actions/chart-releaser/cr.sh +++ /dev/null @@ -1,384 +0,0 @@ -#!/usr/bin/env bash - -# Copyright The Helm Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -set -o errexit -set -o nounset -set -o pipefail - -DEFAULT_HELM_VERSION=v3.13.2 -ARCH=$(uname) -ARCH="${ARCH,,}-amd64" # Official helm is available only for x86_64 - -released_charts=() -dry_run=false - -show_help() { - cat < - - -h, --help Display help - -v, --version The helm version to use (default: $DEFAULT_HELM_VERSION)" - -d, --charts-dir The charts directory (default either: helm, chart or charts) - -u, --oci-username The username used to login to the OCI registry - -r, --oci-registry The OCI registry - -n, --oci-name Specifies the name of the package in the OCI registry (default is name from Chart.yml) - -t, --tag-name-pattern Specifies GitHub repository release naming pattern (ex. '{chartName}-chart') - --install-dir Specifies custom install dir - --skip-helm-install Skip helm installation (default: false) - --skip-dependencies Skip dependencies update from "Chart.yaml" to dir "charts/" before packaging (default: false) - --skip-exisiting Skip the chart push if the GithHub release exists - -l, --mark-as-latest Mark the created GitHub release as 'latest' (default: true) -EOF -} - -errexit() { - >&2 echo "$*" - exit 1 -} - -main() { - local version="$DEFAULT_HELM_VERSION" - local charts_dir= - local oci_username= - local oci_registry= - local oci_host= - local install_dir= - local skip_helm_install=false - local skip_dependencies=false - local skip_existing=true - local mark_as_latest=true - local oci_name= - local tag_name_pattern= - local repo_root= - - parse_command_line "$@" - - : "${GITHUB_TOKEN:?Environment variable GITHUB_TOKEN must be set}" - : "${OCI_PASSWORD:?Environment variable OCI_PASSWORD must be set}" - - (! $dry_run) || echo "===> DRY-RUN: TRUE" - - repo_root=$(git rev-parse --show-toplevel) - pushd "$repo_root" >/dev/null - - find_charts_dir - echo 'Looking up latest tag...' - - local latest_tag - latest_tag=$(lookup_latest_tag) - - echo "Discovering changed charts since '$latest_tag'..." - local changed_charts=() - readarray -t changed_charts <<<"$(lookup_changed_charts "$latest_tag")" - - if [[ -n "${changed_charts[*]}" ]]; then - install_helm - helm_login - - for chart in "${changed_charts[@]}"; do - local desc name version info=() - readarray -t info <<<"$(chart_info "$chart")" - desc="${info[0]}" - if [[ -n ${oci_pattern} ]]; then - name="${oci_pattern}" - else - name="${info[1]}" - fi - version="${info[2]}" - - package_chart "$chart" - release_chart "$chart" "$name" "$version" "$desc" - done - - echo "released_charts=$( - IFS=, - echo "${released_charts[*]}" - )" >released_charts.txt - else - echo "Nothing to do. No chart changes detected." - echo "released_charts=" >released_charts.txt - fi - - echo "chart_version=${latest_tag}" >chart_version.txt - popd >/dev/null -} - -parse_command_line() { - while [ "${1:-}" != "-" ]; do - case "${1:-}" in - -h | --help) - show_help - exit - ;; - -v | --version) - if [[ -n "${2:-}" ]]; then - version="$2" - shift - else - echo "ERROR: '-v|--version' cannot be empty." >&2 - show_help - exit 1 - fi - ;; - -d | --charts-dir) - if [[ -n "${2:-}" ]]; then - charts_dir="$2" - shift - else - echo "ERROR: '-d|--charts-dir' cannot be empty." >&2 - show_help - exit 1 - fi - ;; - -u | --oci-username) - if [[ -n "${2:-}" ]]; then - oci_username="$2" - shift - else - echo "ERROR: '--oci-username' cannot be empty." >&2 - show_help - exit 1 - fi - ;; - -r | --oci-registry) - if [[ -n "${2:-}" ]]; then - oci_registry="$2" - shift - else - echo "ERROR: '--oci-registry' cannot be empty." >&2 - show_help - exit 1 - fi - ;; - --install-dir) - if [[ -n "${2:-}" ]]; then - install_dir="$2" - shift - fi - ;; - --skip-helm-install) - if [[ -n "${2:-}" ]]; then - skip_helm_install="$2" - shift - fi - ;; - --skip-dependencies) - if [[ -n "${2:-}" ]]; then - skip_dependencies="$2" - shift - fi - ;; - --skip-existing) - if [[ -n "${2:-}" ]]; then - skip_existing="$2" - shift - fi - ;; - -l | --mark-as-latest) - if [[ -n "${2:-}" ]]; then - mark_as_latest="$2" - shift - fi - ;; - -n | --oci-name) - if [[ -n "${2:-}" ]]; then - oci_name="$2" - shift - fi - ;; - -t | --tag-name-pattern) - if [[ -n "${2:-}" ]]; then - tag_name_pattern="$2" - shift - fi - ;; - *) - break - ;; - esac - - shift - done - - if [[ -z "$oci_username" ]]; then - echo "ERROR: '-u|--oci-username' is required." >&2 - show_help - exit 1 - fi - - if [[ -z "$oci_registry" ]]; then - echo "ERROR: '-r|--oci-registry' is required." >&2 - show_help - exit 1 - fi - - if [[ -n $tag_name_pattern && $tag_name_pattern != *"{chartName}"* ]]; then - echo "ERROR: Name pattern must contain '{chartName}' field." >&2 - show_help - exit 1 - fi - - if [[ -z "$install_dir" ]]; then - # use /tmp or RUNNER_TOOL_CACHE in GitHub Actions - install_dir="${RUNNER_TOOL_CACHE:-/tmp}/cra/$ARCH" - - export HELM_CACHE_HOME="${install_dir}/.cache" - export HELM_CONFIG_HOME="${install_dir}/.config" - export HELM_DATA_HOME="${install_dir}.share" - fi -} - -install_helm() { - if ( "$skip_helm_install" ) && ( which helm &> /dev/null ); then - echo "Skipng helm install. Using existing helm..." - return - elif ( "$skip_helm_install" ); then - errexit "ERROR: Remove --skip-helm-install or preinstall!" - fi - - if [[ ! -x "$install_dir/helm" ]]; then - mkdir -p "$install_dir" - - echo "Installing Helm ($version) to $install_dir..." - curl -sSLo helm.tar.gz "https://get.helm.sh/helm-${version}-${ARCH}.tar.gz" - curl -sSL "https://get.helm.sh/helm-${version}-${ARCH}.tar.gz.sha256sum" | \ - sed 's/helm-.*/helm.tar.gz/' > helm.sha256sum - - if ( ! sha256sum -c helm.sha256sum ); then - rm -f helm.tar.gz helm.sha256sum - errexit "ERROR: Aborting helm checksum is invalid" - fi - - tar -C "$install_dir/.." -xzf helm.tar.gz "$ARCH/helm" - rm -f helm.tar.gz helm.sha256sum - else - echo "Helm is found in the install directory" - fi - - echo 'Setting PATH to use helm from the install directory...' - export PATH="$install_dir:$PATH" -} - -lookup_latest_tag() { - git fetch --tags >/dev/null 2>&1 - - if ! git describe --tags --abbrev=0 HEAD~ 2>/dev/null; then - git rev-list --max-parents=0 --first-parent HEAD - fi -} - -filter_charts() { - local charts=() - while read -r path; do - if [[ -f "${path}/Chart.yaml" ]]; then - charts+=("$path") - fi - done - printf "%s\n" "${charts[@]}" -} - -find_charts_dir() { - local cdirs=() - if [ -n "$charts_dir" ]; then return; fi - if [ -f "helm/Chart.yaml" ]; then cdirs+=("."); fi - if [ -f "chart/Chart.yaml" ]; then cdirs+=("."); fi - if (( "${#cdirs[@]}" > 1 )); then - errexit "ERROR: Can't use both helm and chart directory." - fi - charts_dir="${cdirs[0]:-charts/}" -} - -lookup_changed_charts() { - local commit="$1" - - local changed_files - changed_files=$(git diff --find-renames --name-only "$commit" -- "$charts_dir") - - local depth=$(($(tr "/" "\n" <<<"$charts_dir" | sed '/^\(\.\)*$/d' | wc -l) + 1)) - local fields="1-${depth}" - - cut -d '/' -f "$fields" <<<"$changed_files" | uniq | filter_charts -} - -package_chart() { - local chart="$1" flags= - ( $skip_dependencies ) || flags="-u" - - echo "Packaging chart '$chart'..." - dry_run helm package "$chart" $flags -d "${install_dir}/package/$chart" -} - -dry_run() { - # dry-run on - if ($dry_run); then - { set -x; echo "$@" >/dev/null; set +x; } 2>&1 | sed '/set +x/d' >&2; return - else - "$@" - fi -} - -chart_info() { - local chart_dir="$1" - # use readarray with the retruned line - helm show chart "$chart_dir" | sed -En '/^(description|name|version)/p' | sort | sed 's/^.*: //' -} - -# get github release tag -release_tag() { - local name="$1" version="$2" - if [ -n "$tag_name_pattern" ]; then - tag="${tag_name_pattern//\{chartName\}/$name}" - fi - echo "${tag:-$name}-$version" -} - -release_exists() { - local tag="$1" - # fields: release tagName date - dry_run gh release ls | tr -s '[:blank:]' | sed -E 's/\sLatest//' | cut -f 1 | grep -q "$tag" && echo true || echo false -} - -release_chart() { - local releaseExists flags tag chart_package chart="$1" name="$2" version="$3" desc="$4" - tag=$(release_tag "$name" "$version") - chart_package="${install_dir}/package/${chart}/${name}-${version}.tgz" - releaseExists=$(release_exists "$tag") - - if ($releaseExists && $skip_existing); then - echo "Release tag '$tag' is present. Skip chart push (skip_existing=true)..." - return - fi - dry_run helm push "${chart_package}" "oci://${oci_registry}" - - if (! $releaseExists); then - # shellcheck disable=SC2086 - (! $mark_as_latest) || flags="--latest" - dry_run gh release create "$tag" $flags --title "$tag" --notes "$desc" - fi - - # (re)upload package, i.e. overwrite, since skip_existing is not provided. - dry_run gh release upload "$tag" "$chart_package" --clobber - released_charts+=("$chart") -} - -helm_login() { - # Get the cleared host url - oci_registry="${oci_registry#oci://}" - oci_host="${oci_registry%%/*}" - echo "$OCI_PASSWORD" | dry_run helm registry login -u "${oci_username}" --password-stdin "${oci_host}" -} - -main "$@" diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 91ca540..1f3308e 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -45,6 +45,6 @@ jobs: oci_registry: ghcr.io/samvera-labs oci_username: samvera-labs oci_password: ${{ secrets.GITHUB_TOKEN }} - oci_name: charts/fcrepo + oci_directory: charts github_token: ${{ secrets.GITHUB_TOKEN }} tag_name_pattern: "{chartName}-chart"