Skip to content

Commit bde5a2e

Browse files
committed
refactor release script
1 parent c12b7ec commit bde5a2e

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

release.sh

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#!/usr/bin/env bash
22

3-
set -x
4-
53
set -euo pipefail
64

75
# === CONFIGURATION ===
@@ -27,10 +25,8 @@ fi
2725
echo "🔄 Switching to '$MAIN_BRANCH' and pulling latest changes..."
2826
git checkout "$MAIN_BRANCH"
2927

30-
# By setting GIT_TERMINAL_PROMPT=0, we tell Git to fail immediately
31-
# if it needs to interactively ask for credentials, instead of hanging.
3228
if ! GIT_TERMINAL_PROMPT=0 git pull origin "$MAIN_BRANCH"; then
33-
echo "❌ Git Error: Failed to pull from origin. Please ensure your git credentials (SSH key, PAT) are configured correctly and do not require interactive prompting."
29+
echo "❌ Git Error: Failed to pull from origin. Please ensure your git credentials are configured correctly."
3430
exit 1
3531
fi
3632

@@ -56,12 +52,11 @@ while [[ $# -gt 0 ]]; do
5652
done
5753

5854
# --- Detect and Calculate Version ---
55+
# This logic block is the corrected part.
5956
if [[ -z "$VERSION" ]]; then
60-
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null)
61-
if [[ -z "$LATEST_TAG" ]]; then
62-
echo "🔍 No existing tags found. Creating initial release."
63-
VERSION="$INITIAL_VERSION"
64-
else
57+
# We check if the 'git describe' command SUCCEEDS. If it fails, it means no tags exist.
58+
if LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null); then
59+
# The command succeeded, so tags exist.
6560
echo "🔍 Latest tag found: $LATEST_TAG"
6661
if [[ $LATEST_TAG =~ ^v([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
6762
MAJOR="${BASH_REMATCH[1]}"
@@ -77,6 +72,10 @@ if [[ -z "$VERSION" ]]; then
7772
patch) ((PATCH++)) ;;
7873
esac
7974
VERSION="v$MAJOR.$MINOR.$PATCH"
75+
else
76+
# The command failed, which means no tags were found.
77+
echo "🔍 No existing tags found. Creating initial release."
78+
VERSION="$INITIAL_VERSION"
8079
fi
8180
fi
8281

@@ -106,7 +105,6 @@ git tag -a "$VERSION" -m "Release $VERSION"
106105
echo "2. Pushing tag to GitHub..."
107106
if ! GIT_TERMINAL_PROMPT=0 git push origin "$VERSION"; then
108107
echo "❌ Git Error: Failed to push the new tag. Please check your permissions and credentials."
109-
# Attempt to clean up the failed tag locally
110108
git tag -d "$VERSION"
111109
exit 1
112110
fi
@@ -126,6 +124,4 @@ echo "5. Notifying Go proxy..."
126124
) &
127125

128126
echo ""
129-
echo "✅ Release $VERSION completed successfully!"
130-
echo " Visit the release page at: https://github.com/$REPO/releases/tag/$VERSION"
131-
echo " Track the package on: https://pkg.go.dev/$REPO@$VERSION"
127+
echo "✅ Release $VERSION completed successfully!"

0 commit comments

Comments
 (0)