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

Simplify chart change detection #80

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
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,8 @@ runs:
args+=(--charts-repo-url "${{ inputs.charts_repo_url }}")
fi

# Install yq
sudo snap install yq

"$GITHUB_ACTION_PATH/cr.sh" "${args[@]}"
shell: bash
44 changes: 10 additions & 34 deletions cr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,9 @@ main() {
repo_root=$(git rev-parse --show-toplevel)
pushd "$repo_root" > /dev/null

echo 'Looking up latest tag...'
local latest_tag
latest_tag=$(lookup_latest_tag)

echo "Discovering changed charts since '$latest_tag'..."
echo "Discovering changed charts..."
local changed_charts=()
readarray -t changed_charts <<< "$(lookup_changed_charts "$latest_tag")"
readarray -t changed_charts <<< "$(lookup_changed_charts)"

if [[ -n "${changed_charts[*]}" ]]; then
install_chart_releaser
Expand Down Expand Up @@ -199,38 +195,18 @@ install_chart_releaser() {
fi
}

lookup_latest_tag() {
git fetch --tags > /dev/null 2>&1

if ! git describe --tags --abbrev=0 2> /dev/null; then
git rev-list --max-parents=0 --first-parent HEAD
fi
}

filter_charts() {
while read -r chart; do
[[ ! -d "$chart" ]] && continue
local file="$chart/Chart.yaml"
if [[ -f "$file" ]]; then
echo "$chart"
else
echo "WARNING: $file is missing, assuming that '$chart' is not a Helm chart. Skipping." 1>&2
lookup_changed_charts() {
charts_dir=charts
charts=$(find "$charts_dir" -name Chart.yaml -type f -exec dirname {} +)
for chart_path in $charts; do
chart_version=$(helm show chart $chart_path | yq eval '.version' -)
chart_tag="$(basename $chart_path)-$chart_version"
if [ ! $(git tag -l $chart_tag) ]; then
echo $chart_path
fi
done
}

lookup_changed_charts() {
local commit="$1"

local changed_files
changed_files=$(git diff --find-renames --name-only "$commit" -- "$charts_dir")

local depth=$(( $(tr "/" "\n" <<< "$charts_dir" | wc -l) + 1 ))
local fields="1-${depth}"

cut -d '/' -f "$fields" <<< "$changed_files" | uniq | filter_charts
}

package_chart() {
local chart="$1"

Expand Down