fix(ci): true using functions for change detection inside CI

This commit is contained in:
kjeld Schouten-Lebbing 2022-04-01 11:11:13 +02:00
parent 8ca2bd58c4
commit 322ed9f5f2
No known key found for this signature in database
GPG Key ID: 4CDAD4A532BC1EDB
1 changed files with 35 additions and 0 deletions

View File

@ -54,6 +54,41 @@ runs:
id: filter-bumped-charts
shell: bash
run: |
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
}
export -f lookup_latest_tag
filter_charts() {
while read -r chart; do
[[ ! -d "$chart" ]] && continue
if [[ $(git diff $latest_tag $chart/Chart.yaml | grep "+version") ]]; then
echo "$chart"
else
echo "Version not bumped. Skipping." 1>&2
fi
done
}
export -f filter_charts
lookup_changed_charts() {
local commit="$1"
local $charts_dir="charts/**"
local changed_files
changed_files=$(git diff --find-renames --name-only "$commit" -- "$charts_dir" | grep "Chart.yaml")
local depth=$(( $(tr "/" "\n" <<< "$charts_dir" | sed '/^\(\.\)*$/d' | wc -l) + 1 ))
local fields="1-${depth}"
cut -d '/' -f "$fields" <<< "$changed_files" | uniq | filter_charts
}
export -f lookup_changed_charts
repo_root=$(git rev-parse --show-toplevel)
pushd "$repo_root" > /dev/null