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

Optionally use chart-testing to detect changed charts #167

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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