Skip to content

Commit 9f58b4b

Browse files
committed
fix[ci]: fix changelog script failing when tag doesn't exist yet and unblock installer on changelog failure
1 parent 913e5e0 commit 9f58b4b

2 files changed

Lines changed: 29 additions & 13 deletions

File tree

.github/scripts/generate-changelog.sh

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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 ─────────────────────────────────────
5664
if [ -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
7388
fi
7489

7590
echo "Current tag: $CURRENT_TAG"
91+
echo "Current ref: $CURRENT_REF"
7692
echo "Previous tag: $PREVIOUS_TAG"
7793
echo "Model: $MODEL"
7894
echo
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

84100
if [ -z "$COMMITS" ]; then
85101
echo "No commits found between $PREVIOUS_TAG and $CURRENT_TAG."

.github/workflows/v11-deployment-pipeline.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ jobs:
561561
build_installer_release:
562562
name: Build & Upload Installer
563563
needs: [generate_changelog, setup_deployment]
564-
if: ${{ needs.setup_deployment.outputs.tag != '' && needs.setup_deployment.outputs.environment == 'rc' }}
564+
if: ${{ always() && needs.setup_deployment.result == 'success' && needs.setup_deployment.outputs.tag != '' && needs.setup_deployment.outputs.environment == 'rc' && needs.generate_changelog.result != 'cancelled' }}
565565
uses: ./.github/workflows/installer-release.yml
566566
with:
567567
version: ${{ needs.setup_deployment.outputs.tag }}

0 commit comments

Comments
 (0)