forked from psvnanda/ActivityIndicator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_pod_version.sh
executable file
·175 lines (142 loc) · 4.61 KB
/
update_pod_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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/bin/bash
# The purpose of this script is to automate the process of incrementing the version number of
# this development pods. It provides an abstracted command line interface for specifying a new
# version number, performing the following actions:
#
# – Updating the version number specified in the .podspec file that sits in this pod repository
# – Pushing a tag for the version number (tagged to the commit which modified the podspec)
# – Creating a directory for the new version number in the AE specs repo
# – Copying the podspec file for the previous version to that location and updating the version number
# - Pushing all commits related to the above to Github
#
# The primary benefits of automating this workflow with this script are time saved and the prevention
# of human error.
# TODO: Add check/clone for local AENetworks specs repo.
# TODO: Replace manual input of new version number with enumerated Major/Minor/Patch options, to prevent typos there as well.
# TODO: Add handling for first time version tagging (e.g. edge case where there are no preexisting tags.
# User I/O
ask() {
while true; do
if [ "${2:-}" = "Y" ]; then
prompt="Y/n"
default=Y
elif [ "${2:-}" = "N" ]; then
prompt="y/N"
default=N
else
prompt="y/n"
default=
fi
read -p "$1 [$prompt] " REPLY </dev/tty
if [ -z "$REPLY" ]; then
REPLY=$default
fi
case "$REPLY" in
Y*|y*) return 0 ;;
N*|n*) return 1 ;;
esac
done
}
# Convenience Methods
SAVEIFS=$IFS
readPodName() {
local fname=$1
while read -r line
do
IFS=$SAVEIFS read -ra values <<< "$line"
if [ "${values[0]}" = "s.name" ]; then
text=${values[2]}
pod_name=`echo $text | sed s/[\'\"]//g`
echo $pod_name
exit 1
fi
done < "$fname"
}
readPodVersion() {
local fname=$1
while read -r line
do
IFS=$SAVEIFS read -ra values <<< "$line"
if [ "${values[0]}" = "s.version" ]; then
text=${values[2]}
pod_version=`echo $text | sed s/[\'\"]//g`
echo $pod_version
exit 1
fi
done < "$fname"
}
# Variable declaration
filename=`ls *.podspec`
branch=`git symbolic-ref --short HEAD`
podname=`readPodName $filename`
version=`readPodVersion $filename`
reposPath="$HOME/.cocoapods/repos/aenetworks/Specs"
startPath=`pwd`
# Sync with Github repo
echo ""
echo "======================================================="
echo "Syncing branch with origin..."
echo ""
git pull origin $branch
echo "======================================================="
echo "Syncing tags with origin..."
echo ""
git pull origin --tags
# Prompt user for new version number
echo "======================================================="
echo "REPO = $podname"
echo "BRANCH = $branch"
echo "VERSION = $version"
echo ""
echo -n "Enter new version (or blank to cancel): "
read newVersion
chars=${#newVersion}
# Create new pod version with user input
if [ $chars -gt 0 ]; then
podPath="$reposPath/$podname"
versionPath="$podPath/$newVersion"
specPath="$startPath/$filename"
echo "======================================================="
if ask "You entered $newVersion. Do you want to proceed?" Y; then
echo "======================================================="
echo "Checking if podspec needs update..."
if [ $version == $newVersion ]; then
echo "–– Podspec version is unchanged. No changes made to $filename"
else
echo "–– Updating $filename to version $newVersion"
sed -E -l -i "" "s/^(.*s\.version.*=)(.*)$/\1 \\'$newVersion\\'/g" $filename
fi
existingTag=`git tag | grep $newVersion`
echo ""
echo "Checking for existing tag $newVersion"
if [ "$existingTag" ]; then
echo "–– Tag already exists for $newVersion. No tag pushed"
else
echo "–– Committing $filename and pushing tag $newVersion to $branch"
git add $filename
git commit -m "Updated to Version $newVersion"
git push origin $branch
git tag -a $newVersion -m "Version $newVersion"
git push origin $newVersion
fi
targetPath="$versionPath/$filename"
echo ""
echo "Checking for existing $targetPath"
if [ -d $podPath ] && [ -f $targetPath ]; then
echo "–– $filename already exists in $versionPath"
echo "–– No need to create new version in Specs repo"
else
echo "–– Copying $filename to $versionPath"
cd $podPath
git pull
mkdir $newVersion
cd $newVersion
cp $specPath .
git add $filename
git commit -m "Pushing $podname Version $newVersion"
git push origin $branch
fi
else
echo "Version update cancelled. No changes have been saved."
fi
fi