11#! /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
29
310set -euo pipefail
411
@@ -13,6 +20,11 @@ files_to_update_version=("$properties" "$readme")
1320github_repository_url=" https://github.com/RedMadRobot/%Stub%"
1421
1522# region Utils
23+ function error() {
24+ echo " ❌ $1 "
25+ return 1
26+ }
27+
1628function property {
1729 grep " ^${1} =" " $properties " | cut -d' =' -f2
1830}
@@ -31,22 +43,26 @@ function diff_link() {
3143}
3244# endregion
3345
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+
3451# 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 "
4057echo
4158
4259# 1. Calculate version values for later
4360last_version=$( property " version" )
44- version=$( date " +%Y.%m.%d" )
4561if [[ " $last_version " == " $version " ]]; then
4662 echo " 🤔 Version $version is already set."
4763 exit 0
4864fi
49- echo " 🚀 Update $last_version -> $version "
65+ echo " 🚀 Update $last_version → $version "
5066echo
5167
5268# 2. Update version everywhere
@@ -56,30 +72,31 @@ for file in "${files_to_update_version[@]}" ; do
5672done
5773
5874# 3. Update header in CHANGELOG.md
75+ date=$( date -u +%Y-%m-%d)
5976header_replacement=\
6077" ## [Unreleased]
6178
6279### Changes
6380
6481- *No changes*
6582
66- ## [$version ]"
83+ ## [$version ] ( $date ) "
6784replace " ^## \[Unreleased\].*" " $header_replacement " " $changelog "
6885echo " ✅ Updated CHANGELOG.md header"
6986
7087# 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 " ) "
7390replace " ^\[unreleased\]:.*" " $unreleased_diff_link \n$version_diff_link " " $changelog "
7491echo " ✅ Added a diff link to CHANGELOG.md"
7592
7693# 5. Ask if the changes should be pushed to remote branch
7794echo
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."
8097read -p " Enter 'yes' to continue: " -r input
8198if [[ " $input " != " yes" ]]; then
82- echo " 👌 DONE ."
99+ echo " 👌 SKIPPED ."
83100 exit 0
84101fi
85102
88105echo " ⏳ Pushing the changes to the remote repository..."
89106git add " $readme " " $changelog " " $properties "
90107git 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 "
93110echo " 🎉 DONE."
111+ echo " Create a Pull Request: $( diff_link " main" " $release_branch " ) "
0 commit comments