@@ -26,34 +26,37 @@ jobs:
2626 | sed 's/.*"\(.*\)"/\1/')
2727 echo "version=$VERSION" >> "$GITHUB_OUTPUT"
2828
29- - name : Compute release tag
30- id : tag
29+ - name : Check if release already exists
30+ id : check
31+ env :
32+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
3133 run : |
3234 VERSION="${{ steps.version.outputs.version }}"
33- # Append short SHA if a tag for this exact version already exists,
34- # so rapid merges never collide on the same tag.
35- if git rev-parse "v${VERSION}" >/dev/null 2>&1; then
36- SHORT_SHA=$(git rev-parse --short HEAD)
37- TAG="v${VERSION}-${SHORT_SHA}"
35+ TAG="v${VERSION}"
36+ if gh release view "$TAG" >/dev/null 2>&1; then
37+ echo "exists=true" >> "$GITHUB_OUTPUT"
38+ echo "Release $TAG already exists — skipping."
3839 else
39- TAG="v${VERSION} "
40+ echo "exists=false" >> "$GITHUB_OUTPUT "
4041 fi
4142 echo "tag=$TAG" >> "$GITHUB_OUTPUT"
4243
4344 - name : Build changelog
45+ if : steps.check.outputs.exists == 'false'
4446 run : |
45- LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
47+ LAST_TAG=$(git describe --tags --abbrev=0 --exclude="${{ steps.check.outputs.tag }}" 2>/dev/null || echo "")
4648 if [ -z "$LAST_TAG" ]; then
4749 git log --pretty=format:"- %s" HEAD | head -20 > /tmp/changelog.txt
4850 else
4951 git log "${LAST_TAG}..HEAD" --pretty=format:"- %s" > /tmp/changelog.txt
5052 fi
5153
5254 - name : Create GitHub Release
55+ if : steps.check.outputs.exists == 'false'
5356 env :
5457 GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
5558 run : |
56- TAG="${{ steps.tag .outputs.tag }}"
59+ TAG="${{ steps.check .outputs.tag }}"
5760 gh release create "$TAG" \
5861 --title "$TAG" \
5962 --notes-file /tmp/changelog.txt \
0 commit comments