Skip to content

Commit

Permalink
👷 Init tag handling
Browse files Browse the repository at this point in the history
  • Loading branch information
heavynimbus committed May 31, 2024
1 parent 4278374 commit ce38008
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 1 deletion.
27 changes: 27 additions & 0 deletions .github/workflows/upgrade-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Build and Test

on:
push:
branches:
- '*/*'

jobs:
upgrade-version:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Java 21
uses: actions/setup-java@v4
with:
distribution: 'oracle'
java-version: '21.0.3'
cache: 'maven'
cache-dependency-path: 'server/pom.xml'
- name: Upgrade server version
run: |
./set-version.sh --pom server/pom.xml
- name: Commit and push
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "⬆️ Upgrade server version"
43 changes: 43 additions & 0 deletions set-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env bash

while [[ $# -gt 0 ]]; do
case "$1" in
--pom)
MAVEN_POM="$2"
shift 2
;;
--snapshot)
SNAPSHOT=true
shift
;;
*)
echo "Unknown argument: $1"
exit 1
;;
esac
done

if [ -z "$MAVEN_POM" ]; then
echo "Missing required argument: --pom"
exit 1
fi

if [ -z "$SNAPSHOT" ]; then
SNAPSHOT=false
fi

NEXT_VERSION=$(grep -rE 'version.next=[0-9]+\.[0-9]+\.[0-9]+' version.properties | cut -d '=' -f2)

MAJOR=$(echo "$NEXT_VERSION" | cut -d '.' -f1)
MINOR=$(echo "$NEXT_VERSION" | cut -d '.' -f2)
PATCH=$(echo "$NEXT_VERSION" | cut -d '.' -f3)


if [ "$SNAPSHOT" = true ]; then
echo "Setting new version: $MAJOR.$MINOR.$((PATCH + 1))-SNAPSHOT"
mvn -f "$MAVEN_POM" versions:set -DgenerateBackupPoms=false -DnewVersion="$MAJOR.$MINOR.$((PATCH + 1))-SNAPSHOT"
sed -i "s/version.next=$MAJOR.$MINOR.$PATCH/version.next=$MAJOR.$MINOR.$((PATCH + 1))/g" version.properties
else
echo "Setting new version: $MAJOR.$MINOR.$PATCH"
mvn -f "$MAVEN_POM" versions:set -DgenerateBackupPoms=false -DnewVersion="$MAJOR.$MINOR.$PATCH"
fi
2 changes: 1 addition & 1 deletion version.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=0.0.1-SNAPSHOT
version.next=0.0.1

0 comments on commit ce38008

Please sign in to comment.