This repository has been archived by the owner on Jun 10, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 32
/
release.sh
executable file
·197 lines (167 loc) · 4.67 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
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#!/bin/sh
RELEASE_LOG_FILE="pl-release.log"
RELEASE_VERSION=""
# simple function used to execute comands from the script
execute_cmd() {
"$@" > $RELEASE_LOG_FILE
}
# check if a previous maven build was successful or not
check_build_result() {
if tail -n 100 pl-release.log|grep -F "BUILD SUCCESS"
then
return 0
else
return 1;
fi
}
# check if the release version was specified
check_release_version() {
if [ "$RELEASE_VERSION" == "" ]; then
echo "--version not specified. Please use: --version X"
exit 1
fi
}
# clean the local repo and revert all local modifications
clean_local_repo() {
git clean -f -d
git reset --hard upstream/master
rm -rf $RELEASE_LOG_FILE
}
# rollback a previous release attempt and prepare the local repo for another one
rollback() {
check_release_version
echo "Aborting ..."
clean_local_repo
git checkout develop
clean_local_repo
git checkout master
clean_local_repo
git branch -D release/$RELEASE_VERSION
git push origin :release/$RELEASE_VERSION
git push upstream :release/$RELEASE_VERSION
git tag -d v$RELEASE_VERSION
git push origin :refs/tags/v$RELEASE_VERSION
git push upstream :refs/tags/v$RELEASE_VERSION
echo "Done."
}
# perform the release
release() {
if [ "$DEVELOPMENT_VERSION" == "" ]; then
echo "--snapshot not specified. Please use: --snapshot X"
exit 1
fi
check_release_version
rm -rf $RELEASE_LOG_FILE
echo "###################################################"
echo " PicketLink Release Script "
echo "###################################################"
echo ""
echo "Current version: $DEVELOPMENT_VERSION"
echo "Release version: $RELEASE_VERSION"
echo ""
echo "Preparing local repository to release."
execute_cmd git checkout master
echo " Fetching latest changes from upstream..."
execute_cmd git fetch upstream master
echo " Pulling changes from master..."
execute_cmd git pull upstream master
echo "Done."
echo ""
read -p "Check all project dependencies before releasing ?[y/n] " FLAG_NO_DEPENDENCY_CHECK
if [ "$FLAG_NO_DEPENDENCY_CHECK" == "y" ]; then
echo "Checking dependencies."
execute_cmd mvn -DskipTests=true clean install dependency:resolve -Dmaven.repo.local=/tmp/release_repo
if check_build_result; then
echo "Done."
else
echo "ERROR: Error checking dependencies. Check the logs."
exit 1;
fi
else
echo "WARNING: Depedencies were not checked. This can impact users when downloading the project's artifacts."
fi
echo ""
echo "Preparing to release using git flow."
echo " Starting release $RELEASE_VERSION..."
execute_cmd git checkout -b release/v$RELEASE_VERSION
echo "Done."
echo ""
FLAG_PERFORM_RELEASE="false"
echo "Releasing version $RELEASE_VERSION."
execute_cmd perl -pi -e 's/'$DEVELOPMENT_VERSION'/'$RELEASE_VERSION'/g' `find . -name pom.xml`
execute_cmd mvn -Prelease -DskipTests=true clean install
if check_build_result; then
echo "Done."
else
echo "ERROR: Release failed."
exit 1
fi
execute_cmd git add .
execute_cmd git commit -m "Release $RELEASE_VERSION."
execute_cmd git tag -a v$RELEASE_VERSION -m "Version $RELEASE_VERSION."
execute_cmd git push --tags upstream
echo ""
FLAG_PUBLISH_NEXUS="n"
read -p "Do you want to publish artifacts to Nexus staging repository ?[y/n] " FLAG_PUBLISH_NEXUS
if [ "$FLAG_PUBLISH_NEXUS" == "y" ]; then
echo "Publishing artifacts to Nexus. "
execute_cmd mvn -Prelease -DskipTests=true clean source:jar deploy
echo "Done. You can now go to Nexus and finish release the artifacts."
fi
echo ""
echo "Finishing the release."
git flow release finish $RELEASE_VERSION
clean_local_repo
git checkout master
git branch -D release/v$RELEASE_VERSION
git reset --hard upstream/master
echo "Done."
exit 0
}
usage()
{
cat << EOF
usage: $0 options
Use this script to release PicketLink versions.
OPTIONS:
--snapshot Snapshot version number to update from.
--version New snapshot version number to update to, if undefined, defaults to the version number updated from.
--rollback Undo a previous release attempt and prepares the local repo for a new one.
EOF
}
DEVELOPMENT_VERSION=""
FLAG_NO_DEPENDENCY_CHECK="false"
ROLLBACK="false"
while true; do
case "$1" in
--help)
usage
exit
;;
--snapshot )
DEVELOPMENT_VERSION=$2
shift
shift
;;
--version )
RELEASE_VERSION=$2
shift
shift
;;
--rollback )
ROLLBACK="true"
shift
;;
-- )
shift;
break ;;
* )
break
;;
esac
done
if [ "$ROLLBACK" == "true" ]; then
rollback
exit 0
fi
release