Skip to content

Commit 1a23f70

Browse files
committed
Simplify chart change detection
Signed-off-by: Floris van der Grinten <[email protected]>
1 parent a996ace commit 1a23f70

File tree

2 files changed

+13
-34
lines changed

2 files changed

+13
-34
lines changed

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,8 @@ runs:
3636
args+=(--charts-repo-url "${{ inputs.charts_repo_url }}")
3737
fi
3838
39+
# Install yq
40+
sudo snap install yq
41+
3942
"$GITHUB_ACTION_PATH/cr.sh" "${args[@]}"
4043
shell: bash

cr.sh

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,9 @@ main() {
5050
repo_root=$(git rev-parse --show-toplevel)
5151
pushd "$repo_root" > /dev/null
5252

53-
echo 'Looking up latest tag...'
54-
local latest_tag
55-
latest_tag=$(lookup_latest_tag)
56-
57-
echo "Discovering changed charts since '$latest_tag'..."
53+
echo "Discovering changed charts..."
5854
local changed_charts=()
59-
readarray -t changed_charts <<< "$(lookup_changed_charts "$latest_tag")"
55+
readarray -t changed_charts <<< "$(lookup_changed_charts)"
6056

6157
if [[ -n "${changed_charts[*]}" ]]; then
6258
install_chart_releaser
@@ -199,38 +195,18 @@ install_chart_releaser() {
199195
fi
200196
}
201197

202-
lookup_latest_tag() {
203-
git fetch --tags > /dev/null 2>&1
204-
205-
if ! git describe --tags --abbrev=0 2> /dev/null; then
206-
git rev-list --max-parents=0 --first-parent HEAD
207-
fi
208-
}
209-
210-
filter_charts() {
211-
while read -r chart; do
212-
[[ ! -d "$chart" ]] && continue
213-
local file="$chart/Chart.yaml"
214-
if [[ -f "$file" ]]; then
215-
echo "$chart"
216-
else
217-
echo "WARNING: $file is missing, assuming that '$chart' is not a Helm chart. Skipping." 1>&2
198+
lookup_changed_charts() {
199+
charts_dir=charts
200+
charts=$(find "$charts_dir" -name Chart.yaml -type f -exec dirname {} +)
201+
for chart_path in $charts; do
202+
chart_version=$(helm show chart $chart_path | yq eval '.version' -)
203+
chart_tag="$(basename $chart_path)-$chart_version"
204+
if [ ! $(git tag -l $chart_tag) ]; then
205+
echo $chart_path
218206
fi
219207
done
220208
}
221209

222-
lookup_changed_charts() {
223-
local commit="$1"
224-
225-
local changed_files
226-
changed_files=$(git diff --find-renames --name-only "$commit" -- "$charts_dir")
227-
228-
local depth=$(( $(tr "/" "\n" <<< "$charts_dir" | wc -l) + 1 ))
229-
local fields="1-${depth}"
230-
231-
cut -d '/' -f "$fields" <<< "$changed_files" | uniq | filter_charts
232-
}
233-
234210
package_chart() {
235211
local chart="$1"
236212

0 commit comments

Comments
 (0)