Skip to content

Commit 8b29ba6

Browse files
committed
wip
1 parent 2320e40 commit 8b29ba6

File tree

1 file changed

+94
-65
lines changed

1 file changed

+94
-65
lines changed

scripts/publishPackages.sh

Lines changed: 94 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -16,36 +16,36 @@ function patchVersion() {
1616

1717
poetry version $version
1818
local bumpVersionResult=$?
19-
if [ $bumpVersionResult -ne 0 ]; then
19+
if [ "$bumpVersionResult" -ne "0" ]; then
2020
echo "Failed to bump version of $package to $version"
21-
exit 1
21+
return 1
2222
fi
2323

24-
if [ "${#deps[@]}" -ne "0" ]; then
25-
if [ "${deps[0]}" != "" ]; then
24+
if [ "${#deps[@]}" -ne "0" ]; then # -ne is integer inequality
25+
if [ "${deps[0]}" != "" ]; then # != is string inequality
2626
for dep in "${deps[@]}"; do
2727
poetry add $dep@$version
2828
local addDepResult=$?
29-
if [ $addDepResult -ne 0 ]; then
29+
if [ "$addDepResult" -ne "0" ]; then
3030
echo "Failed to add $dep@$version to $package"
31-
exit 1
31+
return 1
3232
fi
3333
done
3434
fi
3535
fi
3636

3737
poetry lock
3838
local lockResult=$?
39-
if [ $lockResult -ne 0 ]; then
39+
if [ "$lockResult" -ne "0" ]; then
4040
echo "Failed to lock $package"
41-
exit 1
41+
return 1
4242
fi
4343

4444
poetry install
4545
local installResult=$?
46-
if [ $installResult -ne 0 ]; then
46+
if [ "$installResult" -ne "0" ]; then
4747
echo "Failed to install $package"
48-
exit 1
48+
return 1
4949
fi
5050

5151
cd $pwd
@@ -60,27 +60,54 @@ function publishPackage() {
6060

6161
cd packages/$package
6262

63+
isPackagePublished $package $version
64+
local isPackagePublishedResult=$?
65+
echo "isPackagePublishedResult: $isPackagePublishedResult"
66+
if [ "$isPackagePublishedResult" -eq "0" ]; then
67+
echo "Skip publish: Package $package with version $version is already published"
68+
return 0
69+
fi
70+
6371
poetry publish --build --username $username --password $password
6472
local publishResult=$?
65-
if [ $publishResult -ne 0 ]; then
73+
if [ "$publishResult" -ne "0" ]; then
6674
echo "Failed to publish $package"
67-
exit 1
75+
return 1
6876
fi
6977

7078
cd $pwd
7179
}
7280

81+
# This will only work for the latest version of the package
82+
function isPackagePublished() {
83+
local package=$1
84+
local version=$2
85+
86+
poetry search $package | grep "$package ($version)"
87+
echo $(poetry search $package | grep "$package ($version)")
88+
local exit_code=$?
89+
echo "exit_code: $exit_code"
90+
91+
if [ "$exit_code" -eq "0" ]; then
92+
echo "Package $package with version $version is published"
93+
return 0
94+
else
95+
echo "Package $package with version $version is not published"
96+
return 1
97+
fi
98+
}
99+
73100
function waitForPackagePublish() {
74101
local package=$1
75102
local version=$2
76103
local seconds=0
77104

78-
while [ $seconds -lt 600 ] # Wait for 10 minutes
105+
while [ "$seconds" -lt "600" ] # Wait for 10 minutes
79106
do
80-
poetry search $package | grep "$package \($version\)"
107+
isPackagePublished $package $version
81108
local exit_code=$?
82109

83-
if [ $exit_code -eq 0 ]; then
110+
if [ "$exit_code" -eq "0" ]; then
84111
echo "Package $package with version $version is published"
85112
break
86113
fi
@@ -89,59 +116,61 @@ function waitForPackagePublish() {
89116
echo "Waiting for $seconds seconds for the $package to be published"
90117
done
91118

92-
if [ $seconds -eq 600 ]; then
119+
if [ "$seconds" -eq "600" ]; then
93120
echo "Package $package with version $version is not published"
94-
exit 1
121+
return 1
95122
fi
96123
}
97124

98125

99126
# Patching Verion of polywrap-msgpack
100127
echo "Patching Version of polywrap-msgpack to $1"
101128
patchVersion polywrap-msgpack $1
102-
local patchVersionResult=$?
103-
if [ $patchVersionResult -ne 0 ]; then
129+
patchVersionResult=$?
130+
if [ "$patchVersionResult" -ne "0" ]; then
104131
echo "Failed to bump version of polywrap-msgpack to $1"
105132
exit 1
106133
fi
107134

108135
echo "Publishing polywrap-msgpack"
109136
publishPackage polywrap-msgpack $2 $3
110-
local publishResult=$?
111-
if [ $publishResult -ne 0 ]; then
137+
publishResult=$?
138+
echo "publishResult: $publishResult"
139+
echo [ "$publishResult" -ne "0" ]
140+
if [ "$publishResult" -ne "0" ]; then
112141
echo "Failed to publish polywrap-msgpack"
113142
exit 1
114143
fi
115144

116145
echo "Waiting for the package to be published"
117146
waitForPackagePublish polywrap-msgpack $1
118-
local waitForPackagePublishResult=$?
119-
if [ $waitForPackagePublishResult -ne 0 ]; then
147+
waitForPackagePublishResult=$?
148+
if [ "$waitForPackagePublishResult" -ne "0" ]; then
120149
echo "Failed to publish polywrap-msgpack"
121150
exit 1
122151
fi
123152

124153
# Patching Verion of polywrap-result
125154
echo "Patching Version of polywrap-result to $1"
126155
patchVersion polywrap-result $1
127-
local patchVersionResult=$?
128-
if [ $patchVersionResult -ne 0 ]; then
156+
patchVersionResult=$?
157+
if [ "$patchVersionResult" -ne "0" ]; then
129158
echo "Failed to bump version of polywrap-result to $1"
130159
exit 1
131160
fi
132161

133162
echo "Publishing polywrap-result"
134163
publishPackage polywrap-result $2 $3
135-
local publishResult=$?
136-
if [ $publishResult -ne 0 ]; then
164+
publishResult=$?
165+
if [ "$publishResult" -ne "0" ]; then
137166
echo "Failed to publish polywrap-result"
138167
exit 1
139168
fi
140169

141170
echo "Waiting for the package to be published"
142171
waitForPackagePublish polywrap-result $1
143-
local waitForPackagePublishResult=$?
144-
if [ $waitForPackagePublishResult -ne 0 ]; then
172+
waitForPackagePublishResult=$?
173+
if [ "$waitForPackagePublishResult" -ne "0" ]; then
145174
echo "Failed to publish polywrap-result"
146175
exit 1
147176
fi
@@ -150,24 +179,24 @@ fi
150179
echo "Patching Version of polywrap-manifest to $1"
151180
deps=(polywrap-msgpack polywrap-result)
152181
patchVersion polywrap-manifest $1 deps
153-
local patchVersionResult=$?
154-
if [ $patchVersionResult -ne 0 ]; then
182+
patchVersionResult=$?
183+
if [ "$patchVersionResult" -ne "0" ]; then
155184
echo "Failed to bump version of polywrap-manifest to $1"
156185
exit 1
157186
fi
158187

159188
echo "Publishing polywrap-manifest"
160189
publishPackage polywrap-manifest $2 $3
161-
local publishResult=$?
162-
if [ $publishResult -ne 0 ]; then
190+
publishResult=$?
191+
if [ "$publishResult" -ne "0" ]; then
163192
echo "Failed to publish polywrap-manifest"
164193
exit 1
165194
fi
166195

167196
echo "Waiting for the package to be published"
168197
waitForPackagePublish polywrap-manifest $1
169-
local waitForPackagePublishResult=$?
170-
if [ $waitForPackagePublishResult -ne 0 ]; then
198+
waitForPackagePublishResult=$?
199+
if [ "$waitForPackagePublishResult" -ne "0" ]; then
171200
echo "Failed to publish polywrap-manifest"
172201
exit 1
173202
fi
@@ -176,24 +205,24 @@ fi
176205
echo "Patching Version of polywrap-core to $1"
177206
deps=(polywrap-result polywrap-manifest)
178207
patchVersion polywrap-core $1 deps
179-
local patchVersionResult=$?
180-
if [ $patchVersionResult -ne 0 ]; then
208+
patchVersionResult=$?
209+
if [ "$patchVersionResult" -ne "0" ]; then
181210
echo "Failed to bump version of polywrap-core to $1"
182211
exit 1
183212
fi
184213

185214
echo "Publishing polywrap-core"
186215
publishPackage polywrap-core $2 $3
187-
local publishResult=$?
188-
if [ $publishResult -ne 0 ]; then
216+
publishResult=$?
217+
if [ "$publishResult" -ne "0" ]; then
189218
echo "Failed to publish polywrap-core"
190219
exit 1
191220
fi
192221

193222
echo "Waiting for the package to be published"
194223
waitForPackagePublish polywrap-core $1
195-
local waitForPackagePublishResult=$?
196-
if [ $waitForPackagePublishResult -ne 0 ]; then
224+
waitForPackagePublishResult=$?
225+
if [ "$waitForPackagePublishResult" -ne "0" ]; then
197226
echo "Failed to publish polywrap-core"
198227
exit 1
199228
fi
@@ -202,24 +231,24 @@ fi
202231
echo "Patching Version of polywrap-wasm to $1"
203232
deps=(polywrap-msgpack polywrap-result polywrap-manifest polywrap-core)
204233
patchVersion polywrap-wasm $1 deps
205-
local patchVersionResult=$?
206-
if [ $patchVersionResult -ne 0 ]; then
234+
patchVersionResult=$?
235+
if [ "$patchVersionResult" -ne "0" ]; then
207236
echo "Failed to bump version of polywrap-wasm to $1"
208237
exit 1
209238
fi
210239

211240
echo "Publishing polywrap-wasm"
212241
publishPackage polywrap-wasm $2 $3
213-
local publishResult=$?
214-
if [ $publishResult -ne 0 ]; then
242+
publishResult=$?
243+
if [ "$publishResult" -ne "0" ]; then
215244
echo "Failed to publish polywrap-wasm"
216245
exit 1
217246
fi
218247

219248
echo "Waiting for the package to be published"
220249
waitForPackagePublish polywrap-wasm $1
221-
local waitForPackagePublishResult=$?
222-
if [ $waitForPackagePublishResult -ne 0 ]; then
250+
waitForPackagePublishResult=$?
251+
if [ "$waitForPackagePublishResult" -ne "0" ]; then
223252
echo "Failed to publish polywrap-wasm"
224253
exit 1
225254
fi
@@ -228,24 +257,24 @@ fi
228257
echo "Patching Version of polywrap-plugin to $1"
229258
deps=(polywrap-msgpack polywrap-result polywrap-manifest polywrap-core)
230259
patchVersion polywrap-plugin $1 deps
231-
local patchVersionResult=$?
232-
if [ $patchVersionResult -ne 0 ]; then
260+
patchVersionResult=$?
261+
if [ "$patchVersionResult" -ne "0" ]; then
233262
echo "Failed to bump version of polywrap-plugin to $1"
234263
exit 1
235264
fi
236265

237266
echo "Publishing polywrap-plugin"
238267
publishPackage polywrap-plugin $2 $3
239-
local publishResult=$?
240-
if [ $publishResult -ne 0 ]; then
268+
publishResult=$?
269+
if [ "$publishResult" -ne "0" ]; then
241270
echo "Failed to publish polywrap-plugin"
242271
exit 1
243272
fi
244273

245274
echo "Waiting for the package to be published"
246275
waitForPackagePublish polywrap-plugin $1
247-
local waitForPackagePublishResult=$?
248-
if [ $waitForPackagePublishResult -ne 0 ]; then
276+
waitForPackagePublishResult=$?
277+
if [ "$waitForPackagePublishResult" -ne "0" ]; then
249278
echo "Failed to publish polywrap-plugin"
250279
exit 1
251280
fi
@@ -254,24 +283,24 @@ fi
254283
echo "Patching Version of polywrap-uri-resolvers to $1"
255284
deps=(polywrap-result polywrap-wasm polywrap-core)
256285
patchVersion polywrap-uri-resolvers $1 deps
257-
local patchVersionResult=$?
258-
if [ $patchVersionResult -ne 0 ]; then
286+
patchVersionResult=$?
287+
if [ "$patchVersionResult" -ne "0" ]; then
259288
echo "Failed to bump version of polywrap-uri-resolvers to $1"
260289
exit 1
261290
fi
262291

263292
echo "Publishing polywrap-uri-resolvers"
264293
publishPackage polywrap-uri-resolvers $2 $3
265-
local publishResult=$?
266-
if [ $publishResult -ne 0 ]; then
294+
publishResult=$?
295+
if [ "$publishResult" -ne "0" ]; then
267296
echo "Failed to publish polywrap-uri-resolvers"
268297
exit 1
269298
fi
270299

271300
echo "Waiting for the package to be published"
272301
waitForPackagePublish polywrap-uri-resolvers $1
273-
local waitForPackagePublishResult=$?
274-
if [ $waitForPackagePublishResult -ne 0 ]; then
302+
waitForPackagePublishResult=$?
303+
if [ "$waitForPackagePublishResult" -ne "0" ]; then
275304
echo "Failed to publish polywrap-uri-resolvers"
276305
exit 1
277306
fi
@@ -280,24 +309,24 @@ fi
280309
echo "Patching Version of polywrap-client to $1"
281310
deps=(polywrap-result polywrap-msgpack polywrap-manifest polywrap-core polywrap-uri-resolvers)
282311
patchVersion polywrap-client $1 deps
283-
local patchVersionResult=$?
284-
if [ $patchVersionResult -ne 0 ]; then
312+
patchVersionResult=$?
313+
if [ "$patchVersionResult" -ne "0" ]; then
285314
echo "Failed to bump version of polywrap-client to $1"
286315
exit 1
287316
fi
288317

289318
echo "Publishing polywrap-client"
290319
publishPackage polywrap-client $2 $3
291-
local publishResult=$?
292-
if [ $publishResult -ne 0 ]; then
320+
publishResult=$?
321+
if [ "$publishResult" -ne "0" ]; then
293322
echo "Failed to publish polywrap-client"
294323
exit 1
295324
fi
296325

297326
echo "Waiting for the package to be published"
298327
waitForPackagePublish polywrap-client $1
299-
local waitForPackagePublishResult=$?
300-
if [ $waitForPackagePublishResult -ne 0 ]; then
328+
waitForPackagePublishResult=$?
329+
if [ "$waitForPackagePublishResult" -ne "0" ]; then
301330
echo "Failed to publish polywrap-client"
302331
exit 1
303332
fi

0 commit comments

Comments
 (0)