-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbump_version.sh
executable file
·66 lines (54 loc) · 1.78 KB
/
bump_version.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash
current_version=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout --no-transfer-progress --batch-mode)
bump_type=""
determine_bump_version() {
commit_messages=$(git log --pretty=%B $current_version...HEAD)
if [[ $commit_messages == *"BREAKING CHANGE"* || $commit_messages == *"major("*")"* ]]; then
echo "Found breaking or major changes, will bump major"
bump_type="MAJOR"
elif [[ $commit_messages == *"feat("*")"* || $commit_messages == *"minor("*")"* ]]; then
echo "Found new features or minor changes, will bump minor"
bump_type="MINOR"
else
echo "No new features or major/minor changes, will bump patch"
bump_type="PATCH"
fi
}
determine_bump_version
# Extract major
major_part="${current_version%.*.*}"
# Remove major from the version
rest="${current_version#*.}"
# Get the minor part from rest
minor_part="${rest%.*}"
# Get the patch part from rest
patch_part="${rest#*.}"
case $bump_type in
"MAJOR")
# Increment major
major_part=$(($major_part + 1))
;;
"MINOR")
# Increment minor
minor_part=$(($minor_part + 1))
;;
"PATCH")
# Increment patch
patch_part=$(($patch_part + 1))
;;
*)
echo "Could not determine which part to increment"
exit 1
esac
new_version="$major_part.$minor_part.$patch_part"
echo "Setting new version: $new_version"
mvn versions:set -DnewVersion=$new_version --no-transfer-progress --batch-mode
if [ "$CI" = true ]; then
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --local user.name "Release bot"
git add ./pom.xml
git commit -m "Release: $new_version"
git tag $new_version
git push
git push --tags
fi