2021-06-21 08:03:10 +10:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
# Fail if any command fails
|
|
|
|
set -e
|
|
|
|
|
2022-07-04 03:10:16 +10:00
|
|
|
VERSION=$1
|
|
|
|
NO_COMMIT=$2
|
2021-06-21 08:03:10 +10:00
|
|
|
|
|
|
|
# Sanity check that we actually have a version
|
|
|
|
if [ "$VERSION" = "" ]; then
|
2022-07-04 03:10:16 +10:00
|
|
|
echo "Usage $0 <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
|
2022-01-02 05:55:37 +11:00
|
|
|
if echo "$VERSION" | grep -q -Ev "^[0-9]+\.[0-9]+\.[0-9]+$"; then
|
2021-06-21 08:07:47 +10:00
|
|
|
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
|
|
|
|
|
2022-07-04 03:13:43 +10:00
|
|
|
function maybe_git() {
|
|
|
|
if [ "$NO_COMMIT" = "--no-commit" ]; then
|
|
|
|
echo "Would run: git $*"
|
|
|
|
else
|
|
|
|
git "$@"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-06-21 08:03:10 +10:00
|
|
|
# Check that no out-standing changes in git
|
2022-07-04 03:14:25 +10:00
|
|
|
if [ "$NO_COMMIT" = "" ] && [ -n "$(git status --porcelain)" ]; then
|
2021-06-21 08:03:10 +10:00
|
|
|
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
|
|
|
|
|
2022-07-04 03:10:16 +10:00
|
|
|
TAGNAME="v$VERSION"
|
|
|
|
|
|
|
|
for PROJECT_TOML_FILE in agb/Cargo.toml agb-*/Cargo.toml; do
|
|
|
|
DIRECTORY=$(dirname "$PROJECT_TOML_FILE")
|
|
|
|
|
|
|
|
# Update the version in Cargo.toml
|
|
|
|
sed -i -e "s/^version = \".*\"/version = \"$VERSION\"/" "$DIRECTORY/Cargo.toml"
|
|
|
|
|
|
|
|
# Also update the lock file
|
|
|
|
(cd "$DIRECTORY" && cargo update)
|
|
|
|
|
|
|
|
if [ "$DIRECTORY" = "agb" ]; then
|
|
|
|
# also update the agb version in the template and the examples
|
|
|
|
sed -i -e "s/^agb = \".*\"/agb = \"$VERSION\"/" template/Cargo.toml
|
|
|
|
|
|
|
|
for EXAMPLE_TOML_FILE in examples/*/Cargo.toml book/games/*/Cargo.toml; do
|
|
|
|
EXAMPLE_DIR=$(dirname "$EXAMPLE_TOML_FILE")
|
|
|
|
sed -E -i -e "/agb =/ s/version = \"[^\"]+\"/version = \"$VERSION\"/" "$EXAMPLE_DIR/Cargo.toml"
|
|
|
|
(cd "$EXAMPLE_DIR" && cargo update)
|
|
|
|
done
|
|
|
|
else
|
|
|
|
PROJECT_NAME_WITH_UNDERSCORES=$(echo -n "$DIRECTORY" | tr - _)
|
|
|
|
|
|
|
|
for CARGO_TOML_FILE in agb-*/Cargo.toml agb/Cargo.toml examples/*/Cargo.toml book/games/*/Cargo.toml; do
|
|
|
|
sed -i -E -e "s/($PROJECT_NAME_WITH_UNDERSCORES = .*version = \")[^\"]+(\".*)/\1$VERSION\2/" "$CARGO_TOML_FILE"
|
|
|
|
(cd "$(dirname "$CARGO_TOML_FILE")" && cargo generate-lockfile)
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
done
|
2021-06-21 08:03:10 +10:00
|
|
|
|
2021-08-16 08:20:51 +10:00
|
|
|
# Sanity check to make sure the build works
|
2022-07-04 03:20:14 +10:00
|
|
|
just ci
|
2022-01-13 09:04:39 +11:00
|
|
|
|
2022-01-13 09:23:23 +11:00
|
|
|
for EXAMPLE_TOML_FILE in examples/*/Cargo.toml book/games/*/Cargo.toml; do
|
|
|
|
EXAMPLE_DIR=$(dirname "$EXAMPLE_TOML_FILE")
|
2022-01-01 23:41:35 +11:00
|
|
|
(cd "$EXAMPLE_DIR" && cargo check --release)
|
|
|
|
done
|
2021-08-16 08:20:51 +10:00
|
|
|
|
2022-07-04 03:13:43 +10:00
|
|
|
# Commit the Cargo.toml changes
|
2022-07-04 03:20:14 +10:00
|
|
|
maybe_git commit -am "Release v$VERSION"
|
2021-06-21 08:03:10 +10:00
|
|
|
|
2022-07-04 03:13:43 +10:00
|
|
|
# Tag the version
|
|
|
|
maybe_git tag -a "$TAGNAME" -m "v$VERSION"
|
2021-06-21 08:03:10 +10:00
|
|
|
|
2022-07-04 03:13:43 +10:00
|
|
|
echo "Done! Push with"
|
|
|
|
echo "git push --atomic origin master $TAGNAME"
|