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