$(awk '/<version>/ {count++; if(count == 2) print $0}' pom.xml | sed -n 's|.*<version>\([^<]*\)</version>.*|\1|p')
Some checks failed
ci / build (push) Failing after 20s
Some checks failed
ci / build (push) Failing after 20s
This commit is contained in:
parent
a30e0ec119
commit
d9223df62a
3 changed files with 44 additions and 40 deletions
|
@ -38,45 +38,8 @@ jobs:
|
|||
uses: actions/checkout@v4
|
||||
- name: Update version
|
||||
run: |
|
||||
set -e
|
||||
|
||||
# Extract version using grep/sed as fallback (works even with -SNAPSHOT)
|
||||
current_version=$(xmllint --xpath "/*[local-name()='project']/*[local-name()='version']/text()" pom.xml)
|
||||
|
||||
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"
|
||||
mvn versions:set -DnewVersion="$new_version"
|
||||
mvn versions:commit
|
||||
|
||||
# Remove unnecessary backup file
|
||||
rm -f pom.xml.versionsBackup
|
||||
|
||||
echo "✅ Done!"
|
||||
chmod +x update-version.sh
|
||||
./update-version.sh
|
||||
- name: Build and push
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
|
|
2
pom.xml
2
pom.xml
|
@ -10,7 +10,7 @@
|
|||
</parent>
|
||||
<groupId>de.telekom</groupId>
|
||||
<artifactId>silly-game</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<name>silly-game</name>
|
||||
<description>Demo project for Spring Boot</description>
|
||||
<url/>
|
||||
|
|
41
update-version.sh
Executable file
41
update-version.sh
Executable file
|
@ -0,0 +1,41 @@
|
|||
#!/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"
|
||||
mvn versions:set -DnewVersion="$new_version"
|
||||
mvn versions:commit
|
||||
|
||||
# Remove unnecessary backup file
|
||||
rm -f pom.xml.versionsBackup
|
||||
|
||||
echo "✅ Done!"
|
Loading…
Reference in a new issue