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
|
|
|
|
}
|
|
|
|
|
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"
|
2019-05-30 11:53:41 -07:00
|
|
|
grep -q "^version = \"$expectedCrateVersion\"$" "$Cargo_toml" || {
|
|
|
|
echo "Error: $Cargo_toml version is not $expectedCrateVersion"
|
2019-03-20 20:30:44 -07:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
echo "$crate_name is is marked as unpublishable"
|
|
|
|
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
|
2019-05-30 11:53:41 -07:00
|
|
|
crate=$(dirname "$Cargo_toml")
|
2019-01-07 21:46:55 -08:00
|
|
|
# TODO: the rocksdb package does not build with the stock rust docker image,
|
|
|
|
# so use the solana rust docker image until this is resolved upstream
|
2019-07-18 21:19:07 -07:00
|
|
|
cargoCommand="cargo publish --token $CRATES_IO_TOKEN"
|
2019-03-14 19:41:05 -07:00
|
|
|
ci/docker-run.sh "$rust_stable_docker_image" bash -exc "cd $crate; $cargoCommand"
|
2019-05-30 11:53:41 -07:00
|
|
|
) || true # <-- Don't fail. We want to be able to retry the job in cases when a publish fails halfway due to network/cloud issues
|
2019-06-03 18:54:41 -07:00
|
|
|
|
|
|
|
numRetries=30
|
|
|
|
for ((i = 1 ; i <= numRetries ; i++)); do
|
|
|
|
echo "Attempt ${i} of ${numRetries}"
|
2019-07-12 21:36:01 -07:00
|
|
|
if [[ $(is_crate_version_uploaded "$crate_name" "$expectedCrateVersion") = True ]] ; then
|
2019-07-16 19:09:49 -07:00
|
|
|
echo "Found ${crate_name} version ${expectedCrateVersion} on crates.io REST API"
|
|
|
|
|
|
|
|
really_uploaded=0
|
|
|
|
(
|
|
|
|
set -x
|
|
|
|
rm -rf crate-test
|
2019-07-18 21:19:07 -07:00
|
|
|
cargo +"$rust_stable" init crate-test
|
2019-07-16 19:09:49 -07:00
|
|
|
cd crate-test/
|
|
|
|
echo "${crate_name} = \"${expectedCrateVersion}\"" >> Cargo.toml
|
|
|
|
echo "[workspace]" >> Cargo.toml
|
2019-07-18 21:19:07 -07:00
|
|
|
cargo +"$rust_stable" check
|
2019-07-16 19:09:49 -07:00
|
|
|
) && really_uploaded=1
|
|
|
|
if ((really_uploaded)); then
|
|
|
|
break;
|
|
|
|
fi
|
|
|
|
echo "${crate_name} not yet available for download from crates.io"
|
2019-06-03 18:54:41 -07:00
|
|
|
fi
|
|
|
|
echo "Did not find ${crate_name} version ${expectedCrateVersion} on crates.io. Sleeping for 2 seconds."
|
|
|
|
sleep 2
|
|
|
|
done
|
2018-10-25 12:26:57 -07:00
|
|
|
done
|
2018-05-21 23:02:54 -07:00
|
|
|
|
|
|
|
exit 0
|