From 92e33511bdb2c8cc8d2132f3e113e4ed032a116c Mon Sep 17 00:00:00 2001 From: Ivan Polchenko <2119240+i5okie@users.noreply.github.com> Date: Mon, 25 Sep 2023 11:13:34 -0700 Subject: [PATCH] Update lookup_latest_tag function to lookup previous tag Signed-off-by: Ivan Polchenko <2119240+i5okie@users.noreply.github.com> --- .github/actions/chart_releaser/cr.sh | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/.github/actions/chart_releaser/cr.sh b/.github/actions/chart_releaser/cr.sh index a8cb24b1..01d31db2 100644 --- a/.github/actions/chart_releaser/cr.sh +++ b/.github/actions/chart_releaser/cr.sh @@ -248,28 +248,16 @@ install_chart_releaser() { lookup_latest_tag() { git fetch --tags >/dev/null 2>&1 + latest_tag=$(git tag --sort=-creatordate | sed -n '2p') - 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 + if [ -z "$latest_tag" ]; then + # If no tags are found, return the initial commit hash + git rev-list --max-parents=0 --first-parent HEAD 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 + echo "$latest_tag" fi } - filter_charts() { while read -r chart; do [[ ! -d "$chart" ]] && continue