From 6c1b2786ec1901c446cd57f8665febea7e5e0fd6 Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Sun, 20 Jun 2021 23:03:10 +0100 Subject: [PATCH 1/6] Add simple release script to automate tag generation --- release.sh | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100755 release.sh diff --git a/release.sh b/release.sh new file mode 100755 index 00000000..ba075463 --- /dev/null +++ b/release.sh @@ -0,0 +1,66 @@ +#!/usr/bin/env bash + +# Fail if any command fails +set -e + +PROJECT=$1 +VERSION=$2 + +# Sanity check that we actually have a version +if [ "$VERSION" = "" ]; then + echo "Usage $0 " + exit 1 +fi + +# 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" + ;; + 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 + +# Sanity check to make sure the build works +(cd agb && cargo test) +(cd agb-image-converter && cargo test) + +# 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) +git add "$DIRECTIORY/Cargo.toml" + +if [ "$PROJECT" = "agb" ]; then + # also update the agb version in the template + sed -i -e "s/agb = \"\(.*\)\"/$VERSION/" template/Cargo.toml + git add template/Cargo.toml +fi + +# Commit the Cargo.toml changes +git commit -m "Release $PROJECT v$VERSION" + +# Tag the version +git tag -a $TAGNAME -m "$PROJECT - v$VERSION" + +echo "Done! Push with" +echo "git push origin $TAGNAME" \ No newline at end of file From c1917b7d0adf5e20d879b9e64926a9b8d4b64825 Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Sun, 20 Jun 2021 23:04:56 +0100 Subject: [PATCH 2/6] Must be in master branch before you can release --- release.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/release.sh b/release.sh index ba075463..be4eaf85 100755 --- a/release.sh +++ b/release.sh @@ -39,6 +39,12 @@ if [ ! -z "$(git status --porcelain)" ]; then exit 1 fi +# Check that we are in the master branch +if [ "$(git symbolic-ref --short HEAD)" != "master" ]; then + echo "You must be in the master branch before releasing" + exit 1 +fi + # Sanity check to make sure the build works (cd agb && cargo test) (cd agb-image-converter && cargo test) From 9924fb9aa13b137cae7b2573ce9b49843f7a506f Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Sun, 20 Jun 2021 23:07:06 +0100 Subject: [PATCH 3/6] Check that the version number is of the correct format --- release.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/release.sh b/release.sh index be4eaf85..f51c4e8f 100755 --- a/release.sh +++ b/release.sh @@ -12,6 +12,12 @@ if [ "$VERSION" = "" ]; then exit 1 fi +# Check the format of version +if [ ! "$(echo "$VERSION" | grep -E "[0-9]+\.[0-9]+\.[0-9]+")" ]; then + echo "Version must be of the form x.y.z" + exit 1 +fi + # Set up $DIRECTORY and $TAGNAME case "$PROJECT" in agb) From ba58d3bf27b0b699dfb59ec451d4fdc4b0484a94 Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Sun, 20 Jun 2021 23:07:47 +0100 Subject: [PATCH 4/6] Check version number is of the correct format --- release.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/release.sh b/release.sh index f51c4e8f..098b1216 100755 --- a/release.sh +++ b/release.sh @@ -13,8 +13,8 @@ if [ "$VERSION" = "" ]; then fi # Check the format of version -if [ ! "$(echo "$VERSION" | grep -E "[0-9]+\.[0-9]+\.[0-9]+")" ]; then - echo "Version must be of the form x.y.z" +if [ ! "$(echo "$VERSION" | grep -E "^[0-9]+\.[0-9]+\.[0-9]+$")" ]; then + echo "Version must be of the form x.y.z, got $VERSION" exit 1 fi From 05b2d66907a77603497b63c64410ea80eb6e2e66 Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Sun, 20 Jun 2021 23:14:17 +0100 Subject: [PATCH 5/6] Fix issues uncovered while testing --- release.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/release.sh b/release.sh index 098b1216..e57c2d5a 100755 --- a/release.sh +++ b/release.sh @@ -56,15 +56,15 @@ fi (cd agb-image-converter && cargo test) # Update the version in Cargo.toml -sed -i -e "s/^version = .*/version = $VERSION/" "$DIRECTORY/Cargo.toml" +sed -i -e "s/^version = \".*\"/version = \"$VERSION\"/" "$DIRECTORY/Cargo.toml" # Also update the lock file (cd "$DIRECTORY" && cargo update) -git add "$DIRECTIORY/Cargo.toml" +git add "$DIRECTORY/Cargo.toml" if [ "$PROJECT" = "agb" ]; then # also update the agb version in the template - sed -i -e "s/agb = \"\(.*\)\"/$VERSION/" template/Cargo.toml + sed -i -e "s/^agb = \".*\"/agb = \"$VERSION\"/" template/Cargo.toml git add template/Cargo.toml fi From adfb4839b6b3d328812390cf685c792a19ab77a9 Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Sun, 20 Jun 2021 23:31:07 +0100 Subject: [PATCH 6/6] Improve recommended command to run --- release.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/release.sh b/release.sh index e57c2d5a..d3a6a4a2 100755 --- a/release.sh +++ b/release.sh @@ -75,4 +75,4 @@ git commit -m "Release $PROJECT v$VERSION" git tag -a $TAGNAME -m "$PROJECT - v$VERSION" echo "Done! Push with" -echo "git push origin $TAGNAME" \ No newline at end of file +echo "git push --atomic origin master $TAGNAME" \ No newline at end of file