Skip to content

Commit

Permalink
Optionally use chart-testing to detect changed charts
Browse files Browse the repository at this point in the history
  • Loading branch information
jouve committed Nov 27, 2023
1 parent 6203d70 commit 84698b7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}`)
Expand Down Expand Up @@ -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/[email protected]

- name: Run chart-releaser
uses: helm/[email protected]
env:
Expand Down
15 changes: 10 additions & 5 deletions cr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 84698b7

Please sign in to comment.