-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
103 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#!/bin/sh | ||
|
||
# USAGE: | ||
# ./scripts/cargo-publish.sh <crate-dir> [--dry-run] | ||
# | ||
# if --dry-run is provided, the script runs cargo publish --dry-run, | ||
# otherwise it performs a real publish. | ||
# | ||
# the script returns 0 on success of cargo publish, and 1 on failure | ||
# the only exception is when cargo publish fails because the crate is already published | ||
# in that case, the script also returns 0 | ||
|
||
CRATE_DIR="$1" | ||
DRY_FLAG="${2:-}" | ||
|
||
echo "Publishing crate in directory: $CRATE_DIR" | ||
|
||
cd "$CRATE_DIR" | ||
|
||
if [ "$DRY_FLAG" = "--dry-run" ]; then | ||
echo "Dry run enabled. Will not actually publish to crates.io." | ||
CARGO_COMMAND="cargo publish --dry-run" | ||
else | ||
CARGO_COMMAND="cargo publish" | ||
fi | ||
|
||
OUTPUT="$($CARGO_COMMAND 2>&1)" | ||
EXIT_CODE=$? | ||
echo "Ran cargo command, exit code was $EXIT_CODE" | ||
|
||
if [ "$DRY_FLAG" = "--dry-run" ]; then | ||
if [ "$EXIT_CODE" -eq 0 ]; then | ||
echo "Dry-run succeeded; nothing was actually published." | ||
exit 0 | ||
fi | ||
# If it failed under --dry-run, handle error or log accordingly: | ||
echo "Dry-run failed for $CRATE_DIR." | ||
echo "$OUTPUT" | ||
exit 1 | ||
fi | ||
|
||
if [ "$EXIT_CODE" -eq 0 ] ; then | ||
echo "Publish command succeeded: $CRATE_DIR" | ||
exit 0 | ||
fi | ||
|
||
# If cargo failed, check whether it was 'already uploaded' | ||
if echo "$OUTPUT" | grep -q "already uploaded"; then | ||
echo "Crate is already published: $CRATE_DIR" | ||
exit 0 | ||
fi | ||
|
||
echo "Publish command failed for $CRATE_DIR" | ||
echo "$OUTPUT" | ||
exit 1 |