@@ -52,34 +52,50 @@ command -v git >/dev/null || { echo "git is required"; exit 1; }
5252: " ${THREATWINDS_API_KEY:? THREATWINDS_API_KEY is required} "
5353: " ${THREATWINDS_API_SECRET:? THREATWINDS_API_SECRET is required} "
5454
55+ # ─── Resolve current ref (tag may not exist yet when pipeline runs) ────────────
56+ if git rev-parse " $CURRENT_TAG " > /dev/null 2>&1 ; then
57+ CURRENT_REF=" $CURRENT_TAG "
58+ else
59+ echo " Tag $CURRENT_TAG not found in repo yet, using HEAD"
60+ CURRENT_REF=" HEAD"
61+ fi
62+
5563# ─── Resolve previous tag if not provided ─────────────────────────────────────
5664if [ -z " $PREVIOUS_TAG " ]; then
5765 echo " Auto-detecting previous tag..."
5866 ALL_TAGS=$( git tag --sort=-v:refname)
59- FOUND_CURRENT=false
60- for tag in $ALL_TAGS ; do
61- if [ " $FOUND_CURRENT " = true ]; then
62- PREVIOUS_TAG=" $tag "
63- break
64- fi
65- if [ " $tag " = " $CURRENT_TAG " ]; then
66- FOUND_CURRENT=true
67- fi
68- done
67+ if [ " $CURRENT_REF " = " $CURRENT_TAG " ]; then
68+ # Tag exists: find the tag immediately before CURRENT_TAG
69+ FOUND_CURRENT=false
70+ for tag in $ALL_TAGS ; do
71+ if [ " $FOUND_CURRENT " = true ]; then
72+ PREVIOUS_TAG=" $tag "
73+ break
74+ fi
75+ if [ " $tag " = " $CURRENT_TAG " ]; then
76+ FOUND_CURRENT=true
77+ fi
78+ done
79+ else
80+ # Tag doesn't exist yet: use the most recent existing tag
81+ PREVIOUS_TAG=$( echo " $ALL_TAGS " | head -1)
82+ [ -n " $PREVIOUS_TAG " ] && echo " Tag not yet created; using most recent existing tag: $PREVIOUS_TAG "
83+ fi
6984 if [ -z " $PREVIOUS_TAG " ]; then
7085 PREVIOUS_TAG=$( git rev-list --max-parents=0 HEAD | head -1)
7186 echo " No previous tag found, using first commit: $PREVIOUS_TAG "
7287 fi
7388fi
7489
7590echo " Current tag: $CURRENT_TAG "
91+ echo " Current ref: $CURRENT_REF "
7692echo " Previous tag: $PREVIOUS_TAG "
7793echo " Model: $MODEL "
7894echo
7995
8096# ─── Collect commits ──────────────────────────────────────────────────────────
81- COMMITS=$( git log " ${PREVIOUS_TAG} ..${CURRENT_TAG } " --pretty=format:" - %h %s (%an)" --no-merges)
82- COMMIT_COUNT=$( git rev-list --count " ${PREVIOUS_TAG} ..${CURRENT_TAG } " --no-merges)
97+ COMMITS=$( git log " ${PREVIOUS_TAG} ..${CURRENT_REF } " --pretty=format:" - %h %s (%an)" --no-merges)
98+ COMMIT_COUNT=$( git rev-list --count " ${PREVIOUS_TAG} ..${CURRENT_REF } " --no-merges)
8399
84100if [ -z " $COMMITS " ]; then
85101 echo " No commits found between $PREVIOUS_TAG and $CURRENT_TAG ."
0 commit comments