2018-11-11 08:19:04 -08:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -e
|
2018-05-27 18:19:07 -07:00
|
|
|
cd "$(dirname "$0")/.."
|
2019-03-20 20:30:44 -07:00
|
|
|
source ci/semver_bash/semver.sh
|
2019-07-18 21:19:07 -07:00
|
|
|
source ci/rust-version.sh stable
|
2018-05-21 23:02:54 -07:00
|
|
|
|
2019-06-03 18:54:41 -07:00
|
|
|
# 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));"
|
|
|
|
}
|
|
|
|
|
2018-12-11 22:38:55 -08:00
|
|
|
# Only package/publish if this is a tagged release
|
2019-06-06 12:20:47 -07:00
|
|
|
[[ -n $CI_TAG ]] || {
|
|
|
|
echo CI_TAG unset, skipped
|
2019-01-09 09:28:19 -08:00
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
2019-06-06 12:20:47 -07:00
|
|
|
semverParseInto "$CI_TAG" MAJOR MINOR PATCH SPECIAL
|
2019-03-20 20:30:44 -07:00
|
|
|
expectedCrateVersion="$MAJOR.$MINOR.$PATCH$SPECIAL"
|
|
|
|
|
2019-01-09 09:28:19 -08:00
|
|
|
[[ -n "$CRATES_IO_TOKEN" ]] || {
|
|
|
|
echo CRATES_IO_TOKEN undefined
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2023-05-31 23:28:10 -07:00
|
|
|
# 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
|
|
|
|
|
2019-05-30 11:53:41 -07:00
|
|
|
Cargo_tomls=$(ci/order-crates-for-publishing.py)
|
|
|
|
|
2019-05-30 13:44:27 -07:00
|
|
|
for Cargo_toml in $Cargo_tomls; do
|
2019-07-16 07:27:17 -07:00
|
|
|
echo "--- $Cargo_toml"
|
2023-05-31 23:28:10 -07:00
|
|
|
|
|
|
|
# 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
|
2019-03-20 20:30:44 -07:00
|
|
|
|
2019-07-12 21:36:01 -07:00
|
|
|
crate_name=$(grep -m 1 '^name = ' "$Cargo_toml" | cut -f 3 -d ' ' | tr -d \")
|
|
|
|
|
2019-07-12 21:50:50 -07:00
|
|
|
if grep -q "^publish = false" "$Cargo_toml"; then
|
2020-09-24 00:53:30 -07:00
|
|
|
echo "$crate_name is marked as unpublishable"
|
2019-07-12 21:50:50 -07:00
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
2019-07-12 21:36:01 -07:00
|
|
|
if [[ $(is_crate_version_uploaded "$crate_name" "$expectedCrateVersion") = True ]] ; then
|
|
|
|
echo "${crate_name} version ${expectedCrateVersion} is already on crates.io"
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
2018-10-25 12:26:57 -07:00
|
|
|
(
|
|
|
|
set -x
|
2024-01-21 18:43:21 -08:00
|
|
|
|
2019-05-30 11:53:41 -07:00
|
|
|
crate=$(dirname "$Cargo_toml")
|
2019-07-18 21:19:07 -07:00
|
|
|
cargoCommand="cargo publish --token $CRATES_IO_TOKEN"
|
2024-01-21 18:43:21 -08:00
|
|
|
|
|
|
|
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
|
2024-02-06 23:17:33 -08:00
|
|
|
if ci/docker-run-default-image.sh bash -exc "cd $crate; $cargoCommand"; then
|
2024-01-21 18:43:21 -08:00
|
|
|
break
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$i" -lt "$numRetries" ]; then
|
|
|
|
sleep 3
|
|
|
|
else
|
|
|
|
echo "couldn't publish '$crate_name'"
|
|
|
|
exit 1
|
2019-07-16 19:09:49 -07:00
|
|
|
fi
|
2024-01-21 18:43:21 -08:00
|
|
|
done
|
|
|
|
)
|
2018-10-25 12:26:57 -07:00
|
|
|
done
|
2018-05-21 23:02:54 -07:00
|
|
|
|
|
|
|
exit 0
|