1
1
#! /usr/bin/env bash
2
2
3
- set -x
4
-
5
3
set -euo pipefail
6
4
7
5
# === CONFIGURATION ===
27
25
echo " 🔄 Switching to '$MAIN_BRANCH ' and pulling latest changes..."
28
26
git checkout " $MAIN_BRANCH "
29
27
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.
32
28
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."
34
30
exit 1
35
31
fi
36
32
@@ -56,12 +52,11 @@ while [[ $# -gt 0 ]]; do
56
52
done
57
53
58
54
# --- Detect and Calculate Version ---
55
+ # This logic block is the corrected part.
59
56
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.
65
60
echo " 🔍 Latest tag found: $LATEST_TAG "
66
61
if [[ $LATEST_TAG =~ ^v([0-9]+)\. ([0-9]+)\. ([0-9]+)$ ]]; then
67
62
MAJOR=" ${BASH_REMATCH[1]} "
@@ -77,6 +72,10 @@ if [[ -z "$VERSION" ]]; then
77
72
patch) (( PATCH++ )) ;;
78
73
esac
79
74
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 "
80
79
fi
81
80
fi
82
81
@@ -106,7 +105,6 @@ git tag -a "$VERSION" -m "Release $VERSION"
106
105
echo " 2. Pushing tag to GitHub..."
107
106
if ! GIT_TERMINAL_PROMPT=0 git push origin " $VERSION " ; then
108
107
echo " ❌ Git Error: Failed to push the new tag. Please check your permissions and credentials."
109
- # Attempt to clean up the failed tag locally
110
108
git tag -d " $VERSION "
111
109
exit 1
112
110
fi
@@ -126,6 +124,4 @@ echo "5. Notifying Go proxy..."
126
124
) &
127
125
128
126
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