Skip to content

Commit aa1cacc

Browse files
committed
Handling correctly both tag release and first release
1 parent 2504907 commit aa1cacc

1 file changed

Lines changed: 29 additions & 7 deletions

File tree

cr.sh

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -249,11 +249,27 @@ install_chart_releaser() {
249249
lookup_latest_tag() {
250250
git fetch --tags >/dev/null 2>&1
251251

252-
if ! git describe --tags --abbrev=0 HEAD~ 2>/dev/null; then
253-
git rev-list --max-parents=0 --first-parent HEAD
252+
if git symbolic-ref --short -q HEAD; then
253+
if ! git describe --tags --abbrev=0 HEAD~ 2>/dev/null; then
254+
git rev-list --max-parents=0 --first-parent HEAD
255+
fi
256+
else
257+
# In a detached HEAD state, such as when the pipeline
258+
# is triggered by a push on a tag commit, we need to look back
259+
# by date
260+
current_commit=$(git rev-parse HEAD)
261+
for tag in $(git tag --sort=-creatordate); do
262+
if [ $(git rev-parse "$tag") = "$current_commit" ]; then
263+
continue
264+
else
265+
echo "$tag"
266+
break
267+
fi
268+
done
254269
fi
255270
}
256271

272+
257273
filter_charts() {
258274
while read -r chart; do
259275
[[ ! -d "$chart" ]] && continue
@@ -269,15 +285,21 @@ filter_charts() {
269285
lookup_changed_charts() {
270286
local commit="$1"
271287

272-
local changed_files
273-
changed_files=$(git diff --find-renames --name-only "$commit" -- "$charts_dir")
288+
if [ -z "$commit" ]; then
289+
# If no commit is given (i.e., no previous tag), consider all charts.
290+
find "$charts_dir" -maxdepth 1 -type d | filter_charts
291+
else
292+
local changed_files
293+
changed_files=$(git diff --find-renames --name-only "$commit" -- "$charts_dir")
274294

275-
local depth=$(($(tr "/" "\n" <<<"$charts_dir" | sed '/^\(\.\)*$/d' | wc -l) + 1))
276-
local fields="1-${depth}"
295+
local depth=$(($(tr "/" "\n" <<<"$charts_dir" | sed '/^\(\.\)*$/d' | wc -l) + 1))
296+
local fields="1-${depth}"
277297

278-
cut -d '/' -f "$fields" <<<"$changed_files" | uniq | filter_charts
298+
cut -d '/' -f "$fields" <<<"$changed_files" | uniq | filter_charts
299+
fi
279300
}
280301

302+
281303
package_chart() {
282304
local chart="$1"
283305

0 commit comments

Comments
 (0)