1
+ # Ensures that the package or brick is ready for a release.
2
+ #
3
+ # Will update the version.dart file and update the CHANGELOG.md.
4
+ #
5
+ # Set it up for a new version:
6
+ # `./release_ready.sh <version>
7
+
8
+ # Check if current directory has a pubspec.yaml, if so we assume it is correctly set up.
9
+ if [ ! -f " pubspec.yaml" ] && [ ! -f " brick.yaml" ]; then
10
+ echo " $( pwd) is not a valid package or brick."
11
+ exit 1
12
+ fi
13
+
14
+ currentBranch=$( git symbolic-ref --short -q HEAD)
15
+ if [[ ! $currentBranch == " main" ]]; then
16
+ echo " Releasing is only supported on the main branch."
17
+ exit 1
18
+ fi
19
+
20
+ # Get information
21
+ old_version=" "
22
+ current_name=" "
23
+ if [ -f " pubspec.yaml" ]; then
24
+ old_version=$( dart pub deps --json | pcregrep -o1 -i ' "version": "(.*?)"' | head -1)
25
+ current_name=$( dart pub deps --json | pcregrep -o1 -i ' "name": "(.*?)"' | head -1)
26
+ elif [ -f " brick.yaml" ]; then
27
+ old_version=$( cat brick.yaml | pcregrep ' version: (.*?)' | tr " " " \n" | tail -1)
28
+ current_name=$( cat brick.yaml | pcregrep ' name: (.*?)' | tr " " " \n" | tail -1)
29
+ fi
30
+
31
+ if [ -z " $old_version " ] || [ -z " $current_name " ]; then
32
+ echo " Current version or name was not resolved."
33
+ exit 1
34
+ fi
35
+
36
+ # Get new version
37
+ new_version=" $1 " ;
38
+
39
+ if [[ " $new_version " == " " ]]; then
40
+ echo " No new version supplied, please provide one"
41
+ exit 1
42
+ fi
43
+
44
+ if [[ " $new_version " == " $old_version " ]]; then
45
+ echo " Current version is $old_version , can't update."
46
+ exit 1
47
+ fi
48
+
49
+ # Retrieving all the commits in the current directory since the last tag.
50
+ previousTag=" ${current_name} -v${old_version} "
51
+ raw_commits=" $( git log --pretty=format:" %s" --no-merges --reverse $previousTag ..HEAD -- .) "
52
+ markdown_commits=$( echo " $raw_commits " | sed -En " s/\(#([0-9]+)\)/([#\1](https:\/\/github.com\/VeryGoodOpenSource\/dart_frog\/pull\/\1))/p" )
53
+
54
+ if [[ " $markdown_commits " == " " ]]; then
55
+ echo " No commits since last tag, can't update."
56
+ exit 0
57
+ fi
58
+ commits=$( echo " $markdown_commits " | sed -En " s/^/- /p" )
59
+
60
+ echo " Updating version to $new_version "
61
+ sed -i ' ' " s/version: $old_version /version: $new_version /g" pubspec.yaml
62
+
63
+ # Update dart file with new version.
64
+ dart run build_runner build --delete-conflicting-outputs > /dev/null
65
+
66
+ if grep -q $new_version " CHANGELOG.md" ; then
67
+ echo " CHANGELOG already contains version $new_version ."
68
+ exit 1
69
+ fi
70
+
71
+ # Add a new version entry with the found commits to the CHANGELOG.md.
72
+ echo " # ${new_version} \n\n${commits} \n\n$( cat CHANGELOG.md) " > CHANGELOG.md
73
+ echo " CHANGELOG for $current_name generated, validate entries here: $( pwd) /CHANGELOG.md"
74
+
75
+ echo " Creating git branch for $current_name @$new_version "
76
+ git checkout -b " chore($current_name )/$new_version " > /dev/null
77
+
78
+ git add pubspec.yaml CHANGELOG.md
79
+ if [ -f lib/version.dart ]; then
80
+ git add lib/version.dart
81
+ fi
82
+
83
+ echo " "
84
+ echo " Run the following command if you wish to commit the changes:"
85
+ echo " git commit -m \" chore($current_name ): $new_version \" "
0 commit comments