From 8b29ba6393b9d0d59412eb0f0b29e174cf8d5df9 Mon Sep 17 00:00:00 2001 From: Niraj Kamdar Date: Fri, 3 Mar 2023 14:39:51 +0400 Subject: [PATCH 1/2] wip --- scripts/publishPackages.sh | 159 ++++++++++++++++++++++--------------- 1 file changed, 94 insertions(+), 65 deletions(-) diff --git a/scripts/publishPackages.sh b/scripts/publishPackages.sh index e7cc947a..3801d3a2 100644 --- a/scripts/publishPackages.sh +++ b/scripts/publishPackages.sh @@ -16,19 +16,19 @@ function patchVersion() { poetry version $version local bumpVersionResult=$? - if [ $bumpVersionResult -ne 0 ]; then + if [ "$bumpVersionResult" -ne "0" ]; then echo "Failed to bump version of $package to $version" - exit 1 + return 1 fi - if [ "${#deps[@]}" -ne "0" ]; then - if [ "${deps[0]}" != "" ]; then + if [ "${#deps[@]}" -ne "0" ]; then # -ne is integer inequality + if [ "${deps[0]}" != "" ]; then # != is string inequality for dep in "${deps[@]}"; do poetry add $dep@$version local addDepResult=$? - if [ $addDepResult -ne 0 ]; then + if [ "$addDepResult" -ne "0" ]; then echo "Failed to add $dep@$version to $package" - exit 1 + return 1 fi done fi @@ -36,16 +36,16 @@ function patchVersion() { poetry lock local lockResult=$? - if [ $lockResult -ne 0 ]; then + if [ "$lockResult" -ne "0" ]; then echo "Failed to lock $package" - exit 1 + return 1 fi poetry install local installResult=$? - if [ $installResult -ne 0 ]; then + if [ "$installResult" -ne "0" ]; then echo "Failed to install $package" - exit 1 + return 1 fi cd $pwd @@ -60,27 +60,54 @@ function publishPackage() { cd packages/$package + isPackagePublished $package $version + local isPackagePublishedResult=$? + echo "isPackagePublishedResult: $isPackagePublishedResult" + if [ "$isPackagePublishedResult" -eq "0" ]; then + echo "Skip publish: Package $package with version $version is already published" + return 0 + fi + poetry publish --build --username $username --password $password local publishResult=$? - if [ $publishResult -ne 0 ]; then + if [ "$publishResult" -ne "0" ]; then echo "Failed to publish $package" - exit 1 + return 1 fi cd $pwd } +# This will only work for the latest version of the package +function isPackagePublished() { + local package=$1 + local version=$2 + + poetry search $package | grep "$package ($version)" + echo $(poetry search $package | grep "$package ($version)") + local exit_code=$? + echo "exit_code: $exit_code" + + if [ "$exit_code" -eq "0" ]; then + echo "Package $package with version $version is published" + return 0 + else + echo "Package $package with version $version is not published" + return 1 + fi +} + function waitForPackagePublish() { local package=$1 local version=$2 local seconds=0 - while [ $seconds -lt 600 ] # Wait for 10 minutes + while [ "$seconds" -lt "600" ] # Wait for 10 minutes do - poetry search $package | grep "$package \($version\)" + isPackagePublished $package $version local exit_code=$? - if [ $exit_code -eq 0 ]; then + if [ "$exit_code" -eq "0" ]; then echo "Package $package with version $version is published" break fi @@ -89,9 +116,9 @@ function waitForPackagePublish() { echo "Waiting for $seconds seconds for the $package to be published" done - if [ $seconds -eq 600 ]; then + if [ "$seconds" -eq "600" ]; then echo "Package $package with version $version is not published" - exit 1 + return 1 fi } @@ -99,24 +126,26 @@ function waitForPackagePublish() { # Patching Verion of polywrap-msgpack echo "Patching Version of polywrap-msgpack to $1" patchVersion polywrap-msgpack $1 -local patchVersionResult=$? -if [ $patchVersionResult -ne 0 ]; then +patchVersionResult=$? +if [ "$patchVersionResult" -ne "0" ]; then echo "Failed to bump version of polywrap-msgpack to $1" exit 1 fi echo "Publishing polywrap-msgpack" publishPackage polywrap-msgpack $2 $3 -local publishResult=$? -if [ $publishResult -ne 0 ]; then +publishResult=$? +echo "publishResult: $publishResult" +echo [ "$publishResult" -ne "0" ] +if [ "$publishResult" -ne "0" ]; then echo "Failed to publish polywrap-msgpack" exit 1 fi echo "Waiting for the package to be published" waitForPackagePublish polywrap-msgpack $1 -local waitForPackagePublishResult=$? -if [ $waitForPackagePublishResult -ne 0 ]; then +waitForPackagePublishResult=$? +if [ "$waitForPackagePublishResult" -ne "0" ]; then echo "Failed to publish polywrap-msgpack" exit 1 fi @@ -124,24 +153,24 @@ fi # Patching Verion of polywrap-result echo "Patching Version of polywrap-result to $1" patchVersion polywrap-result $1 -local patchVersionResult=$? -if [ $patchVersionResult -ne 0 ]; then +patchVersionResult=$? +if [ "$patchVersionResult" -ne "0" ]; then echo "Failed to bump version of polywrap-result to $1" exit 1 fi echo "Publishing polywrap-result" publishPackage polywrap-result $2 $3 -local publishResult=$? -if [ $publishResult -ne 0 ]; then +publishResult=$? +if [ "$publishResult" -ne "0" ]; then echo "Failed to publish polywrap-result" exit 1 fi echo "Waiting for the package to be published" waitForPackagePublish polywrap-result $1 -local waitForPackagePublishResult=$? -if [ $waitForPackagePublishResult -ne 0 ]; then +waitForPackagePublishResult=$? +if [ "$waitForPackagePublishResult" -ne "0" ]; then echo "Failed to publish polywrap-result" exit 1 fi @@ -150,24 +179,24 @@ fi echo "Patching Version of polywrap-manifest to $1" deps=(polywrap-msgpack polywrap-result) patchVersion polywrap-manifest $1 deps -local patchVersionResult=$? -if [ $patchVersionResult -ne 0 ]; then +patchVersionResult=$? +if [ "$patchVersionResult" -ne "0" ]; then echo "Failed to bump version of polywrap-manifest to $1" exit 1 fi echo "Publishing polywrap-manifest" publishPackage polywrap-manifest $2 $3 -local publishResult=$? -if [ $publishResult -ne 0 ]; then +publishResult=$? +if [ "$publishResult" -ne "0" ]; then echo "Failed to publish polywrap-manifest" exit 1 fi echo "Waiting for the package to be published" waitForPackagePublish polywrap-manifest $1 -local waitForPackagePublishResult=$? -if [ $waitForPackagePublishResult -ne 0 ]; then +waitForPackagePublishResult=$? +if [ "$waitForPackagePublishResult" -ne "0" ]; then echo "Failed to publish polywrap-manifest" exit 1 fi @@ -176,24 +205,24 @@ fi echo "Patching Version of polywrap-core to $1" deps=(polywrap-result polywrap-manifest) patchVersion polywrap-core $1 deps -local patchVersionResult=$? -if [ $patchVersionResult -ne 0 ]; then +patchVersionResult=$? +if [ "$patchVersionResult" -ne "0" ]; then echo "Failed to bump version of polywrap-core to $1" exit 1 fi echo "Publishing polywrap-core" publishPackage polywrap-core $2 $3 -local publishResult=$? -if [ $publishResult -ne 0 ]; then +publishResult=$? +if [ "$publishResult" -ne "0" ]; then echo "Failed to publish polywrap-core" exit 1 fi echo "Waiting for the package to be published" waitForPackagePublish polywrap-core $1 -local waitForPackagePublishResult=$? -if [ $waitForPackagePublishResult -ne 0 ]; then +waitForPackagePublishResult=$? +if [ "$waitForPackagePublishResult" -ne "0" ]; then echo "Failed to publish polywrap-core" exit 1 fi @@ -202,24 +231,24 @@ fi echo "Patching Version of polywrap-wasm to $1" deps=(polywrap-msgpack polywrap-result polywrap-manifest polywrap-core) patchVersion polywrap-wasm $1 deps -local patchVersionResult=$? -if [ $patchVersionResult -ne 0 ]; then +patchVersionResult=$? +if [ "$patchVersionResult" -ne "0" ]; then echo "Failed to bump version of polywrap-wasm to $1" exit 1 fi echo "Publishing polywrap-wasm" publishPackage polywrap-wasm $2 $3 -local publishResult=$? -if [ $publishResult -ne 0 ]; then +publishResult=$? +if [ "$publishResult" -ne "0" ]; then echo "Failed to publish polywrap-wasm" exit 1 fi echo "Waiting for the package to be published" waitForPackagePublish polywrap-wasm $1 -local waitForPackagePublishResult=$? -if [ $waitForPackagePublishResult -ne 0 ]; then +waitForPackagePublishResult=$? +if [ "$waitForPackagePublishResult" -ne "0" ]; then echo "Failed to publish polywrap-wasm" exit 1 fi @@ -228,24 +257,24 @@ fi echo "Patching Version of polywrap-plugin to $1" deps=(polywrap-msgpack polywrap-result polywrap-manifest polywrap-core) patchVersion polywrap-plugin $1 deps -local patchVersionResult=$? -if [ $patchVersionResult -ne 0 ]; then +patchVersionResult=$? +if [ "$patchVersionResult" -ne "0" ]; then echo "Failed to bump version of polywrap-plugin to $1" exit 1 fi echo "Publishing polywrap-plugin" publishPackage polywrap-plugin $2 $3 -local publishResult=$? -if [ $publishResult -ne 0 ]; then +publishResult=$? +if [ "$publishResult" -ne "0" ]; then echo "Failed to publish polywrap-plugin" exit 1 fi echo "Waiting for the package to be published" waitForPackagePublish polywrap-plugin $1 -local waitForPackagePublishResult=$? -if [ $waitForPackagePublishResult -ne 0 ]; then +waitForPackagePublishResult=$? +if [ "$waitForPackagePublishResult" -ne "0" ]; then echo "Failed to publish polywrap-plugin" exit 1 fi @@ -254,24 +283,24 @@ fi echo "Patching Version of polywrap-uri-resolvers to $1" deps=(polywrap-result polywrap-wasm polywrap-core) patchVersion polywrap-uri-resolvers $1 deps -local patchVersionResult=$? -if [ $patchVersionResult -ne 0 ]; then +patchVersionResult=$? +if [ "$patchVersionResult" -ne "0" ]; then echo "Failed to bump version of polywrap-uri-resolvers to $1" exit 1 fi echo "Publishing polywrap-uri-resolvers" publishPackage polywrap-uri-resolvers $2 $3 -local publishResult=$? -if [ $publishResult -ne 0 ]; then +publishResult=$? +if [ "$publishResult" -ne "0" ]; then echo "Failed to publish polywrap-uri-resolvers" exit 1 fi echo "Waiting for the package to be published" waitForPackagePublish polywrap-uri-resolvers $1 -local waitForPackagePublishResult=$? -if [ $waitForPackagePublishResult -ne 0 ]; then +waitForPackagePublishResult=$? +if [ "$waitForPackagePublishResult" -ne "0" ]; then echo "Failed to publish polywrap-uri-resolvers" exit 1 fi @@ -280,24 +309,24 @@ fi echo "Patching Version of polywrap-client to $1" deps=(polywrap-result polywrap-msgpack polywrap-manifest polywrap-core polywrap-uri-resolvers) patchVersion polywrap-client $1 deps -local patchVersionResult=$? -if [ $patchVersionResult -ne 0 ]; then +patchVersionResult=$? +if [ "$patchVersionResult" -ne "0" ]; then echo "Failed to bump version of polywrap-client to $1" exit 1 fi echo "Publishing polywrap-client" publishPackage polywrap-client $2 $3 -local publishResult=$? -if [ $publishResult -ne 0 ]; then +publishResult=$? +if [ "$publishResult" -ne "0" ]; then echo "Failed to publish polywrap-client" exit 1 fi echo "Waiting for the package to be published" waitForPackagePublish polywrap-client $1 -local waitForPackagePublishResult=$? -if [ $waitForPackagePublishResult -ne 0 ]; then +waitForPackagePublishResult=$? +if [ "$waitForPackagePublishResult" -ne "0" ]; then echo "Failed to publish polywrap-client" exit 1 fi From aaf3c0b038d354576bfc1653becf92a903423df0 Mon Sep 17 00:00:00 2001 From: Niraj Kamdar Date: Fri, 3 Mar 2023 15:12:06 +0400 Subject: [PATCH 2/2] fix: publishPackages script --- scripts/publishPackages.sh | 41 ++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/scripts/publishPackages.sh b/scripts/publishPackages.sh index 3801d3a2..52db3e3f 100644 --- a/scripts/publishPackages.sh +++ b/scripts/publishPackages.sh @@ -18,6 +18,7 @@ function patchVersion() { local bumpVersionResult=$? if [ "$bumpVersionResult" -ne "0" ]; then echo "Failed to bump version of $package to $version" + cd $pwd return 1 fi @@ -28,6 +29,7 @@ function patchVersion() { local addDepResult=$? if [ "$addDepResult" -ne "0" ]; then echo "Failed to add $dep@$version to $package" + cd $pwd return 1 fi done @@ -38,6 +40,7 @@ function patchVersion() { local lockResult=$? if [ "$lockResult" -ne "0" ]; then echo "Failed to lock $package" + cd $pwd return 1 fi @@ -45,6 +48,7 @@ function patchVersion() { local installResult=$? if [ "$installResult" -ne "0" ]; then echo "Failed to install $package" + cd $pwd return 1 fi @@ -53,8 +57,9 @@ function patchVersion() { function publishPackage() { local package=$1 - local username=$2 - local password=$3 + local version=$2 + local username=$3 + local password=$4 local pwd=$(echo $PWD) @@ -62,9 +67,9 @@ function publishPackage() { isPackagePublished $package $version local isPackagePublishedResult=$? - echo "isPackagePublishedResult: $isPackagePublishedResult" if [ "$isPackagePublishedResult" -eq "0" ]; then echo "Skip publish: Package $package with version $version is already published" + cd $pwd return 0 fi @@ -72,6 +77,7 @@ function publishPackage() { local publishResult=$? if [ "$publishResult" -ne "0" ]; then echo "Failed to publish $package" + cd $pwd return 1 fi @@ -79,20 +85,17 @@ function publishPackage() { } # This will only work for the latest version of the package +# Can only be called inside the top level function since directory needs to be changed function isPackagePublished() { local package=$1 local version=$2 poetry search $package | grep "$package ($version)" - echo $(poetry search $package | grep "$package ($version)") local exit_code=$? - echo "exit_code: $exit_code" if [ "$exit_code" -eq "0" ]; then - echo "Package $package with version $version is published" return 0 else - echo "Package $package with version $version is not published" return 1 fi } @@ -102,6 +105,10 @@ function waitForPackagePublish() { local version=$2 local seconds=0 + local pwd=$(echo $PWD) + + cd packages/$package + while [ "$seconds" -lt "600" ] # Wait for 10 minutes do isPackagePublished $package $version @@ -116,6 +123,8 @@ function waitForPackagePublish() { echo "Waiting for $seconds seconds for the $package to be published" done + cd $pwd + if [ "$seconds" -eq "600" ]; then echo "Package $package with version $version is not published" return 1 @@ -133,10 +142,8 @@ if [ "$patchVersionResult" -ne "0" ]; then fi echo "Publishing polywrap-msgpack" -publishPackage polywrap-msgpack $2 $3 +publishPackage polywrap-msgpack $1 $2 $3 publishResult=$? -echo "publishResult: $publishResult" -echo [ "$publishResult" -ne "0" ] if [ "$publishResult" -ne "0" ]; then echo "Failed to publish polywrap-msgpack" exit 1 @@ -160,7 +167,7 @@ if [ "$patchVersionResult" -ne "0" ]; then fi echo "Publishing polywrap-result" -publishPackage polywrap-result $2 $3 +publishPackage polywrap-result $1 $2 $3 publishResult=$? if [ "$publishResult" -ne "0" ]; then echo "Failed to publish polywrap-result" @@ -186,7 +193,7 @@ if [ "$patchVersionResult" -ne "0" ]; then fi echo "Publishing polywrap-manifest" -publishPackage polywrap-manifest $2 $3 +publishPackage polywrap-manifest $1 $2 $3 publishResult=$? if [ "$publishResult" -ne "0" ]; then echo "Failed to publish polywrap-manifest" @@ -212,7 +219,7 @@ if [ "$patchVersionResult" -ne "0" ]; then fi echo "Publishing polywrap-core" -publishPackage polywrap-core $2 $3 +publishPackage polywrap-core $1 $2 $3 publishResult=$? if [ "$publishResult" -ne "0" ]; then echo "Failed to publish polywrap-core" @@ -238,7 +245,7 @@ if [ "$patchVersionResult" -ne "0" ]; then fi echo "Publishing polywrap-wasm" -publishPackage polywrap-wasm $2 $3 +publishPackage polywrap-wasm $1 $2 $3 publishResult=$? if [ "$publishResult" -ne "0" ]; then echo "Failed to publish polywrap-wasm" @@ -264,7 +271,7 @@ if [ "$patchVersionResult" -ne "0" ]; then fi echo "Publishing polywrap-plugin" -publishPackage polywrap-plugin $2 $3 +publishPackage polywrap-plugin $1 $2 $3 publishResult=$? if [ "$publishResult" -ne "0" ]; then echo "Failed to publish polywrap-plugin" @@ -290,7 +297,7 @@ if [ "$patchVersionResult" -ne "0" ]; then fi echo "Publishing polywrap-uri-resolvers" -publishPackage polywrap-uri-resolvers $2 $3 +publishPackage polywrap-uri-resolvers $1 $2 $3 publishResult=$? if [ "$publishResult" -ne "0" ]; then echo "Failed to publish polywrap-uri-resolvers" @@ -316,7 +323,7 @@ if [ "$patchVersionResult" -ne "0" ]; then fi echo "Publishing polywrap-client" -publishPackage polywrap-client $2 $3 +publishPackage polywrap-client $1 $2 $3 publishResult=$? if [ "$publishResult" -ne "0" ]; then echo "Failed to publish polywrap-client"