Skip to content

Commit

Permalink
Simplify chart change detection
Browse files Browse the repository at this point in the history
  • Loading branch information
florisvdg committed May 3, 2021
1 parent a996ace commit a1a695b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 34 deletions.
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

0 comments on commit a1a695b

Please sign in to comment.