-
Notifications
You must be signed in to change notification settings - Fork 176
/
Copy pathpublish.sh
executable file
·85 lines (72 loc) · 2.04 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
#!/usr/bin/env bash
#
# This script is copied from `https://github.com/paritytech/jsonrpc` with some minor tweaks.
# Add `--dry-run` and/or `--allow-dirty` to your command line to test things before publication.
set -eu
ORDER=(types proc-macros core client/http-client client/transport client/ws-client client/wasm-client server jsonrpsee)
DIR=$(pwd)
function read_toml () {
NAME=""
VERSION=""
NAME=$(grep "^name" ./Cargo.toml | sed -e 's/.*"\(.*\)"/\1/')
VERSION=$(grep "^version" $DIR/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
cd - > /dev/null
done
echo "Tagging jsonrpsee@$VERSION"
set -x
git tag -a -s v$VERSION -m "Version $VERSION"
sleep 3
git push --tags