Only package charts when the chart version has changed
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:
https://github.com/helm/chart-releaser-action/blob/d1e09fd16821c091b45aa754f65bae4dd675d425/cr.sh#L297
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)
This would be an awesome addition for a workflow where the charts should be pushed to an OCI registry as well:
# deploy charts to github pages
- uses: helm/[email protected]
id: cr
env:
CR_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CR_GENERATE_RELEASE_NOTES: true
CR_SKIP_EXISTING: true
# setup access to container registry
- uses: docker/login-action@v3
if: ${{ steps.cr.outputs.changed_charts }}
with: # [...]
# push charts to container registry
- name: Push charts to container registry
if: ${{ steps.cr.outputs.changed_charts }}
run: |
for CHART in .cr-release-packages/*; do
if [ -z "${CHART:-}" ]; then break; fi
helm push "${CHART}" oci://ghcr.io/${{ github.repository }}
done
This would be a great feature. On my side I'd like to be able to make modifications to my chart without having to release a new version each time. So be in a development phase, then bump the chart version to trigger a new release.
With the default config I get the known error about the Github release already existing. So I thought I could use the skip_existing flag for that. It correctly resolves the Github release part of the problem, but even with this flag enabled it keeps packaging and updating the index.yaml file. However this is an issue because I end up with a lot of duplicated entries for the same version, and more problematic the artifact hashes are wrong since they correspond to newer packages that were never uploaded (since the github release part was skipped).
I'm not sure if this can be considered a bug of the action were the cr index part should honor the skip_existing flag or if this needs to be a separate new feature as requested here.
We have the same issue, even though the chart has changed and is already released, It keeps packaging and updating index.yaml