Skip to content

Only package charts when the chart version has changed #209

Open
@AndersBennedsgaard

Description

We need to do some preprocessing which runs dereferencing on the JSON schema we use for our Helm chart values, before packaging our charts. That means the git diff command in this action always detects changes:

changed_files=$(git diff --find-renames --name-only "$commit" -- "$charts_dir")

In my mind, it would make sense for cr to only package and release charts where the version has been bumped - at the least optionally, using a flag such as only_package_on_version_change (naming is hard..)

Currently we run the packaging step ourselves, and only detect charts that have changed their version:

source_sha="${{ github.event.pull_request.base.sha }}" # base commit in the PR
target_sha="${{ github.sha }}" # merge commit sha
# get the list of charts that have changed
changed="$(git diff --name-only --diff-filter=ACMRT "$source_sha" "$target_sha" -- "charts/*/Chart.yaml" | cut -d '/' -f 2)"

# check if the PR has modified any chart versions
# prevent https://www.shellcheck.net/wiki/SC2030 using '<<<' to read into an array
changed_charts=()
while read -r chart; do
  old_version="$(git show "$source_sha":"charts/$chart/Chart.yaml" | yq '.version')"
  new_version="$(yq '.version' "charts/$chart/Chart.yaml")"
  if [[ "$old_version" != "$new_version" ]]; then
    echo "::notice::Chart '$chart' has changed from version $old_version to $new_version"
    changed_charts+=("$chart")
  fi
done < <(echo -n "$changed")

(this releases new versions on closed PRs, so I guess this needs some changes in order to also run on pushes to main and other cases)

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions