2021-06-21 08:03:10 +10:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
# Fail if any command fails
|
|
|
|
set -e
|
|
|
|
|
|
|
|
PROJECT=$1
|
|
|
|
VERSION=$2
|
2021-08-16 08:15:25 +10:00
|
|
|
NO_COMMIT=$3
|
2021-06-21 08:03:10 +10:00
|
|
|
|
|
|
|
# Sanity check that we actually have a version
|
|
|
|
if [ "$VERSION" = "" ]; then
|
2021-08-16 08:15:25 +10:00
|
|
|
echo "Usage $0 <project> <version> [--no-commit]"
|
2021-06-21 08:03:10 +10:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-06-21 08:07:06 +10:00
|
|
|
# Check the format of version
|
2021-06-21 08:07:47 +10:00
|
|
|
if [ ! "$(echo "$VERSION" | grep -E "^[0-9]+\.[0-9]+\.[0-9]+$")" ]; then
|
|
|
|
echo "Version must be of the form x.y.z, got $VERSION"
|
2021-06-21 08:07:06 +10:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-08-16 08:15:25 +10:00
|
|
|
# Check if no commit option is valid
|
2021-08-16 08:16:30 +10:00
|
|
|
if [ ! "$NO_COMMIT" = "" ] && [ ! "$NO_COMMIT" = "--no-commit" ]; then
|
2021-08-16 08:15:25 +10:00
|
|
|
echo "Must pass either no last argument or --no-commit"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-06-21 08:03:10 +10:00
|
|
|
# Set up $DIRECTORY and $TAGNAME
|
|
|
|
case "$PROJECT" in
|
|
|
|
agb)
|
|
|
|
DIRECTORY="agb"
|
|
|
|
TAGNAME="v$VERSION"
|
|
|
|
;;
|
|
|
|
agb-image-converter)
|
|
|
|
DIRECTORY="agb-image-converter"
|
|
|
|
TAGNAME="agb-image-converter/v$VERSION"
|
|
|
|
;;
|
2021-10-19 06:24:52 +11:00
|
|
|
agb-sound-converter)
|
|
|
|
DIRECTORY="agb-sound-converter"
|
|
|
|
TAGNAME="agb-sound-converter/v$VERSION"
|
|
|
|
;;
|
2021-08-16 05:40:48 +10:00
|
|
|
agb-macros)
|
|
|
|
DIRECTORY="agb-macros"
|
|
|
|
TAGNAME="agb-macros/v$VERSION"
|
2021-08-08 01:43:50 +10:00
|
|
|
;;
|
2021-06-21 08:03:10 +10:00
|
|
|
mgba-test-runner)
|
|
|
|
DIRECTORY="mgba-test-runner"
|
|
|
|
TAGNAME="mgba-test-runner/v$VERSION"
|
|
|
|
;;
|
|
|
|
|
|
|
|
*)
|
|
|
|
echo "Unknown project name $PROJECT"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
# Check that no out-standing changes in git
|
|
|
|
if [ ! -z "$(git status --porcelain)" ]; then
|
|
|
|
echo "Uncommitted changes, please commit first"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-08-16 08:15:25 +10:00
|
|
|
# Check that we are in the master branch, but only if actually committing
|
|
|
|
if [ ! "$NO_COMMIT" = "--no-commit" ] && [ "$(git symbolic-ref --short HEAD)" != "master" ]; then
|
2021-06-21 08:04:56 +10:00
|
|
|
echo "You must be in the master branch before releasing"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-06-21 08:03:10 +10:00
|
|
|
# Update the version in Cargo.toml
|
2021-06-21 08:14:17 +10:00
|
|
|
sed -i -e "s/^version = \".*\"/version = \"$VERSION\"/" "$DIRECTORY/Cargo.toml"
|
2021-06-21 08:03:10 +10:00
|
|
|
|
|
|
|
# Also update the lock file
|
|
|
|
(cd "$DIRECTORY" && cargo update)
|
2021-06-21 08:48:46 +10:00
|
|
|
git add "$DIRECTORY/Cargo.toml" "$DIRECTORY/Cargo.lock"
|
2021-06-21 08:03:10 +10:00
|
|
|
|
|
|
|
if [ "$PROJECT" = "agb" ]; then
|
|
|
|
# also update the agb version in the template
|
2021-06-21 08:14:17 +10:00
|
|
|
sed -i -e "s/^agb = \".*\"/agb = \"$VERSION\"/" template/Cargo.toml
|
2021-06-21 08:03:10 +10:00
|
|
|
git add template/Cargo.toml
|
2021-08-16 08:12:18 +10:00
|
|
|
else
|
2021-08-16 08:18:55 +10:00
|
|
|
PROJECT_NAME_WITH_UNDERSCORES=$(echo -n "$PROJECT" | tr - _)
|
2021-08-16 08:12:18 +10:00
|
|
|
sed -i -E -e "s/($PROJECT_NAME_WITH_UNDERSCORES = .*version = \")[^\"]+(\".*)/\1$VERSION\2/" agb/Cargo.toml
|
|
|
|
|
|
|
|
(cd agb && cargo update)
|
|
|
|
git add agb/Cargo.toml agb/Cargo.lock
|
2021-06-21 08:03:10 +10:00
|
|
|
fi
|
|
|
|
|
2021-08-16 08:20:51 +10:00
|
|
|
# Sanity check to make sure the build works
|
|
|
|
(cd agb && cargo test)
|
|
|
|
(cd agb-image-converter && cargo test)
|
2021-10-19 06:27:38 +11:00
|
|
|
(cd agb-sound-converter && cargo test)
|
2021-08-16 08:20:51 +10:00
|
|
|
(cd agb-macros && cargo test)
|
|
|
|
|
2021-08-16 08:15:25 +10:00
|
|
|
if [ ! "$NO_COMMIT" = "--no-commit" ]; then
|
|
|
|
# Commit the Cargo.toml changes
|
|
|
|
git commit -m "Release $PROJECT v$VERSION"
|
2021-06-21 08:03:10 +10:00
|
|
|
|
2021-08-16 08:15:25 +10:00
|
|
|
# Tag the version
|
|
|
|
git tag -a $TAGNAME -m "$PROJECT - v$VERSION"
|
2021-06-21 08:03:10 +10:00
|
|
|
|
2021-08-16 08:15:25 +10:00
|
|
|
echo "Done! Push with"
|
|
|
|
echo "git push --atomic origin master $TAGNAME"
|
|
|
|
fi
|