From 84698b7cd939ea90cb3b9ced9e785f865c71c79e Mon Sep 17 00:00:00 2001 From: Cyril Jouve Date: Sun, 15 Oct 2023 23:49:00 +0200 Subject: [PATCH] Optionally use chart-testing to detect changed charts --- README.md | 9 +++++++++ cr.sh | 15 ++++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 7b06e14..1d3a633 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,11 @@ A GitHub action to turn a GitHub project into a self-hosted Helm chart repo, usi - `changed_charts`: 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. - `chart_version`: The version of the most recently generated charts; will be set even if no charts have been updated since the last run. +### Changed charts detection + +If [chart-testing](https://github.com/helm/chart-testing) is present in the PATH, it will be used to detect changed charts using `ct list-changed` command. +If not present, it will fallback to a simpler method of detection using `git diff`. + ### Environment variables - `CR_TOKEN` (required): The GitHub token of this repository (`${{ secrets.GITHUB_TOKEN }}`) @@ -69,6 +74,10 @@ jobs: - name: Install Helm uses: azure/setup-helm@v3 + # optional, setup chart-testing for changed charts detection + - name: Set up chart-testing + uses: helm/chart-testing-action@v2.5.0 + - name: Run chart-releaser uses: helm/chart-releaser-action@v1.6.0 env: diff --git a/cr.sh b/cr.sh index 4897b65..3252a00 100755 --- a/cr.sh +++ b/cr.sh @@ -293,13 +293,18 @@ filter_charts() { lookup_changed_charts() { local commit="$1" - local changed_files - changed_files=$(git diff --find-renames --name-only "$commit" -- "$charts_dir") + if command -v ct >/dev/null; then + echo Using ct to detect changed charts + ct list-changed --since "$commit" --chart-dirs "$charts_dir" + else + 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}" + local depth=$(($(tr "/" "\n" <<<"$charts_dir" | sed '/^\(\.\)*$/d' | wc -l) + 1)) + local fields="1-${depth}" - cut -d '/' -f "$fields" <<<"$changed_files" | uniq | filter_charts + cut -d '/' -f "$fields" <<<"$changed_files" | uniq | filter_charts + fi } package_chart() {