forked from liferay/liferay-blade-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
publish.sh
executable file
·252 lines (185 loc) · 9.21 KB
/
publish.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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
#!/bin/bash
bladeInstall=$(curl -L https://raw.githubusercontent.com/liferay/liferay-blade-cli/master/cli/installers/local | sh)
if [ "$?" != "0" ]; then
echo $bladeInstall
echo blade install failed
exit 1
fi
export PATH="$PATH:$HOME/jpm/bin"
bladeVersion=$(blade version)
if [ "$?" != "0" ]; then
echo blade version failed
exit 1
fi
bladeTask="check"
nexusOpt=""
releaseType=""
scanOpt="--scan"
# check the arguments first
while [ $# -gt 0 ]; do
if [ "$1" = "--local" ]; then
nexusOpt="-PlocalNexus"
elif [ "$1" = "--remote" ]; then
nexusOpt="-PremoteNexus"
elif [ "$1" = "--skip-tests" ]; then
bladeTask="jar"
elif [ "$1" = "--skip-scan" ]; then
scanOpt=""
fi
shift
done
ISRELEASE=$(cat cli/build.gradle | grep -e "^version = \"[0-9.]*\"$")
ISSNAPSHOT=$(cat cli/build.gradle | grep -e "^version = \"[0-9.]*-SNAPSHOT\"$")
if [ ! -z "$ISRELEASE" ]; then
releaseType="release"
fi
if [ ! -z "$ISSNAPSHOT" ]; then
releaseType="snapshots"
fi
# Setup a temp directory
timestamp=$(date +%s)
tmpDir="/tmp/$timestamp/"
mkdir -p $tmpDir
if [ -z "$repoHost" ]; then
if [ "$nexusOpt" = "-PlocalNexus" ]; then
repoHost="http://localhost:8081"
else
repoHost="https://repository.liferay.com"
fi
elif [ "$repoHost" = "http://localhost:8081" ]; then
nexusOpt="-PlocalNexus"
fi
# Switch gradle wrapper distributionUrl to use -bin instead of -all. See BLADE-594 for more details
sed "s/all/bin/" gradle/wrapper/gradle-wrapper.properties > gradle-wrapper.properties.edited
mv gradle-wrapper.properties.edited gradle/wrapper/gradle-wrapper.properties
# First clean local build folder to try to minimize variants
./gradlew -q --no-daemon --console=plain clean
if [ "$?" != "0" ]; then
echo Failed clean.
exit 1
fi
# Publish the Remote Deploy Command jar
./gradlew -q --no-daemon --console=plain $nexusOpt -P${releaseType} :extensions:remote-deploy-command:publish --info ${scanOpt} > /tmp/$timestamp/remote-deploy-publish-command.txt; retcode=$?
remoteDeployCommandPublishCommand=$(cat /tmp/$timestamp/remote-deploy-publish-command.txt)
if [ "$retcode" != "0" ] || [ -z "$remoteDeployCommandPublishCommand" ]; then
echo Failed :extensions:remote-deploy-command:publish
exit 1
fi
# Publish the Activator Project Template
./gradlew -q --no-daemon --console=plain $nexusOpt -P${releaseType} :extensions:project-templates-activator:publish -x :cli:bladeExtensionsVersions -x :cli:processResources --info ${scanOpt}; retcode=$?
# Publish the Content Targeting Report Project Template
./gradlew -q --no-daemon --console=plain $nexusOpt -P${releaseType} :extensions:project-templates-content-targeting-report:publish -x :cli:bladeExtensionsVersions -x :cli:processResources --info ${scanOpt}; retcode=$?
# Publish the Content Targeting Rule Project Template
./gradlew -q --no-daemon --console=plain $nexusOpt -P${releaseType} :extensions:project-templates-content-targeting-rule:publish -x :cli:bladeExtensionsVersions -x :cli:processResources --info ${scanOpt}; retcode=$?
# Publish the Content Targeting Tracking Action Project Template
./gradlew -q --no-daemon --console=plain $nexusOpt -P${releaseType} :extensions:project-templates-content-targeting-tracking-action:publish -x :cli:bladeExtensionsVersions -x :cli:processResources --info ${scanOpt}; retcode=$?
# Publish the Freemarker Portlet Project Template
./gradlew -q --no-daemon --console=plain $nexusOpt -P${releaseType} :extensions:project-templates-freemarker-portlet:publish -x :cli:bladeExtensionsVersions -x :cli:processResources --info ${scanOpt}; retcode=$?
# Publish the Social Bookmark Project Template
./gradlew -q --no-daemon --console=plain $nexusOpt -P${releaseType} :extensions:project-templates-social-bookmark:publish -x :cli:bladeExtensionsVersions -x :cli:processResources --info ${scanOpt}
# Publish the JS Theme Project Template
./gradlew -q --no-daemon --console=plain $nexusOpt -P${releaseType} :extensions:project-templates-js-theme:publish -x :cli:bladeExtensionsVersions -x :cli:processResources --info ${scanOpt} > /tmp/$timestamp/js-theme-template-publish-command.txt; retcode=$?
jsThemeTemplatePublishCommand=$(cat /tmp/$timestamp/js-theme-template-publish-command.txt)
if [ "$retcode" != "0" ] || [ -z "$jsThemeTemplatePublishCommand" ]; then
echo Failed :extensions:project-templates-js-theme:publish
exit 1
fi
# Publish the JS Widget Project Template
./gradlew -q --no-daemon --console=plain $nexusOpt -P${releaseType} :extensions:project-templates-js-widget:publish -x :cli:bladeExtensionsVersions -x :cli:processResources --info ${scanOpt} > /tmp/$timestamp/js-widget-template-publish-command.txt; retcode=$?
jsWidgetTemplatePublishCommand=$(cat /tmp/$timestamp/js-widget-template-publish-command.txt)
if [ "$retcode" != "0" ] || [ -z "$jsWidgetTemplatePublishCommand" ]; then
echo Failed :extensions:project-templates-js-widget:publish
exit 1
fi
# Publish the Maven Profile jar
./gradlew -q --no-daemon --console=plain $nexusOpt -P${releaseType} :extensions:maven-profile:publish -x :cli:bladeExtensionsVersions -x :cli:processResources --info ${scanOpt} > /tmp/$timestamp/maven-profile-publish-command.txt; retcode=$?
mavenProfilePublishCommand=$(cat /tmp/$timestamp/maven-profile-publish-command.txt)
if [ "$retcode" != "0" ] || [ -z "$mavenProfilePublishCommand" ]; then
echo Failed :extensions:maven-profile:publish
exit 1
fi
# Grep the output of the previous command to find the url of the published jar
mavenProfilePublishUrl=$(echo "$mavenProfilePublishCommand" | grep Uploading | grep '.jar ' | grep -v -e '-sources' -e '-tests' | cut -d' ' -f4)
if [ "$?" != "0" ] || [ -z "$mavenProfilePublishUrl" ]; then
echo Failed grepping for mavenProfilePublishUrl
exit 1
fi
# Download the just published jar in order to later compare it to the embedded maven profile that is in blade jar
mavenProfileJarUrl="${repoHost}${mavenProfilePublishUrl}"
curl -s "$mavenProfileJarUrl" -o /tmp/$timestamp/maven_profile.jar
if [ "$?" != "0" ]; then
echo Downloading maven.profile jar failed.
exit 1
else
echo "Published $mavenProfileJarUrl"
fi
# fix permissions
mkdir -p ~/.config/configstore
chmod g+rwx ~/.config ~/.config/configstore
# Test the blade cli jar locally, but don't publish.
./gradlew -q --no-daemon --console=plain $nexusOpt -P${releaseType} --refresh-dependencies clean $bladeTask --info ${scanOpt} > /tmp/$timestamp/blade-cli-jar-command.txt; retcode=$?
if [ "$retcode" != "0" ]; then
echo Failed :cli:jar
cat /tmp/$timestamp/blade-cli-jar-command.txt
exit 1
fi
# now that we have the blade jar just built, lets extract the embedded maven profile jar and compare to the maven profile downloaded from nexus
embeddedMavenProfileJar=$(jar -tf cli/build/libs/blade.jar | grep "maven.profile-")
if [ -z "$embeddedMavenProfileJar" ]; then
echo Failed to find embedded maven.profile jar in blade jar
exit 1
fi
unzip -p cli/build/libs/blade.jar "$embeddedMavenProfileJar" > /tmp/$timestamp/myExtractedMavenProfile.jar
diff -s /tmp/$timestamp/myExtractedMavenProfile.jar /tmp/$timestamp/maven_profile.jar
if [ "$?" != "0" ]; then
echo Failed local blade.jar diff with downloaded maven profile jar. The embedded maven profile jar and nexus maven profile jar are not identical
exit 1
fi
# Now lets go ahead and publish the blade cli jar for real since the embedded maven profile was correct
./gradlew -q --no-daemon --console=plain $nexusOpt -P${releaseType} --refresh-dependencies :cli:publish --info ${scanOpt} > /tmp/$timestamp/blade-cli-publish-command.txt; retcode=$?
bladeCliPublishCommand=$(cat /tmp/$timestamp/blade-cli-publish-command.txt)
if [ "$retcode" != "0" ] || [ -z "$bladeCliPublishCommand" ]; then
echo Failed :cli:publish
exit 1
fi
# Grep the output of the blade jar publish to find the url
bladeCliJarUrl=$(echo "$bladeCliPublishCommand" | grep Uploading | grep '.jar ' | grep -v -e '-sources' -e '-tests' | cut -d' ' -f4)
# download the just published jar in order to extract the embedded maven profile jar to compare to previously downloaded version from above (just to be double sure)
bladeCliUrl="${repoHost}${bladeCliJarUrl}"
curl -s "$bladeCliUrl" -o /tmp/$timestamp/blade.jar
if [ "$?" != "0" ]; then
echo Downloading blade jar failed.
exit 1
else
echo "Published $bladeCliUrl"
fi
unzip -p /tmp/$timestamp/blade.jar "$embeddedMavenProfileJar" > /tmp/$timestamp/myExtractedMavenProfile.jar
diff -s /tmp/$timestamp/myExtractedMavenProfile.jar /tmp/$timestamp/maven_profile.jar
if [ "$?" != "0" ]; then
echo Failed local blade.jar diff with downloaded maven profile jar. The embedded maven profile jar and nexus maven profile jar are not identical
exit 1
fi
localBladeVersion=$(java -jar /tmp/$timestamp/blade.jar version)
# Already handled in the dockerfile
# mkdir ~/.blade
echo "$repoHost/nexus/content/groups/public/com/liferay/blade/com.liferay.blade.cli/" > ~/.blade/update.url
if [ "$releaseType" = "snapshots" ]; then
bladeUpdate=$(blade update --snapshots)
else
bladeUpdate=$(blade update)
fi
if [ "$?" != "0" ]; then
echo Failed blade update.
echo $bladeUpdate
exit 1
fi
updatedBladeVersion=$(blade version)
echo $bladeUpdate
echo $localBladeVersion
echo $updatedBladeVersion
if [ "$localBladeVersion" != "$updatedBladeVersion" ]; then
echo "After blade updated versions do not match."
echo "Built blade version = $localBladeVersion"
echo "Updated blade version = $updatedBladeVersion"
exit 1
fi