@@ -123,26 +123,44 @@ jobs:
123123 - name : Check if version should be bumped (alpha releases only)
124124 id : version_check
125125 if : inputs.operation == 'update' && inputs.release_type == 'alpha'
126+ env :
127+ GH_TOKEN : ${{ steps.generate_token.outputs.token || github.token }}
126128 run : |
127129 # Get current version from current branch
128130 CURRENT_VERSION="${{ steps.check.outputs.current_version }}"
129131 CURRENT_BASE="${{ steps.check.outputs.base_version }}"
130132
131- # Get version from main branch
132- git fetch origin main
133- MAIN_VERSION=$(git show origin/main:package.json | node -p "JSON.parse(require('fs').readFileSync('/dev/stdin', 'utf8')).version")
134- MAIN_BASE=$(echo "$MAIN_VERSION" | sed 's/-.*$//')
133+ # Get version from latest beta or production release (excluding alpha)
134+ LATEST_RELEASE_TAG=$(gh release list --limit 100 | cut -f3 | grep -E "(RELEASE)" | head -n1 || echo "")
135+
136+ if [ -n "$LATEST_RELEASE_TAG" ]; then
137+ # Extract base version from latest beta/production release tag
138+ LATEST_RELEASE_BASE=$(echo "$LATEST_RELEASE_TAG" | sed 's/^v//' | sed 's/-.*$//')
139+ echo "Found latest beta/production release: $LATEST_RELEASE_TAG (base: $LATEST_RELEASE_BASE)"
140+ else
141+ # No beta/production releases found, use 0.0.0 as baseline
142+ LATEST_RELEASE_BASE="0.0.0"
143+ echo "No beta/production releases found, using baseline: $LATEST_RELEASE_BASE"
144+ fi
135145
136146 echo "current_base=$CURRENT_BASE" >> $GITHUB_OUTPUT
137- echo "main_base=$MAIN_BASE " >> $GITHUB_OUTPUT
147+ echo "latest_release_base=$LATEST_RELEASE_BASE " >> $GITHUB_OUTPUT
138148
139- # Check if versions match (meaning we should bump)
140- if [ "$CURRENT_BASE" = "$MAIN_BASE " ]; then
149+ # Check if current base is same or older than latest release (meaning we should bump)
150+ if [ "$CURRENT_BASE" = "$LATEST_RELEASE_BASE " ]; then
141151 echo "should_bump=true" >> $GITHUB_OUTPUT
142- echo "β
Versions match ($CURRENT_BASE = $MAIN_BASE ) - will bump version"
152+ echo "β
Current base matches latest release ($CURRENT_BASE = $LATEST_RELEASE_BASE ) - will bump version"
143153 else
144- echo "should_bump=false" >> $GITHUB_OUTPUT
145- echo "βοΈ Versions differ ($CURRENT_BASE β $MAIN_BASE) - will use current version"
154+ # Use version comparison to check if current is newer
155+ if printf '%s\n%s\n' "$LATEST_RELEASE_BASE" "$CURRENT_BASE" | sort -V | head -n1 | grep -q "^$LATEST_RELEASE_BASE$"; then
156+ if [ "$CURRENT_BASE" != "$LATEST_RELEASE_BASE" ]; then
157+ echo "should_bump=false" >> $GITHUB_OUTPUT
158+ echo "βοΈ Current base is newer than latest release ($CURRENT_BASE > $LATEST_RELEASE_BASE) - will use current version"
159+ fi
160+ else
161+ echo "should_bump=true" >> $GITHUB_OUTPUT
162+ echo "β
Current base is older than latest release ($CURRENT_BASE < $LATEST_RELEASE_BASE) - will bump version"
163+ fi
146164 fi
147165
148166 - name : Update versions
@@ -211,9 +229,21 @@ jobs:
211229 case "${{ inputs.release_type }}" in
212230 "alpha")
213231 if [ "${{ inputs.should_bump_version }}" = "true" ] && [ "${{ steps.version_check.outputs.should_bump }}" = "true" ]; then
214- # Use our bump script to increment patch version
215- bun run version:bump
216- NEW_BASE=$(node -p "require('./package.json').version")
232+ # Calculate new base version by bumping the latest release version
233+ LATEST_RELEASE_BASE="${{ steps.version_check.outputs.latest_release_base }}"
234+
235+ # Use Node.js to properly increment the version
236+ NEW_BASE=$(node -e "
237+ const latest = '$LATEST_RELEASE_BASE';
238+ const [major, minor, patch] = latest.split('.').map(Number);
239+ console.log(\`\${major}.\${minor}.\${patch + 1}\`);
240+ ")
241+
242+ echo "Bumping from latest release base $LATEST_RELEASE_BASE to $NEW_BASE"
243+
244+ # Set the new base version in all package.json files
245+ bun run version:set "$NEW_BASE"
246+
217247 NEW_VERSION="${NEW_BASE}-${VERSION_SUFFIX}.${BUILD_NUMBER}.${RELEASE_SHA}"
218248 else
219249 NEW_VERSION="${BASE_VERSION}-${VERSION_SUFFIX}.${BUILD_NUMBER}.${RELEASE_SHA}"
0 commit comments