-
Notifications
You must be signed in to change notification settings - Fork 0
/
publish
executable file
·38 lines (30 loc) · 1.31 KB
/
publish
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
#! /bin/bash
echo "Releasing to crates.io:"
echo -en " Checking git status..."
git status -s | grep -E ' M |\?\?' &&
echo " BAILING OUT: git is not clean -- commit and push pending changes before running this command" &&
exit 1
echo " OK"
echo -en " Getting unpublished version stated in Cargo.tom..."
UNPUBLISHED_VERSION=`grep --max-count 1 version Cargo.toml | sed 's|[^"]*"\(.*\)"|\1|'`
echo " ${UNPUBLISHED_VERSION} OK"
echo -en " Publishing to crates.io:"
cargo publish || exit 1
echo -en " Pushing new tag to git..."
git tag -a "${UNPUBLISHED_VERSION}" -m "as released to crates.io" &&
git push origin --tags &&
echo " OK" || echo " FAILED"
echo -en " Preparing Cargo.toml for next version..."
V_PREFIX=`echo ${UNPUBLISHED_VERSION} | sed "s|\(.*\.\)\(.*\)|\1|"`
V_SUFFIX=`echo ${UNPUBLISHED_VERSION} | sed "s|\(.*\.\)\(.*\)|\2|"`
NEXT_V_SUFFIX=$((V_SUFFIX+1))
NEXT_VERSION="${V_PREFIX}${NEXT_V_SUFFIX}"
echo -en " from ${UNPUBLISHED_VERSION} to ${NEXT_VERSION}..."
sed -i "s|version\( *\)= \"${UNPUBLISHED_VERSION}\"|version\1= \"${NEXT_VERSION}\"|" Cargo.toml &&
echo " OK" || echo " FAILED"
echo -en " Committing & pushing Cargo.toml new version change..."
git add Cargo.toml &&
git commit -m "crate's next version after publishing to crates.io" &&
git push &&
echo " OK" || echo " FAILED"
echo "DONE"