-
Notifications
You must be signed in to change notification settings - Fork 0
/
new_version.sh
executable file
·90 lines (74 loc) · 2.41 KB
/
new_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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/bin/bash
has_breaking_exclamation() {
commit_message="$1"
commit_part="${commit_message%%:*}"
[[ $commit_part == *! ]]
}
has_breaking_footer() {
commit_message="$1"
breaking_token1="BREAKING CHANGE"
breaking_token2="BREAKING-CHANGE"
if [[ "$commit_message" == *$'\n\n'"$breaking_token1: "* ]]
then true
elif [[ "$commit_message" == *$'\n\n'"$breaking_token2: "* ]]
then true
else false
fi
}
is_breaking_change() {
has_breaking_footer "$1" || has_breaking_exclamation "$1"
}
is_minor_change() {
commit_type="$1"
extra_minor_commit_types_str="$2"
declare -A minor_commit_types=(["feat"]=1)
for type in ${extra_minor_commit_types_str//,/ }
do
if [[ $type == "fix" ]]
then
echo "WARNING: Ignoring type \"$type\" for extra-minor-commit-types"
else
minor_commit_types+=([$type]=1)
fi
done
[ "${minor_commit_types[$commit_type]}" ]
}
is_patch_change() {
commit_type="$1"
extra_patch_commit_types_str="$2"
declare -A patch_commit_types=(["fix"]=1)
for type in ${extra_patch_commit_types_str//,/ }
do
if [[ $type == "feat" ]]
then
echo "WARNING: Ignoring type \"$type\" for extra-patch-commit-types"
else
patch_commit_types+=([$type]=1)
fi
done
[ "${patch_commit_types[$commit_type]}" ]
}
commit_message="$1"
current_version="$2"
extra_minor_commit_types="$3"
extra_patch_commit_types="$4"
echo "Obtaining new version from commit message \"$commit_message\", current version \"$current_version\", extra minor commit types \"$extra_minor_commit_types\" and extra patch commit types \"$extra_patch_commit_types\""
current_version_major=$(echo "$current_version" | cut -d. -f1)
current_version_minor=$(echo "$current_version" | cut -d. -f2)
current_version_patch=$(echo "$current_version" | cut -d. -f3)
commit_type=$(echo "${commit_message%%:*}" | cut -d "(" -f1)
if is_breaking_change "$commit_message";
then
new_version="$(("$current_version_major" + 1)).0.0"
elif is_minor_change "$commit_type" "$extra_minor_commit_types";
then
new_version="$current_version_major.$(("$current_version_minor" + 1)).0"
elif is_patch_change "$commit_type" "$extra_patch_commit_types";
then
new_version="$current_version_major.$current_version_minor.$(("$current_version_patch" + 1))"
else
echo "ERROR: Couldn't obtain new version for commit type \"$commit_type\""
exit 1
fi
echo "New version: $new_version"
echo "NEW_VERSION=$new_version" >> $GITHUB_ENV