Skip to content

Commit d546af8

Browse files
committed
fix: Release flow
1 parent 5467097 commit d546af8

File tree

2 files changed

+58
-25
lines changed

2 files changed

+58
-25
lines changed

RELEASING.md

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,39 @@
11
# Releasing
22

3-
1. Run the script `release.sh`:
3+
1. Run the script `release.sh` with the desired version as a parameter:
44
```bash
5-
./release.sh
5+
./release.sh [version]
66
````
7-
2. The script will ask you if you want to push the changes and create a release tag.
7+
8+
2. The script will ask you if you want to push the release branch and create a release tag.
9+
810
3. Ensure `CHANGELOG.md` looks good and is ready to be published.
9-
Delete sections that don't contain changes.
10-
4. Type "yes" to console if everything is okay.
1111

12-
Tag push will trigger GitHub Actions workflow, which will publish the release artifacts to Maven Central and create a GitHub release.
12+
4. Type "yes" to the console if everything is okay.
13+
Tag push triggers a GitHub Actions workflow,
14+
which publishes the release artifacts to Maven Central and creates a GitHub release.
15+
16+
5. Click the link displayed in the console to create a Pull Request for release branch.
17+
18+
6. Merge the Pull Request as soon as the "Check" workflow succeeds.
19+
It is recommended to use fast-forward merge to merge release branches.
1320

1421
## Manual release preparation
1522

1623
To prepare a release manually, follow the steps the script does:
1724

18-
1. Ensure the repository is up-to-date, and the main branch is checked out.
19-
2. Update the version in `gradle.properties` and `README.md` ("Usage" section) using the current date as a version.
20-
3. Update the `CHANGELOG.md`:
25+
1. Ensure the repository is up to date, and the main branch is checked out.
26+
27+
2. Create the release branch with the name `release/[version]`.
28+
29+
3. Update the version in `gradle.properties` and `README.md` ("Usage" section) with the version to be released.
30+
31+
4. Update the `CHANGELOG.md`:
2132
1. Replace `Unreleased` section with the release version
2233
2. Add a link to the diff between the previous and the new version
2334
3. Add a new empty `Unreleased` section on the top
24-
4. Commit the changes, create a tag on the commit and push it to the remote repository
35+
36+
5. Commit the changes, create a tag on the latest commit, and push it to the remote repository.
37+
The tag should follow the format `v[version]`.
38+
39+
6. Create a Pull Request for the release branch and merge it.

release.sh

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
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

310
set -euo pipefail
411

@@ -13,6 +20,11 @@ files_to_update_version=("$properties" "$readme")
1320
github_repository_url="https://github.com/RedMadRobot/%Stub%"
1421

1522
#region Utils
23+
function error() {
24+
echo "$1"
25+
return 1
26+
}
27+
1628
function 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"
4057
echo
4158

4259
# 1. Calculate version values for later
4360
last_version=$(property "version")
44-
version=$(date "+%Y.%m.%d")
4561
if [[ "$last_version" == "$version" ]]; then
4662
echo "🤔 Version $version is already set."
4763
exit 0
4864
fi
49-
echo "🚀 Update $last_version -> $version"
65+
echo "🚀 Update $last_version $version"
5066
echo
5167

5268
# 2. Update version everywhere
@@ -56,30 +72,31 @@ for file in "${files_to_update_version[@]}" ; do
5672
done
5773

5874
# 3. Update header in CHANGELOG.md
75+
date=$(date -u +%Y-%m-%d)
5976
header_replacement=\
6077
"## [Unreleased]
6178
6279
### Changes
6380
6481
- *No changes*
6582
66-
## [$version]"
83+
## [$version] ($date)"
6784
replace "^## \[Unreleased\].*" "$header_replacement" "$changelog"
6885
echo "✅ 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")"
7390
replace "^\[unreleased\]:.*" "$unreleased_diff_link\n$version_diff_link" "$changelog"
7491
echo "✅ Added a diff link to CHANGELOG.md"
7592

7693
# 5. Ask if the changes should be pushed to remote branch
7794
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."
8097
read -p " Enter 'yes' to continue: " -r input
8198
if [[ "$input" != "yes" ]]; then
82-
echo "👌 DONE."
99+
echo "👌 SKIPPED."
83100
exit 0
84101
fi
85102

@@ -88,6 +105,7 @@ echo
88105
echo "⏳ Pushing the changes to the remote repository..."
89106
git add "$readme" "$changelog" "$properties"
90107
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"
93110
echo "🎉 DONE."
111+
echo "Create a Pull Request: $(diff_link "main" "$release_branch")"

0 commit comments

Comments
 (0)