-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbump.sh
More file actions
executable file
·73 lines (59 loc) · 1.93 KB
/
Copy pathbump.sh
File metadata and controls
executable file
·73 lines (59 loc) · 1.93 KB
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
67
68
69
70
71
72
73
#!/bin/bash
echo "Version bump script"
get_current_version() {
ver=$(git describe --tags --abbrev=0 2>/dev/null | sed 's/^v//')
ver=${ver:-"0.0.0"}
echo "$ver"
}
current=$(get_current_version)
IFS='.' read -r -a version_parts <<< "$current"
major="${version_parts[0]}"
minor="${version_parts[1]}"
patch="${version_parts[2]}"
has_breaking_change=false
has_feature_change=false
has_patch_change=false
commits=$(git log --pretty=format:"%s %b" $(git describe --tags --abbrev=0 HEAD)..HEAD)
echo "Checking commit history:"
echo "$commits"
echo "----------------------------------"
while IFS= read -r commit; do
if echo "$commit" | grep -q "BREAKING CHANGE:"; then
has_breaking_change=true
fi
if echo "$commit" | grep -qE '^(feat|deprecate):' || echo "$commit" | grep -qE '^(feat|deprecate)\([^)]*\):'; then
has_feature_change=true
fi
if [[ "$has_breaking_change" == false && "$has_feature_change" == false ]]; then
if [[ -n "$commit" ]]; then
has_patch_change=true
fi
fi
done <<< "$commits"
if [[ "$has_breaking_change" == true ]]; then
echo "Found breaking change"
new_version="$((major + 1)).0.0"
update_type="MAJOR"
elif [[ "$has_feature_change" == true ]]; then
echo "Found feature/deprecation commit"
new_version="$major.$((minor + 1)).0"
update_type="MINOR"
else
new_version="$major.$minor.$((patch + 1))"
update_type="PATCH"
fi
echo "----------------------------------"
echo "Current version: v$current"
echo "Detected $update_type version change"
echo "New version: v$new_version"
echo "Creating Git tag: $new_version ..."
git tag -a "$new_version" -m "Release v$new_version"
current_version=$(get_current_version)
echo "Current project version: $current_version"
if [ "$current_version" == "$new_version" ]; then
echo "Done, exiting script"
exit 0
else
echo "Current version does not match expected version, please check manually!"
exit 1
fi