From c5bef3e798a1f8d9f2f81f9c1131e86dd554e6c2 Mon Sep 17 00:00:00 2001 From: Edmondo Porcu Date: Sun, 6 Aug 2023 09:10:52 -0700 Subject: [PATCH] Using a different strategy for handling releasing from git tag push events Signed-off-by: Edmondo Porcu --- cr.sh | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/cr.sh b/cr.sh index 8fcfea3..8126548 100755 --- a/cr.sh +++ b/cr.sh @@ -249,11 +249,27 @@ install_chart_releaser() { lookup_latest_tag() { git fetch --tags >/dev/null 2>&1 - if ! git describe --tags --abbrev=0 HEAD~ 2>/dev/null; then - git rev-list --max-parents=0 --first-parent HEAD + if git symbolic-ref --short -q HEAD; then + if ! git describe --tags --abbrev=0 HEAD~ 2>/dev/null; then + git rev-list --max-parents=0 --first-parent HEAD + fi + else + # In a detached HEAD state, such as when the pipeline + # is triggered by a push on a tag commit, we need to look back + # by date + current_commit=$(git rev-parse HEAD) + for tag in $(git tag --sort=-creatordate); do + if [ $(git rev-parse "$tag") = "$current_commit" ]; then + continue + else + echo "$tag" + break + fi + done fi } + filter_charts() { while read -r chart; do [[ ! -d "$chart" ]] && continue