93 lines
2.2 KiB
Bash
93 lines
2.2 KiB
Bash
#!/bin/sh
|
|
|
|
### whatif (patch|minor|major|alpha|rc|beta)
|
|
whatif() {(
|
|
set -e
|
|
TMPPREFIX=/tmp/tmp.releaser-whatif
|
|
T="$(mktemp -d "${TMPPREFIX}.XXXXXXXX")"
|
|
cleanup() { (set -x;rm -rf "/tmp/${TMPPREFIX#/tmp/}${T#$TMPPREFIX}"); }
|
|
trap "cleanup;exit 1" SIGINT SIGTERM
|
|
git clone . "$T" &> /dev/null
|
|
cargo set-version --manifest-path "$T/Cargo.toml" --bump "$1" &> /dev/null
|
|
tomlq -r .package.version "$T/Cargo.toml"
|
|
rm -rf "/tmp/${TMPPREFIX#/tmp/}${T#$TMPPREFIX}"
|
|
cleanup
|
|
)}
|
|
|
|
if [ $# -eq 0 ];then
|
|
echo "crate releaser:"
|
|
echo
|
|
|
|
printf "% 8s : %s\n" name version
|
|
printf "% 8s : %s\n" -------- --------
|
|
for f in major minor patch rc beta alpha;do
|
|
printf "% 8s : %s\n" $f "$(whatif "$f")"
|
|
done
|
|
|
|
echo "
|
|
Call with any of the above arguments to change this crate's version
|
|
to the associated version:
|
|
|
|
$0 [major|minor|patch|rc|beta|alpha]
|
|
"
|
|
exit 0
|
|
fi
|
|
|
|
BUMP="$1"
|
|
|
|
if [ x"$(git branch --show-current)" != xdev ];then
|
|
1>&2 echo this can only be run from the dev branch
|
|
exit 1
|
|
fi
|
|
|
|
if [ ! -d .git ] || [ ! -f Cargo.toml ];then
|
|
1>&2 echo this can only be run from the root of a rust git repo
|
|
exit 1
|
|
fi
|
|
|
|
if git status --porcelain | grep -q . ;then
|
|
git status || true
|
|
1>&2 echo can only be run on a clean git tree
|
|
exit 1
|
|
fi
|
|
|
|
upgrade() {
|
|
cargo set-version --bump "$BUMP"
|
|
VERSION="$(tomlq -r .package.version Cargo.toml)"
|
|
git add Cargo.toml Cargo.lock
|
|
git commit -m "release $VERSION"
|
|
git merge main
|
|
git checkout main
|
|
git merge dev
|
|
git tag "$VERSION"
|
|
git checkout dev
|
|
cargo set-version --bump alpha
|
|
NEW_VERSION="$(tomlq -r .package.version Cargo.toml)"
|
|
git add Cargo.toml Cargo.lock
|
|
git commit -m "a new version appears: $NEW_VERSION"
|
|
}
|
|
|
|
(
|
|
set -e
|
|
echo "smoke testing the release process first..."
|
|
TMPPREFIX="/tmp/tmp.releaser-testrun"
|
|
T="$(mktemp -d "${TMPPREFIX}.XXXXXXXX")"
|
|
cleanup() { (set -x; rm -rf "/tmp/${TMPPREFIX#/tmp/}${T#$TMPPREFIX}"); }
|
|
trap "cleanup;exit 1" SIGINT SIGTERM
|
|
git clone . "$T"
|
|
cd "$T"
|
|
kill -INT $$
|
|
git checkout main
|
|
git checkout dev
|
|
upgrade "$BUMP"; echo $?
|
|
cleanup
|
|
); RC=$?
|
|
if [ $RC -ne 0 ]; then
|
|
1>&2 echo "smoke test failed. aborting!"
|
|
exit 1
|
|
fi
|
|
|
|
(
|
|
set -e
|
|
upgrade
|
|
) |