-
-
Notifications
You must be signed in to change notification settings - Fork 43
/
semantic-versioning.sh
executable file
·48 lines (43 loc) · 1.31 KB
/
semantic-versioning.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
#!/bin/bash
set -e
validate_is_master_branch(){
echo "Checking branch...";
RELEASE_BRANCH="master";
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD);
echo "current branch: $CURRENT_BRANCH"
if [ $RELEASE_BRANCH != $CURRENT_BRANCH ]; then
echo "A new release version is only bumped on branch: $RELEASE_BRANCH.";
echo "Exiting...";
exit 0;
fi
}
npm_release(){
RELEASE_COMMIT_MSG="new release [skip ci]"
PATCH_MSG="[PATCH]";
MAJOR_MSG="[MAJOR]";
echo "Parsing git message...";
COMMIT_MSG=$(git log -1 --pretty=format:"%s");
echo "Last commit message: ${COMMIT_MSG}";
if [[ $COMMIT_MSG == *"$PATCH_MSG"* ]]; then
echo "Executing new PATCH release..."
npm version patch --force -m "{$RELEASE_COMMIT_MSG";
elif [[ $COMMIT_MSG == *"$MAJOR_MSG"* ]]; then
echo "Executing new MAJOR release..."
npm version major --force -m "${RELEASE_COMMIT_MSG}";
else
echo "Executing new MINOR release...";
npm version minor --force -m "${RELEASE_COMMIT_MSG}";
fi
echo "Publish new version..."
npm publish;
echo "Publish git info...";
git push --follow-tags
echo "New version successfully published."
}
execute-new-release(){
echo "Start Semantic Versioning release...";
validate_is_master_branch;
npm_release;
echo "End Semantic Versioning release.";
}
execute-new-release;