-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathpublish-crates.sh
executable file
·78 lines (61 loc) · 1.85 KB
/
publish-crates.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
#!/usr/bin/env bash
set -eu
# Read in PUBLISH_CRATES var
source $(dirname -- ${BASH_SOURCE[0]})/publish-list
LOOP_AGAIN=false
ATTEMPTS=1
CRATES_UPLOADED=0
readonly MAX_ATTEMPTS=3
readonly VERBOSE=${VERBOSE:-false}
readonly CARGO_OUTPUT_TMP=$(mktemp)
function check_if_crate_uploaded() {
local CRATE=$1;
# Check for whether the crate was already uploaded to determine if we're good to move forward
tail -1 "$CARGO_OUTPUT_TMP" | grep "already uploaded" > /dev/null
# If exit code from `grep` is 0
if [[ ${PIPESTATUS[1]} != 0 ]];
then
echo "$CRATE upload check failed. Will try again"
LOOP_AGAIN=true;
fi
}
function cargo_publish_all() {
# We want to loop though each of the crates and attempt to publish.
if [[ $ATTEMPTS -lt $((MAX_ATTEMPTS + 1)) ]];
then
for crate in "${PUBLISH_CRATES[@]}" ; do
echo "$crate";
# Save the `cargo publish` in case we get a non-zero exit
cargo publish -p $crate 2>&1 | tee "$CARGO_OUTPUT_TMP"
result="${PIPESTATUS[0]}";
# cargo publish exit codes:
if [[ "$result" != 0 ]];
then
check_if_crate_uploaded "$crate";
else
CRATES_UPLOADED=$((CRATES_UPLOADED+1));
fi
done
else
echo "❌ Max number of publish attempts reached"
echo "❌ Max attempts: $MAX_ATTEMPTS"
exit 1
fi
}
function main() {
if [[ $VERBOSE != false ]];
then
echo "VERBOSE MODE ON"
set -x
fi
while cargo_publish_all; [[ $LOOP_AGAIN = true ]];
do
# Reset the loop flag
LOOP_AGAIN=false;
# Increment the attempts counter
ATTEMPTS=$((ATTEMPTS+1));
done
echo "✅ Publish success after # Attempts: $ATTEMPTS"
echo "✅ Crates uploaded: $CRATES_UPLOADED"
}
main;