@@ -16,71 +16,105 @@ 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+ cd $pwd
22+ return 1
2223 fi
2324
24- if [ " ${# deps[@]} " -ne " 0" ]; then
25- if [ " ${deps[0]} " != " " ]; then
25+ if [ " ${# deps[@]} " -ne " 0" ]; then # -ne is integer inequality
26+ if [ " ${deps[0]} " != " " ]; then # != is string inequality
2627 for dep in " ${deps[@]} " ; do
2728 poetry add $dep @$version
2829 local addDepResult=$?
29- if [ $addDepResult -ne 0 ]; then
30+ if [ " $addDepResult " -ne " 0 " ]; then
3031 echo " Failed to add $dep @$version to $package "
31- exit 1
32+ cd $pwd
33+ return 1
3234 fi
3335 done
3436 fi
3537 fi
3638
3739 poetry lock
3840 local lockResult=$?
39- if [ $lockResult -ne 0 ]; then
41+ if [ " $lockResult " -ne " 0 " ]; then
4042 echo " Failed to lock $package "
41- exit 1
43+ cd $pwd
44+ return 1
4245 fi
4346
4447 poetry install
4548 local installResult=$?
46- if [ $installResult -ne 0 ]; then
49+ if [ " $installResult " -ne " 0 " ]; then
4750 echo " Failed to install $package "
48- exit 1
51+ cd $pwd
52+ return 1
4953 fi
5054
5155 cd $pwd
5256}
5357
5458function publishPackage() {
5559 local package=$1
56- local username=$2
57- local password=$3
60+ local version=$2
61+ local username=$3
62+ local password=$4
5863
5964 local pwd=$( echo $PWD )
6065
6166 cd packages/$package
6267
68+ isPackagePublished $package $version
69+ local isPackagePublishedResult=$?
70+ if [ " $isPackagePublishedResult " -eq " 0" ]; then
71+ echo " Skip publish: Package $package with version $version is already published"
72+ cd $pwd
73+ return 0
74+ fi
75+
6376 poetry publish --build --username $username --password $password
6477 local publishResult=$?
65- if [ $publishResult -ne 0 ]; then
78+ if [ " $publishResult " -ne " 0 " ]; then
6679 echo " Failed to publish $package "
67- exit 1
80+ cd $pwd
81+ return 1
6882 fi
6983
7084 cd $pwd
7185}
7286
87+ # This will only work for the latest version of the package
88+ # Can only be called inside the top level function since directory needs to be changed
89+ function isPackagePublished() {
90+ local package=$1
91+ local version=$2
92+
93+ poetry search $package | grep " $package ($version )"
94+ local exit_code=$?
95+
96+ if [ " $exit_code " -eq " 0" ]; then
97+ return 0
98+ else
99+ return 1
100+ fi
101+ }
102+
73103function waitForPackagePublish() {
74104 local package=$1
75105 local version=$2
76106 local seconds=0
77107
78- while [ $seconds -lt 600 ] # Wait for 10 minutes
108+ local pwd=$( echo $PWD )
109+
110+ cd packages/$package
111+
112+ while [ " $seconds " -lt " 600" ] # Wait for 10 minutes
79113 do
80- poetry search $package | grep " $package \( $ version\) "
114+ isPackagePublished $package $ version
81115 local exit_code=$?
82116
83- if [ $exit_code -eq 0 ]; then
117+ if [ " $exit_code " -eq " 0 " ]; then
84118 echo " Package $package with version $version is published"
85119 break
86120 fi
@@ -89,59 +123,61 @@ function waitForPackagePublish() {
89123 echo " Waiting for $seconds seconds for the $package to be published"
90124 done
91125
92- if [ $seconds -eq 600 ]; then
126+ cd $pwd
127+
128+ if [ " $seconds " -eq " 600" ]; then
93129 echo " Package $package with version $version is not published"
94- exit 1
130+ return 1
95131 fi
96132}
97133
98134
99135# Patching Verion of polywrap-msgpack
100136echo " Patching Version of polywrap-msgpack to $1 "
101137patchVersion polywrap-msgpack $1
102- local patchVersionResult=$?
103- if [ $patchVersionResult -ne 0 ]; then
138+ patchVersionResult=$?
139+ if [ " $patchVersionResult " -ne " 0 " ]; then
104140 echo " Failed to bump version of polywrap-msgpack to $1 "
105141 exit 1
106142fi
107143
108144echo " Publishing polywrap-msgpack"
109- publishPackage polywrap-msgpack $2 $3
110- local publishResult=$?
111- if [ $publishResult -ne 0 ]; then
145+ publishPackage polywrap-msgpack $1 $ 2 $3
146+ publishResult=$?
147+ if [ " $publishResult " -ne " 0 " ]; then
112148 echo " Failed to publish polywrap-msgpack"
113149 exit 1
114150fi
115151
116152echo " Waiting for the package to be published"
117153waitForPackagePublish polywrap-msgpack $1
118- local waitForPackagePublishResult=$?
119- if [ $waitForPackagePublishResult -ne 0 ]; then
154+ waitForPackagePublishResult=$?
155+ if [ " $waitForPackagePublishResult " -ne " 0 " ]; then
120156 echo " Failed to publish polywrap-msgpack"
121157 exit 1
122158fi
123159
124160# Patching Verion of polywrap-result
125161echo " Patching Version of polywrap-result to $1 "
126162patchVersion polywrap-result $1
127- local patchVersionResult=$?
128- if [ $patchVersionResult -ne 0 ]; then
163+ patchVersionResult=$?
164+ if [ " $patchVersionResult " -ne " 0 " ]; then
129165 echo " Failed to bump version of polywrap-result to $1 "
130166 exit 1
131167fi
132168
133169echo " Publishing polywrap-result"
134- publishPackage polywrap-result $2 $3
135- local publishResult=$?
136- if [ $publishResult -ne 0 ]; then
170+ publishPackage polywrap-result $1 $ 2 $3
171+ publishResult=$?
172+ if [ " $publishResult " -ne " 0 " ]; then
137173 echo " Failed to publish polywrap-result"
138174 exit 1
139175fi
140176
141177echo " Waiting for the package to be published"
142178waitForPackagePublish polywrap-result $1
143- local waitForPackagePublishResult=$?
144- if [ $waitForPackagePublishResult -ne 0 ]; then
179+ waitForPackagePublishResult=$?
180+ if [ " $waitForPackagePublishResult " -ne " 0 " ]; then
145181 echo " Failed to publish polywrap-result"
146182 exit 1
147183fi
150186echo " Patching Version of polywrap-manifest to $1 "
151187deps=(polywrap-msgpack polywrap-result)
152188patchVersion polywrap-manifest $1 deps
153- local patchVersionResult=$?
154- if [ $patchVersionResult -ne 0 ]; then
189+ patchVersionResult=$?
190+ if [ " $patchVersionResult " -ne " 0 " ]; then
155191 echo " Failed to bump version of polywrap-manifest to $1 "
156192 exit 1
157193fi
158194
159195echo " Publishing polywrap-manifest"
160- publishPackage polywrap-manifest $2 $3
161- local publishResult=$?
162- if [ $publishResult -ne 0 ]; then
196+ publishPackage polywrap-manifest $1 $ 2 $3
197+ publishResult=$?
198+ if [ " $publishResult " -ne " 0 " ]; then
163199 echo " Failed to publish polywrap-manifest"
164200 exit 1
165201fi
166202
167203echo " Waiting for the package to be published"
168204waitForPackagePublish polywrap-manifest $1
169- local waitForPackagePublishResult=$?
170- if [ $waitForPackagePublishResult -ne 0 ]; then
205+ waitForPackagePublishResult=$?
206+ if [ " $waitForPackagePublishResult " -ne " 0 " ]; then
171207 echo " Failed to publish polywrap-manifest"
172208 exit 1
173209fi
176212echo " Patching Version of polywrap-core to $1 "
177213deps=(polywrap-result polywrap-manifest)
178214patchVersion polywrap-core $1 deps
179- local patchVersionResult=$?
180- if [ $patchVersionResult -ne 0 ]; then
215+ patchVersionResult=$?
216+ if [ " $patchVersionResult " -ne " 0 " ]; then
181217 echo " Failed to bump version of polywrap-core to $1 "
182218 exit 1
183219fi
184220
185221echo " Publishing polywrap-core"
186- publishPackage polywrap-core $2 $3
187- local publishResult=$?
188- if [ $publishResult -ne 0 ]; then
222+ publishPackage polywrap-core $1 $ 2 $3
223+ publishResult=$?
224+ if [ " $publishResult " -ne " 0 " ]; then
189225 echo " Failed to publish polywrap-core"
190226 exit 1
191227fi
192228
193229echo " Waiting for the package to be published"
194230waitForPackagePublish polywrap-core $1
195- local waitForPackagePublishResult=$?
196- if [ $waitForPackagePublishResult -ne 0 ]; then
231+ waitForPackagePublishResult=$?
232+ if [ " $waitForPackagePublishResult " -ne " 0 " ]; then
197233 echo " Failed to publish polywrap-core"
198234 exit 1
199235fi
202238echo " Patching Version of polywrap-wasm to $1 "
203239deps=(polywrap-msgpack polywrap-result polywrap-manifest polywrap-core)
204240patchVersion polywrap-wasm $1 deps
205- local patchVersionResult=$?
206- if [ $patchVersionResult -ne 0 ]; then
241+ patchVersionResult=$?
242+ if [ " $patchVersionResult " -ne " 0 " ]; then
207243 echo " Failed to bump version of polywrap-wasm to $1 "
208244 exit 1
209245fi
210246
211247echo " Publishing polywrap-wasm"
212- publishPackage polywrap-wasm $2 $3
213- local publishResult=$?
214- if [ $publishResult -ne 0 ]; then
248+ publishPackage polywrap-wasm $1 $ 2 $3
249+ publishResult=$?
250+ if [ " $publishResult " -ne " 0 " ]; then
215251 echo " Failed to publish polywrap-wasm"
216252 exit 1
217253fi
218254
219255echo " Waiting for the package to be published"
220256waitForPackagePublish polywrap-wasm $1
221- local waitForPackagePublishResult=$?
222- if [ $waitForPackagePublishResult -ne 0 ]; then
257+ waitForPackagePublishResult=$?
258+ if [ " $waitForPackagePublishResult " -ne " 0 " ]; then
223259 echo " Failed to publish polywrap-wasm"
224260 exit 1
225261fi
228264echo " Patching Version of polywrap-plugin to $1 "
229265deps=(polywrap-msgpack polywrap-result polywrap-manifest polywrap-core)
230266patchVersion polywrap-plugin $1 deps
231- local patchVersionResult=$?
232- if [ $patchVersionResult -ne 0 ]; then
267+ patchVersionResult=$?
268+ if [ " $patchVersionResult " -ne " 0 " ]; then
233269 echo " Failed to bump version of polywrap-plugin to $1 "
234270 exit 1
235271fi
236272
237273echo " Publishing polywrap-plugin"
238- publishPackage polywrap-plugin $2 $3
239- local publishResult=$?
240- if [ $publishResult -ne 0 ]; then
274+ publishPackage polywrap-plugin $1 $ 2 $3
275+ publishResult=$?
276+ if [ " $publishResult " -ne " 0 " ]; then
241277 echo " Failed to publish polywrap-plugin"
242278 exit 1
243279fi
244280
245281echo " Waiting for the package to be published"
246282waitForPackagePublish polywrap-plugin $1
247- local waitForPackagePublishResult=$?
248- if [ $waitForPackagePublishResult -ne 0 ]; then
283+ waitForPackagePublishResult=$?
284+ if [ " $waitForPackagePublishResult " -ne " 0 " ]; then
249285 echo " Failed to publish polywrap-plugin"
250286 exit 1
251287fi
254290echo " Patching Version of polywrap-uri-resolvers to $1 "
255291deps=(polywrap-result polywrap-wasm polywrap-core)
256292patchVersion polywrap-uri-resolvers $1 deps
257- local patchVersionResult=$?
258- if [ $patchVersionResult -ne 0 ]; then
293+ patchVersionResult=$?
294+ if [ " $patchVersionResult " -ne " 0 " ]; then
259295 echo " Failed to bump version of polywrap-uri-resolvers to $1 "
260296 exit 1
261297fi
262298
263299echo " Publishing polywrap-uri-resolvers"
264- publishPackage polywrap-uri-resolvers $2 $3
265- local publishResult=$?
266- if [ $publishResult -ne 0 ]; then
300+ publishPackage polywrap-uri-resolvers $1 $ 2 $3
301+ publishResult=$?
302+ if [ " $publishResult " -ne " 0 " ]; then
267303 echo " Failed to publish polywrap-uri-resolvers"
268304 exit 1
269305fi
270306
271307echo " Waiting for the package to be published"
272308waitForPackagePublish polywrap-uri-resolvers $1
273- local waitForPackagePublishResult=$?
274- if [ $waitForPackagePublishResult -ne 0 ]; then
309+ waitForPackagePublishResult=$?
310+ if [ " $waitForPackagePublishResult " -ne " 0 " ]; then
275311 echo " Failed to publish polywrap-uri-resolvers"
276312 exit 1
277313fi
280316echo " Patching Version of polywrap-client to $1 "
281317deps=(polywrap-result polywrap-msgpack polywrap-manifest polywrap-core polywrap-uri-resolvers)
282318patchVersion polywrap-client $1 deps
283- local patchVersionResult=$?
284- if [ $patchVersionResult -ne 0 ]; then
319+ patchVersionResult=$?
320+ if [ " $patchVersionResult " -ne " 0 " ]; then
285321 echo " Failed to bump version of polywrap-client to $1 "
286322 exit 1
287323fi
288324
289325echo " Publishing polywrap-client"
290- publishPackage polywrap-client $2 $3
291- local publishResult=$?
292- if [ $publishResult -ne 0 ]; then
326+ publishPackage polywrap-client $1 $ 2 $3
327+ publishResult=$?
328+ if [ " $publishResult " -ne " 0 " ]; then
293329 echo " Failed to publish polywrap-client"
294330 exit 1
295331fi
296332
297333echo " Waiting for the package to be published"
298334waitForPackagePublish polywrap-client $1
299- local waitForPackagePublishResult=$?
300- if [ $waitForPackagePublishResult -ne 0 ]; then
335+ waitForPackagePublishResult=$?
336+ if [ " $waitForPackagePublishResult " -ne " 0 " ]; then
301337 echo " Failed to publish polywrap-client"
302338 exit 1
303339fi
0 commit comments