-
Notifications
You must be signed in to change notification settings - Fork 0
/
release.sh
executable file
·99 lines (86 loc) · 2.88 KB
/
release.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
91
92
93
94
95
96
97
98
99
#!/bin/bash
# Exit script at first error:
set -e
function printHelp() {
echo ""
echo "USAGE: release.sh <command>"
echo " help"
echo " Prints this message"
echo ""
echo " start"
echo " Starts the release process."
echo ""
echo " finish"
echo " Ends a previously started release process."
}
function checkArtifact() {
if [ -f "IAdvizeSDK.zip" ]; then
echo -e "\033[1;42m => Found release artifact. Unzipping. \033[0m"
rm -Rf tmp
unzip -q IAdvizeSDK.zip -d tmp
echo -e "\033[1;42m => Extracting version name \033[0m"
versionName=$(grep '"version":' tmp/plugin/package.json -m 1 | sed 's/ "version": "\(.*\)",/\1/')
else
echo -e "\033[1;101m No release artifact found. \033[0m"
exit 1
fi
}
function updateReleaseFiles() {
echo -e "\033[1;42m => Updating package.json to target latest SDK\033[0m"
sed -i '' "s/\"@iadvize-oss\/iadvize-react-native-sdk\": \"^\(.*\)\",/\"@iadvize-oss\/iadvize-react-native-sdk\": \"^${versionName}\",/" example/package.json
echo -e "\033[1;42m => Updating CHANGELOG & UPGRADING & README & SUPPORT. \033[0m"
mv tmp/*.md .
}
function printStartSuccess() {
echo -e "\033[1;42m => Release ${versionName} is applied! This is what remains for you to do: \033[0m"
echo -e "\033[1;95m - Test the sample project locally with this release \033[0m"
echo -e "\033[1;95m - Execute './release.sh finish' to continue the release process \033[0m"
}
function checkCurrentRelease() {
if [ -d "tmp" ]; then
echo -e "\033[1;42m => Extracting version name \033[0m"
versionName=$(grep '"version":' tmp/plugin/package.json -m 1 | sed 's/ "version": "\(.*\)",/\1/')
else
echo -e "\033[1;101m No ongoing release found. \033[0m"
exit 1
fi
}
function requestFinishApproval() {
echo -e "\033[1;31m WARNING - You are about to push release ${versionName} to the public repository. \033[0m"
echo -e "\033[1;31m Proceed ? [y/n] \033[0m"
read -s -n 1 key
case $key in
y) ;;
*)
exit 0
esac
}
function commitPushRelease() {
echo -e "\033[1;42m => Committing/pushing version update \033[0m"
git add --all
git commit -m "(build) publish version ${versionName}" --quiet
git tag "${versionName}"
git push origin main --tags
}
function cleanRelease() {
rm -R tmp
rm IAdvizeSDK.zip
}
function printFinishSuccess() {
echo -e "\033[1;42m => Release ${versionName} is now public! This is what remains for you to do: \033[0m"
echo -e "\033[1;95m - Create a github release from tag ${versionName} : https://github.com/iadvize/iadvize-react-native-sdk/releases/new \033[0m"
echo -e "\033[1;95m - Fill description with changelog info \033[0m"
}
if [[ "$1" == "start" ]]; then
checkArtifact
updateReleaseFiles
printStartSuccess
elif [[ "$1" == "finish" ]]; then
checkCurrentRelease
requestFinishApproval
commitPushRelease
cleanRelease
printFinishSuccess
else
printHelp
fi