Skip to content

Commit c056be4

Browse files
tomusdrwdvdplm
andauthored
Allow skipping and retrying publishing. (#557)
* Allow skipping and retrying publishing. * Update _automate/publish.sh Co-authored-by: David <dvdplm@gmail.com> * Even more idempotenter. * Apply suggestions from code review Co-authored-by: David <dvdplm@gmail.com> * Fetch tags before creating. * Replace main with jsonrpc Co-authored-by: David <dvdplm@gmail.com>
1 parent dfa6b98 commit c056be4

File tree

1 file changed

+88
-27
lines changed

1 file changed

+88
-27
lines changed

_automate/publish.sh

Lines changed: 88 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,22 @@ set -eu
44

55
ORDER=(core server-utils tcp ws http ipc stdio pubsub core-client/transports core-client derive test)
66

7-
# First display the plan
8-
for crate in ${ORDER[@]}; do
9-
cd $crate > /dev/null
7+
function read_toml () {
8+
NAME=""
9+
VERSION=""
10+
NAME=$(grep "^name" ./Cargo.toml | sed -e 's/.*"\(.*\)"/\1/')
1011
VERSION=$(grep "^version" ./Cargo.toml | sed -e 's/.*"\(.*\)"/\1/')
11-
echo "$crate@$VERSION"
12+
}
13+
function remote_version () {
14+
REMOTE_VERSION=""
15+
REMOTE_VERSION=$(cargo search "$NAME" | grep "^$NAME =" | sed -e 's/.*"\(.*\)".*/\1/')
16+
}
17+
18+
# First display the plan
19+
for CRATE_DIR in ${ORDER[@]}; do
20+
cd $CRATE_DIR > /dev/null
21+
read_toml
22+
echo "$NAME@$VERSION"
1223
cd - > /dev/null
1324
done
1425

@@ -18,37 +29,87 @@ set -x
1829

1930
cargo clean
2031

32+
set +x
33+
2134
# Then actually perform publishing.
22-
for crate in ${ORDER[@]}; do
23-
cd $crate
24-
VERSION=$(grep "^version" ./Cargo.toml | sed -e 's/.*"\(.*\)"/\1/')
25-
echo "Publishing $crate@$VERSION"
26-
sleep 5 # give the user an opportunity to abort before publishing
27-
cargo publish $@ || read -p ">>>>> Publishing $crate failed. Press [enter] to continue. "
28-
echo " Waiting for published version $VERSION to be available..."
29-
CRATE_NAME=$(grep "^name" ./Cargo.toml | sed -e 's/.*"\(.*\)"/\1/')
30-
LATEST_VERSION=0
31-
while [[ $LATEST_VERSION != $VERSION ]]
32-
do
33-
sleep 3
34-
LATEST_VERSION=$(cargo search "$CRATE_NAME" | grep "^$CRATE_NAME =" | sed -e 's/.*"\(.*\)".*/\1/')
35-
echo " Latest available version: $LATEST_VERSION"
35+
for CRATE_DIR in ${ORDER[@]}; do
36+
cd $CRATE_DIR > /dev/null
37+
read_toml
38+
remote_version
39+
# Seems the latest version matches, skip by default.
40+
if [ "$REMOTE_VERSION" = "$VERSION" ] || [[ "$REMOTE_VERSION" > "$VERSION" ]]; then
41+
RET=""
42+
echo "Seems like $NAME@$REMOTE_VERSION is already published. Continuing in 5s. "
43+
read -t 5 -p ">>>> Type [r][enter] to retry, or [enter] to continue... " RET || true
44+
if [ "$RET" != "r" ]; then
45+
echo "Skipping $NAME@$VERSION"
46+
cd - > /dev/null
47+
continue
48+
fi
49+
fi
50+
51+
# Attempt to publish (allow retries)
52+
while : ; do
53+
# give the user an opportunity to abort or skip before publishing
54+
echo "🚀 Publishing $NAME@$VERSION..."
55+
sleep 3
56+
57+
set +e && set -x
58+
cargo publish $@
59+
RES=$?
60+
set +x && set -e
61+
# Check if it succeeded
62+
if [ "$RES" != "0" ]; then
63+
CHOICE=""
64+
echo "##### Publishing $NAME failed"
65+
read -p ">>>>> Type [s][enter] to skip, or [enter] to retry.. " CHOICE
66+
if [ "$CHOICE" = "s" ]; then
67+
break
68+
fi
69+
fi
70+
done
71+
72+
# Wait again to make sure that the new version is published and available.
73+
echo "Waiting for $NAME@$VERSION to become available at the registry..."
74+
while : ; do
75+
sleep 3
76+
remote_version
77+
if [ "$REMOTE_VERSION" = "$VERSION" ]; then
78+
echo "🥳 $NAME@$VERSION published succesfully."
79+
sleep 3
80+
break
81+
else
82+
echo "#### Got $NAME@$REMOTE_VERSION but expected $NAME@$VERSION. Retrying..."
83+
fi
3684
done
37-
cd -
85+
cd - > /dev/null
3886
done
3987

4088
# Make tags in one go
41-
for crate in ${ORDER[@]}; do
42-
cd $crate
43-
VERSION=$(grep "^version" ./Cargo.toml | sed -e 's/.*"\(.*\)"/\1/')
44-
echo "Tagging $crate@$VERSION"
45-
git tag -a "$crate-$VERSION" -m "$crate $VERSION" || true
46-
cd -
89+
set -x
90+
git fetch --tags
91+
set +x
92+
93+
for CRATE_DIR in ${ORDER[@]}; do
94+
cd $CRATE_DIR > /dev/null
95+
read_toml
96+
echo "Tagging $NAME@$VERSION"
97+
set -x
98+
git tag -a "$NAME-$VERSION" -m "$NAME $VERSION" || true
99+
set +x
100+
cd - > /dev/null
47101
done
48102

103+
set -x
104+
sleep 3
49105
git push --tags
106+
set +x
50107

51-
VERSION=$(grep "^version" ./core/Cargo.toml | sed -e 's/.*"\(.*\)"/\1/')
52-
echo "Tagging main $VERSION"
108+
cd core > /dev/null
109+
read_toml
110+
cd - > /dev/null
111+
echo "Tagging jsonrpc@$VERSION"
112+
set -x
53113
git tag -a v$VERSION -m "Version $VERSION"
114+
sleep 3
54115
git push --tags

0 commit comments

Comments
 (0)