From 523534464f1813e7fe32e6165cad0b23200208df Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Wed, 23 Nov 2022 12:30:13 +0100 Subject: [PATCH] Add and adapt a publish.sh utility script from jsonrpsee (#723) * refactor: Explicitly indicate which crates should be published * chore: Add a convenience publish.sh script * Update scripts/publish.sh Co-authored-by: Niklas Adolfsson * Update scripts/publish.sh Co-authored-by: Niklas Adolfsson * fix: Don't use unsupported -P flag in BSD grep in publish.sh Co-authored-by: Niklas Adolfsson --- cli/Cargo.toml | 1 + codegen/Cargo.toml | 1 + macro/Cargo.toml | 1 + metadata/Cargo.toml | 1 + scripts/publish.sh | 100 +++++++++++++++++++++++++++ subxt/Cargo.toml | 1 + testing/integration-tests/Cargo.toml | 1 + testing/test-runtime/Cargo.toml | 1 + testing/ui-tests/Cargo.toml | 1 + testing/wasm-tests/Cargo.toml | 1 + 10 files changed, 109 insertions(+) create mode 100755 scripts/publish.sh diff --git a/cli/Cargo.toml b/cli/Cargo.toml index d0c934fc03..9a9b1b527a 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -3,6 +3,7 @@ name = "subxt-cli" version = "0.25.0" authors = ["Parity Technologies "] edition = "2021" +publish = true license = "Apache-2.0 OR GPL-3.0" repository = "https://github.com/paritytech/subxt" diff --git a/codegen/Cargo.toml b/codegen/Cargo.toml index 04ffc54a7e..c906ec1d26 100644 --- a/codegen/Cargo.toml +++ b/codegen/Cargo.toml @@ -3,6 +3,7 @@ name = "subxt-codegen" version = "0.25.0" authors = ["Parity Technologies "] edition = "2021" +publish = true license = "Apache-2.0 OR GPL-3.0" repository = "https://github.com/paritytech/subxt" diff --git a/macro/Cargo.toml b/macro/Cargo.toml index 4a4eaaf9fe..098503efcf 100644 --- a/macro/Cargo.toml +++ b/macro/Cargo.toml @@ -3,6 +3,7 @@ name = "subxt-macro" version = "0.25.0" authors = ["Parity Technologies "] edition = "2021" +publish = true autotests = false license = "Apache-2.0 OR GPL-3.0" diff --git a/metadata/Cargo.toml b/metadata/Cargo.toml index ca10bf1201..74492aa595 100644 --- a/metadata/Cargo.toml +++ b/metadata/Cargo.toml @@ -3,6 +3,7 @@ name = "subxt-metadata" version = "0.25.0" authors = ["Parity Technologies "] edition = "2021" +publish = true autotests = false license = "Apache-2.0 OR GPL-3.0" diff --git a/scripts/publish.sh b/scripts/publish.sh new file mode 100755 index 0000000000..a127e4196f --- /dev/null +++ b/scripts/publish.sh @@ -0,0 +1,100 @@ +#!/usr/bin/env bash +# +# This script is copied from `https://github.com/paritytech/jsonrpsee` with some minor tweaks. +# Add `--dry-run` and/or `--allow-dirty` to your command line to test things before publication. + +set -eu + +# Find publishable crates by running something like this below and figure out the topological order: +# $ find . -iname 'Cargo.toml' | xargs grep "publish\ *=\ *true" | grep "^.*\.toml" -o +ORDER=(metadata codegen macro subxt cli) + +function read_toml () { + NAME="" + VERSION="" + # Extract and parse the "name = ..." line that belongs to the [package] section + NAME=$(grep -e "\[package\]" -e 'name*=*' ./Cargo.toml | grep -A1 "\[package\]" | tail -n 1 | sed -e 's/.*"\(.*\)"/\1/') + VERSION=$(grep "^version" ./Cargo.toml | sed -e 's/.*"\(.*\)"/\1/') +} +function remote_version () { + REMOTE_VERSION="" + REMOTE_VERSION=$(cargo search "$NAME" | grep "^$NAME =" | sed -e 's/.*"\(.*\)".*/\1/') +} + +# First display the plan +for CRATE_DIR in ${ORDER[@]}; do + cd $CRATE_DIR > /dev/null + read_toml + echo "$NAME@$VERSION" + cd - > /dev/null +done + +read -p ">>>> Really publish?. Press [enter] to continue. " + +set -x + +cargo clean + +set +x + +# Then actually perform publishing. +for CRATE_DIR in ${ORDER[@]}; do + cd $CRATE_DIR > /dev/null + read_toml + remote_version + # Seems the latest version matches, skip by default. + if [ "$REMOTE_VERSION" = "$VERSION" ] || [[ "$REMOTE_VERSION" > "$VERSION" ]]; then + RET="" + echo "Seems like $NAME@$REMOTE_VERSION is already published. Continuing in 5s. " + read -t 5 -p ">>>> Type [r][enter] to retry, or [enter] to continue... " RET || true + if [ "$RET" != "r" ]; then + echo "Skipping $NAME@$VERSION" + cd - > /dev/null + continue + fi + fi + + # Attempt to publish (allow retries) + while : ; do + # give the user an opportunity to abort or skip before publishing + echo "🚀 Publishing $NAME@$VERSION..." + sleep 3 + + set +e && set -x + cargo publish $@ + RES=$? + set +x && set -e + # Check if it succeeded + if [ "$RES" != "0" ]; then + CHOICE="" + echo "##### Publishing $NAME failed" + read -p ">>>>> Type [s][enter] to skip, or [enter] to retry.. " CHOICE + if [ "$CHOICE" = "s" ]; then + break + fi + else + break + fi + done + + # Wait again to make sure that the new version is published and available. + echo "Waiting for $NAME@$VERSION to become available at the registry..." + while : ; do + sleep 3 + remote_version + if [ "$REMOTE_VERSION" = "$VERSION" ]; then + echo "🥳 $NAME@$VERSION published succesfully." + sleep 3 + break + else + echo "#### Got $NAME@$REMOTE_VERSION but expected $NAME@$VERSION. Retrying..." + fi + done + cd - > /dev/null +done + +echo "Tagging subxt@$VERSION" +set -x +git tag -s -a v$VERSION -m "Version $VERSION" +sleep 3 +git push --tags diff --git a/subxt/Cargo.toml b/subxt/Cargo.toml index cf7c02fd41..f340c01df2 100644 --- a/subxt/Cargo.toml +++ b/subxt/Cargo.toml @@ -3,6 +3,7 @@ name = "subxt" version = "0.25.0" authors = ["Parity Technologies "] edition = "2021" +publish = true license = "Apache-2.0 OR GPL-3.0" readme = "../README.md" diff --git a/testing/integration-tests/Cargo.toml b/testing/integration-tests/Cargo.toml index 98632016a6..9c76615974 100644 --- a/testing/integration-tests/Cargo.toml +++ b/testing/integration-tests/Cargo.toml @@ -3,6 +3,7 @@ name = "integration-tests" version = "0.25.0" authors = ["Parity Technologies "] edition = "2021" +publish = false license = "Apache-2.0 OR GPL-3.0" readme = "../README.md" diff --git a/testing/test-runtime/Cargo.toml b/testing/test-runtime/Cargo.toml index a738f0cc89..ae32e25e6d 100644 --- a/testing/test-runtime/Cargo.toml +++ b/testing/test-runtime/Cargo.toml @@ -2,6 +2,7 @@ name = "test-runtime" version = "0.25.0" edition = "2021" +publish = false [dependencies] subxt = { path = "../../subxt" } diff --git a/testing/ui-tests/Cargo.toml b/testing/ui-tests/Cargo.toml index f3f6696573..b544d1f509 100644 --- a/testing/ui-tests/Cargo.toml +++ b/testing/ui-tests/Cargo.toml @@ -2,6 +2,7 @@ name = "ui-tests" version = "0.25.0" edition = "2021" +publish = false # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/testing/wasm-tests/Cargo.toml b/testing/wasm-tests/Cargo.toml index d539bebb87..48c60ec44c 100644 --- a/testing/wasm-tests/Cargo.toml +++ b/testing/wasm-tests/Cargo.toml @@ -2,6 +2,7 @@ name = "wasm-test" version = "0.1.0" edition = "2021" +publish = false [dev-dependencies] wasm-bindgen-test = "0.3.24"