1
1
#! /usr/bin/env bash
2
+ #
3
+ # Prepares the library for release. Creates a release branch from the 'main'.
4
+ #
5
+ # Usage: ./release.sh [version]
6
+ # Example: ./release.sh 1.0.0
7
+ #
8
+ # Original release script: https://github.com/RedMadRobot/android-library-template/blob/main/release.sh
2
9
3
10
set -euo pipefail
4
11
@@ -13,6 +20,11 @@ files_to_update_version=("$properties" "$readme")
13
20
github_repository_url=" https://github.com/RedMadRobot/%Stub%"
14
21
15
22
# region Utils
23
+ function error() {
24
+ echo " ❌ $1 "
25
+ return 1
26
+ }
27
+
16
28
function property {
17
29
grep " ^${1} =" " $properties " | cut -d' =' -f2
18
30
}
@@ -31,22 +43,26 @@ function diff_link() {
31
43
}
32
44
# endregion
33
45
46
+ # Validate input parameters
47
+ version=${1:- Please, specify the version to be released as a script parameter}
48
+ [[ $version != v* ]] || error " The version should not start from 'v'"
49
+ version_tag=" v$version "
50
+
34
51
# 0. Fetch remote changes
35
- echo " ️⏳ Updating local repository ..."
36
- git fetch --quiet -p origin
37
- git switch --quiet main
38
- git pull --quiet --rebase origin
39
- echo " ✅ Repository updated. "
52
+ echo " ️⏳ Creating release branch ..."
53
+ release_branch= " release/ $version "
54
+ git checkout --quiet -b " $release_branch "
55
+ git pull --quiet --rebase origin main
56
+ echo " ✅ Branch ' $release_branch ' created "
40
57
echo
41
58
42
59
# 1. Calculate version values for later
43
60
last_version=$( property " version" )
44
- version=$( date " +%Y.%m.%d" )
45
61
if [[ " $last_version " == " $version " ]]; then
46
62
echo " 🤔 Version $version is already set."
47
63
exit 0
48
64
fi
49
- echo " 🚀 Update $last_version -> $version "
65
+ echo " 🚀 Update $last_version → $version "
50
66
echo
51
67
52
68
# 2. Update version everywhere
@@ -56,30 +72,31 @@ for file in "${files_to_update_version[@]}" ; do
56
72
done
57
73
58
74
# 3. Update header in CHANGELOG.md
75
+ date=$( date -u +%Y-%m-%d)
59
76
header_replacement=\
60
77
" ## [Unreleased]
61
78
62
79
### Changes
63
80
64
81
- *No changes*
65
82
66
- ## [$version ]"
83
+ ## [$version ] ( $date ) "
67
84
replace " ^## \[Unreleased\].*" " $header_replacement " " $changelog "
68
85
echo " ✅ Updated CHANGELOG.md header"
69
86
70
87
# 4. Add link to version diff
71
- unreleased_diff_link=" [unreleased]: $( diff_link " $version " " main" ) "
72
- version_diff_link=" [$version ]: $( diff_link " $last_version " " $version " ) "
88
+ unreleased_diff_link=" [unreleased]: $( diff_link " $version_tag " " main" ) "
89
+ version_diff_link=" [$version ]: $( diff_link " v $last_version " " $version_tag " ) "
73
90
replace " ^\[unreleased\]:.*" " $unreleased_diff_link \n$version_diff_link " " $changelog "
74
91
echo " ✅ Added a diff link to CHANGELOG.md"
75
92
76
93
# 5. Ask if the changes should be pushed to remote branch
77
94
echo
78
- echo " Do you want to commit the changes and create a release tag?"
79
- echo " The release tag push will trigger a release workflow on CI."
95
+ echo " Do you want to commit the changes and push the release branch and tag?"
96
+ echo " The release tag push triggers a release workflow on CI."
80
97
read -p " Enter 'yes' to continue: " -r input
81
98
if [[ " $input " != " yes" ]]; then
82
- echo " 👌 DONE ."
99
+ echo " 👌 SKIPPED ."
83
100
exit 0
84
101
fi
85
102
88
105
echo " ⏳ Pushing the changes to the remote repository..."
89
106
git add " $readme " " $changelog " " $properties "
90
107
git commit --quiet --message " version: $version "
91
- git tag " $version "
92
- git push --quiet origin HEAD " $version "
108
+ git tag " $version_tag "
109
+ git push --quiet origin HEAD " $version_tag "
93
110
echo " 🎉 DONE."
111
+ echo " Create a Pull Request: $( diff_link " main" " $release_branch " ) "
0 commit comments