Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only package charts when the chart version has changed #209

Open
AndersBennedsgaard opened this issue Aug 22, 2024 · 0 comments
Open

Only package charts when the chart version has changed #209

AndersBennedsgaard opened this issue Aug 22, 2024 · 0 comments

Comments

@AndersBennedsgaard
Copy link

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant