diff --git a/action.yml b/action.yml index 3201c9d..124eeec 100644 --- a/action.yml +++ b/action.yml @@ -36,5 +36,8 @@ runs: args+=(--charts-repo-url "${{ inputs.charts_repo_url }}") fi + # Install yq + sudo snap install yq + "$GITHUB_ACTION_PATH/cr.sh" "${args[@]}" shell: bash diff --git a/cr.sh b/cr.sh index 419cf82..010c719 100755 --- a/cr.sh +++ b/cr.sh @@ -50,13 +50,9 @@ main() { repo_root=$(git rev-parse --show-toplevel) pushd "$repo_root" > /dev/null - echo 'Looking up latest tag...' - local latest_tag - latest_tag=$(lookup_latest_tag) - - echo "Discovering changed charts since '$latest_tag'..." + echo "Discovering changed charts..." local changed_charts=() - readarray -t changed_charts <<< "$(lookup_changed_charts "$latest_tag")" + readarray -t changed_charts <<< "$(lookup_changed_charts)" if [[ -n "${changed_charts[*]}" ]]; then install_chart_releaser @@ -199,38 +195,18 @@ install_chart_releaser() { fi } -lookup_latest_tag() { - git fetch --tags > /dev/null 2>&1 - - if ! git describe --tags --abbrev=0 2> /dev/null; then - git rev-list --max-parents=0 --first-parent HEAD - fi -} - -filter_charts() { - while read -r chart; do - [[ ! -d "$chart" ]] && continue - local file="$chart/Chart.yaml" - if [[ -f "$file" ]]; then - echo "$chart" - else - echo "WARNING: $file is missing, assuming that '$chart' is not a Helm chart. Skipping." 1>&2 +lookup_changed_charts() { + charts_dir=charts + charts=$(find "$charts_dir" -name Chart.yaml -type f -exec dirname {} +) + for chart_path in $charts; do + chart_version=$(helm show chart $chart_path | yq eval '.version' -) + chart_tag="$(basename $chart_path)-$chart_version" + if [ ! $(git tag -l $chart_tag) ]; then + echo $chart_path fi done } -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" | wc -l) + 1 )) - local fields="1-${depth}" - - cut -d '/' -f "$fields" <<< "$changed_files" | uniq | filter_charts -} - package_chart() { local chart="$1"