1+ #! /bin/bash
2+
3+ # Ensures that the package is ready for a release.
4+ #
5+ # Will update the version.dart file and update the CHANGELOG.md.
6+ #
7+ # Set it up for a new version:
8+ # `./release_ready.sh <version>
9+
10+ currentBranch=$( git symbolic-ref --short -q HEAD)
11+ if [[ ! $currentBranch == " main" ]]; then
12+ echo " Releasing is only supported on the main branch."
13+ exit 1
14+ fi
15+
16+ # Get information
17+ old_version=$( git for-each-ref --count=2 --format " %(refname:short)" --sort=-creatordate refs/tags | tail -n +2 | cut -c 2-)
18+
19+ if [ -z " $old_version " ]; then
20+ echo " Current version was not resolved."
21+ exit 1
22+ fi
23+
24+ # Get new version
25+ new_version=" $1 " ;
26+
27+ if [[ " $new_version " == " " ]]; then
28+ echo " No new version supplied, please provide one"
29+ exit 1
30+ fi
31+
32+ if [[ " $new_version " == " $old_version " ]]; then
33+ echo " Current version is $old_version , can't update."
34+ exit 1
35+ fi
36+
37+ # Retrieving all the commits in the current directory since the last tag.
38+ previousTag=" v${old_version} "
39+ raw_commits=" $( git log --pretty=format:" %s" --no-merges --reverse $previousTag ..HEAD -- .) "
40+ markdown_commits=$( echo " $raw_commits " | sed -En " s/\(#([0-9]+)\)/([#\1](https:\/\/github.com\/VeryGoodOpenSource\/very_good_workflows\/pull\/\1))/p" )
41+
42+ if [[ " $markdown_commits " == " " ]]; then
43+ echo " No commits since last tag, can't update."
44+ exit 0
45+ fi
46+ commits=$( echo " $markdown_commits " | sed -En " s/^/- /p" )
47+
48+ if grep -q v$new_version " CHANGELOG.md" ; then
49+ echo " CHANGELOG already contains version $new_version ."
50+ exit 1
51+ fi
52+
53+ # Add a new version entry with the found commits to the CHANGELOG.md.
54+ echo " # ${new_version} \n\n ${commits} \n\n$( cat CHANGELOG.md) " > CHANGELOG.md
55+ echo " CHANGELOG generated, validate entries here: $( pwd) /CHANGELOG.md"
56+
57+ echo " Creating git branch for ver_good_cli@$new_version "
58+ git checkout -b " chore/$new_version " > /dev/null
59+
60+ git add pubspec.yaml CHANGELOG.md
61+
62+ echo " "
63+ echo " Run the following command if you wish to commit the changes:"
64+ echo " git commit -m \" chore: v$new_version \" "
0 commit comments