-
Notifications
You must be signed in to change notification settings - Fork 165
/
publish-crate.sh
executable file
·89 lines (73 loc) · 2.37 KB
/
publish-crate.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
86
87
88
89
#!/usr/bin/env bash
set -e
cd "$(dirname "$0")/.."
source ci/semver_bash/semver.sh
source ci/rust-version.sh stable
# shellcheck disable=SC2086
is_crate_version_uploaded() {
name=$1
version=$2
curl https://crates.io/api/v1/crates/${name}/${version} | \
python3 -c "import sys,json; print('version' in json.load(sys.stdin));"
}
# Only package/publish if this is a tagged release
[[ -n $CI_TAG ]] || {
echo CI_TAG unset, skipped
exit 0
}
semverParseInto "$CI_TAG" MAJOR MINOR PATCH SPECIAL
expectedCrateVersion="$MAJOR.$MINOR.$PATCH$SPECIAL"
[[ -n "$CRATES_IO_TOKEN" ]] || {
echo CRATES_IO_TOKEN undefined
exit 1
}
# check workspace.version for worksapce root
workspace_cargo_tomls=(Cargo.toml programs/sbf/Cargo.toml)
for cargo_toml in "${workspace_cargo_tomls[@]}"; do
if ! grep -q "^version = \"$expectedCrateVersion\"$" "$cargo_toml"; then
echo "Error: Cargo.toml version is not $expectedCrateVersion"
exit 1
fi
done
Cargo_tomls=$(ci/order-crates-for-publishing.py)
for Cargo_toml in $Cargo_tomls; do
echo "--- $Cargo_toml"
# check the version which doesn't inherit from worksapce
if ! grep -q "^version = { workspace = true }$" "$Cargo_toml"; then
echo "Warn: $Cargo_toml doesn't use the inherited version"
grep -q "^version = \"$expectedCrateVersion\"$" "$Cargo_toml" || {
echo "Error: $Cargo_toml version is not $expectedCrateVersion"
exit 1
}
fi
crate_name=$(grep -m 1 '^name = ' "$Cargo_toml" | cut -f 3 -d ' ' | tr -d \")
if grep -q "^publish = false" "$Cargo_toml"; then
echo "$crate_name is marked as unpublishable"
continue
fi
if [[ $(is_crate_version_uploaded "$crate_name" "$expectedCrateVersion") = True ]] ; then
echo "${crate_name} version ${expectedCrateVersion} is already on crates.io"
continue
fi
(
set -x
crate=$(dirname "$Cargo_toml")
cargoCommand="cargo publish --token $CRATES_IO_TOKEN"
numRetries=10
for ((i = 1; i <= numRetries; i++)); do
echo "Attempt ${i} of ${numRetries}"
# The rocksdb package does not build with the stock rust docker image so use
# the solana rust docker image
if ci/docker-run-default-image.sh bash -exc "cd $crate; $cargoCommand"; then
break
fi
if [ "$i" -lt "$numRetries" ]; then
sleep 3
else
echo "couldn't publish '$crate_name'"
exit 1
fi
done
)
done
exit 0