|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Exit on error |
| 4 | +set -e |
| 5 | + |
| 6 | +# Check if required commands are installed |
| 7 | +if ! command -v mvn &> /dev/null; then |
| 8 | + echo "Error: Maven (mvn) is not installed." |
| 9 | + exit 1 |
| 10 | +fi |
| 11 | + |
| 12 | +if ! command -v gh &> /dev/null; then |
| 13 | + echo "Error: GitHub CLI (gh) is not installed." |
| 14 | + exit 1 |
| 15 | +fi |
| 16 | + |
| 17 | +# Get the version from Maven |
| 18 | +VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout) |
| 19 | + |
| 20 | +# Ensure version is not empty |
| 21 | +if [[ -z "$VERSION" ]]; then |
| 22 | + echo "Error: Failed to retrieve project version." |
| 23 | + exit 1 |
| 24 | +fi |
| 25 | + |
| 26 | +# Check if the release already exists on GitHub |
| 27 | +if gh release view "$VERSION" &> /dev/null; then |
| 28 | + echo "Release $VERSION already exists. Deleting..." |
| 29 | + gh release delete "$VERSION" --yes |
| 30 | +fi |
| 31 | + |
| 32 | +# Check if the tag exists locally |
| 33 | +if git rev-parse "$VERSION" >/dev/null 2>&1; then |
| 34 | + echo "Tag $VERSION exists locally." |
| 35 | + |
| 36 | + # Check if the tag exists on GitHub |
| 37 | + if git ls-remote --tags origin | grep -q "refs/tags/$VERSION"; then |
| 38 | + echo "Tag $VERSION exists on GitHub. Deleting..." |
| 39 | + git push --delete origin "$VERSION" |
| 40 | + fi |
| 41 | + |
| 42 | + echo "Recreating tag $VERSION..." |
| 43 | + git tag -d "$VERSION" |
| 44 | +fi |
| 45 | + |
| 46 | +# Create and push the tag again |
| 47 | +git tag "$VERSION" |
| 48 | +git push origin "$VERSION" |
| 49 | + |
| 50 | +# Create a new release |
| 51 | +gh release create "$VERSION" --title "Version $VERSION" --notes "New Version Release" |
| 52 | + |
| 53 | +echo "GitHub release $VERSION created successfully!" |
| 54 | + |
0 commit comments