lighthouse-pulse/scripts/ci/publish.sh
realbigsean 50321c6671 Updates to make crates publishable (#2472)
## Issue Addressed

Related to: #2259

Made an attempt at all the necessary updates here to publish the crates to crates.io. I incremented the minor versions on all the crates that have been previously published. We still might run into some issues as we try to publish because I'm not able to test this out but I think it's a good starting point.

## Proposed Changes

- Add description and license to `ssz_types` and `serde_util`
- rename `serde_util` to `eth2_serde_util`
- increment minor versions
- remove path dependencies
- remove patch dependencies 

## Additional Info
Crates published: 

- [x] `tree_hash` -- need to publish `tree_hash_derive` and `eth2_hashing` first
- [x] `eth2_ssz_types` -- need to publish `eth2_serde_util` first
- [x] `tree_hash_derive`
- [x] `eth2_ssz`
- [x] `eth2_ssz_derive`
- [x] `eth2_serde_util`
- [x] `eth2_hashing`


Co-authored-by: realbigsean <seananderson33@gmail.com>
2021-09-03 01:10:25 +00:00

110 lines
2.3 KiB
Bash
Executable File

#!/usr/bin/env bash
# Based on: https://github.com/tokio-rs/tokio/blob/master/bin/publish
set -e
USAGE="Publish a new release of a lighthouse crate
USAGE:
$(basename "$0") [OPTIONS] [CRATE_PATH] [CRATE] [TAG]
OPTIONS:
-v, --verbose Use verbose Cargo output
-d, --dry-run Perform a dry run (do not publish the release)
-h, --help Show this help text and exit
--allow-dirty Allow dirty working directories to be packaged"
DRY_RUN=""
DIRTY=""
VERBOSE=""
verify() {
echo "Verifying if $CRATE v$VERSION can be released"
# `cargo pkgid` has different formats based on whether the `[lib]` name and `[package]` name
# are the same, necessitating the following logic.
#
# Try to match on `#`
ACTUAL=$(cargo pkgid | sed -n 's/.*#\([0-9]\)/\1/p' )
if [ -z "$ACTUAL" ]; then
# Match on the final `:`
ACTUAL=$(cargo pkgid | sed -n 's/.*:\(.*\)/\1/p')
fi
if [ "$ACTUAL" != "$VERSION" ]; then
echo "expected to release version $VERSION, but Cargo.toml contained $ACTUAL"
exit 1
fi
}
release() {
echo "Releasing $CRATE v$VERSION"
cargo package $VERBOSE $DIRTY
cargo publish $VERBOSE $DRY_RUN $DIRTY
}
while [[ $# -gt 0 ]]
do
case "$1" in
-h|--help)
echo "$USAGE"
exit 0
;;
-v|--verbose)
VERBOSE="--verbose"
set +x
shift
;;
--allow-dirty)
DIRTY="--allow-dirty"
shift
;;
-d|--dry-run)
DRY_RUN="--dry-run"
shift
;;
-*)
echo "unknown flag \"$1\""
echo "$USAGE"
exit 1
;;
*) # crate, crate path, or version
if [ -z "$CRATE_PATH" ]; then
CRATE_PATH="$1"
elif [ -z "$CRATE" ]; then
CRATE="$1"
elif [ -z "$TAG" ]; then
TAG="$1"
VERSION=$(sed -e 's#.*-v\([0-9]\)#\1#' <<< "$TAG")
else
echo "unknown positional argument \"$1\""
echo "$USAGE"
exit 1
fi
shift
;;
esac
done
# set -- "${POSITIONAL[@]}"
if [ -z "$VERSION" ]; then
echo "no version specified!"
HELP=1
fi
if [ -z "$CRATE" ]; then
echo "no crate specified!"
HELP=1
fi
if [ -n "$HELP" ]; then
echo "$USAGE"
exit 1
fi
if [ -d "$CRATE_PATH" ]; then
(cd "$CRATE_PATH" && verify && release )
else
echo "no such dir \"$CRATE_PATH\""
exit 1
fi