michals-silly-game-backend/update-version.sh

45 lines
1.3 KiB
Bash
Raw Normal View History

#!/bin/bash
set -e
# Extract version using grep/sed as fallback (works even with -SNAPSHOT)
current_version=$(awk '/<version>/ {count++; if(count == 2) print $0}' pom.xml | sed -n 's|.*<version>\([^<]*\)</version>.*|\1|p')
if [[ -z "$current_version" ]]; then
echo "❌ Failed to extract version from pom.xml"
exit 1
fi
# Strip "-SNAPSHOT" if present
base_version="${current_version%-SNAPSHOT}"
# Split into major.minor.patch
IFS='.' read -r major minor patch <<< "$base_version"
# Handle missing patch (e.g. 1.0)
patch=${patch:-0}
# Increment minor, reset patch
minor=$((minor + 1))
patch=0
# Preserve -SNAPSHOT if it was present
if [[ "$current_version" == *-SNAPSHOT ]]; then
new_version="${major}.${minor}.${patch}-SNAPSHOT"
else
new_version="${major}.${minor}.${patch}"
fi
# Apply it with Maven
echo "🔧 Updating version: $current_version$new_version"
2025-04-24 12:08:39 +00:00
TAG=$(echo "$new_version" | tr '[:upper:]' '[:lower:]')
2025-04-24 12:09:57 +00:00
sed -i "s|forgejo.edf-bootstrap.cx.fg1.ffm.osc.live/devfw-cicd/michals-silly-game-backend:.*|forgejo.edf-bootstrap.cx.fg1.ffm.osc.live/devfw-cicd/michals-silly-game-backend:$TAG|" k8/deployment.yaml
2025-04-24 12:08:39 +00:00
echo "reference changed to $TAG"
2025-04-14 09:28:11 +00:00
mvn versions:set -DnewVersion="$new_version"
mvn versions:commit
# Remove unnecessary backup file
rm -f pom.xml.versionsBackup
echo "✅ Done!"