Skip to content

Commit d6b7f39

Browse files
committed
Enhance GitHub Release workflow to skip existing releases and improve tag handling
1 parent c496022 commit d6b7f39

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

.github/workflows/publish-maven.yml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,21 +177,28 @@ jobs:
177177
VERSION="${{ needs.publish-maven.outputs.version }}"
178178
GROUP_ID="io.github.copilot-community-sdk"
179179
ARTIFACT_ID="copilot-sdk"
180+
CURRENT_TAG="v${VERSION}"
181+
182+
if gh release view "${CURRENT_TAG}" >/dev/null 2>&1; then
183+
echo "Release ${CURRENT_TAG} already exists. Skipping creation."
184+
exit 0
185+
fi
180186
181187
# Generate release notes from template
182188
export VERSION GROUP_ID ARTIFACT_ID
183189
RELEASE_NOTES=$(envsubst < .github/workflows/notes.template)
184190
185191
# Get the previous tag for generating notes
186-
# Fetch all tags and find the previous version tag (excluding 'latest' and the current tag)
187-
CURRENT_TAG="v${VERSION}"
188-
PREV_TAG=$(git tag -l 'v*' --sort=-version:refname | grep -v "^${CURRENT_TAG}$" | grep -v "^latest$" | head -n 1)
192+
PREV_TAG=$(git tag --list 'v*' --sort=-version:refname \
193+
| grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' \
194+
| grep -Fxv "${CURRENT_TAG}" \
195+
| head -n 1)
189196
190197
echo "Current tag: ${CURRENT_TAG}"
191198
echo "Previous tag: ${PREV_TAG}"
192199
193200
# Build the gh release command
194-
GH_ARGS=("v${VERSION}")
201+
GH_ARGS=("${CURRENT_TAG}")
195202
GH_ARGS+=("--title" "Copilot Java SDK ${VERSION}")
196203
GH_ARGS+=("--notes" "${RELEASE_NOTES}")
197204
GH_ARGS+=("--generate-notes")

0 commit comments

Comments
 (0)