From 4a32c805d19b22500d589d8e5cb375ab9fab43c4 Mon Sep 17 00:00:00 2001 From: Jochum van der Ploeg Date: Fri, 17 Nov 2023 13:38:33 +0100 Subject: [PATCH] chore: add release and retag script (#298) --- tool/release_ready.sh | 64 +++++++++++++++++++++++++++++++++++++++++++ tool/retag_v2.sh | 21 ++++++++++++++ 2 files changed, 85 insertions(+) create mode 100755 tool/release_ready.sh create mode 100755 tool/retag_v2.sh diff --git a/tool/release_ready.sh b/tool/release_ready.sh new file mode 100755 index 0000000..96d5573 --- /dev/null +++ b/tool/release_ready.sh @@ -0,0 +1,64 @@ +#!/bin/bash + +# Ensures that the package is ready for a release. +# +# Will update the version.dart file and update the CHANGELOG.md. +# +# Set it up for a new version: +# `./release_ready.sh + +currentBranch=$(git symbolic-ref --short -q HEAD) +if [[ ! $currentBranch == "main" ]]; then + echo "Releasing is only supported on the main branch." + exit 1 +fi + +# Get information +old_version=$(git for-each-ref --count=2 --format "%(refname:short)" --sort=-creatordate refs/tags | tail -n +2 | cut -c 2-) + +if [ -z "$old_version" ]; then + echo "Current version was not resolved." + exit 1 +fi + +# Get new version +new_version="$1"; + +if [[ "$new_version" == "" ]]; then + echo "No new version supplied, please provide one" + exit 1 +fi + +if [[ "$new_version" == "$old_version" ]]; then + echo "Current version is $old_version, can't update." + exit 1 +fi + +# Retrieving all the commits in the current directory since the last tag. +previousTag="v${old_version}" +raw_commits="$(git log --pretty=format:"%s" --no-merges --reverse $previousTag..HEAD -- .)" +markdown_commits=$(echo "$raw_commits" | sed -En "s/\(#([0-9]+)\)/([#\1](https:\/\/github.com\/VeryGoodOpenSource\/very_good_workflows\/pull\/\1))/p") + +if [[ "$markdown_commits" == "" ]]; then + echo "No commits since last tag, can't update." + exit 0 +fi +commits=$(echo "$markdown_commits" | sed -En "s/^/- /p") + +if grep -q v$new_version "CHANGELOG.md"; then + echo "CHANGELOG already contains version $new_version." + exit 1 +fi + +# Add a new version entry with the found commits to the CHANGELOG.md. +echo "# ${new_version} \n\n ${commits}\n\n$(cat CHANGELOG.md)" > CHANGELOG.md +echo "CHANGELOG generated, validate entries here: $(pwd)/CHANGELOG.md" + +echo "Creating git branch for ver_good_cli@$new_version" +git checkout -b "chore/$new_version" > /dev/null + +git add pubspec.yaml CHANGELOG.md + +echo "" +echo "Run the following command if you wish to commit the changes:" +echo "git commit -m \"chore: v$new_version\"" \ No newline at end of file diff --git a/tool/retag_v2.sh b/tool/retag_v2.sh new file mode 100755 index 0000000..56e8e2d --- /dev/null +++ b/tool/retag_v2.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +# Updates the "v2" tag to point to a newer release. +# To be executed whenever a new 1.x tag is created. +# Usage: ./retag_v2.sh + +currentBranch=$(git symbolic-ref --short -q HEAD) +if [[ ! $currentBranch == "main" ]]; then + echo "Re-tagging is only supported on the main branch." + exit 1 +fi + +# Get new version +new_version="$1"; + +if [[ "$new_version" == "" ]]; then + echo "No new version supplied, please provide one" + exit 1 +fi + +git tag -d v2 && git tag v2 v$new_version && git push origin --delete v2 && git push origin v2 \ No newline at end of file