Skip to content

Commit

Permalink
fix: Fix release flow (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
osipxd authored Jul 31, 2024
1 parent 7655813 commit 8e01fc7
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 26 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

- no changes

## v0.1.0 - 2024.07.25
## v0.1.0 (2024-07-25)

Initial public release

Expand Down
35 changes: 25 additions & 10 deletions RELEASING.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,39 @@
# Releasing

1. Run the script `release.sh`:
1. Run the script `release.sh` with the desired version as a parameter:
```bash
./release.sh
./release.sh [version]
````
2. The script will ask you if you want to push the changes and create a release tag.

2. The script will ask you if you want to push the release branch and create a release tag.

3. Ensure `CHANGELOG.md` looks good and is ready to be published.
Delete sections that don't contain changes.
4. Type "yes" to console if everything is okay.

Tag push will trigger GitHub Actions workflow, which will publish the release artifacts to Maven Central and create a GitHub release.
4. Type "yes" to the console if everything is okay.
Tag push triggers a GitHub Actions workflow,
which publishes the release artifacts to Maven Central and creates a GitHub release.

5. Click the link displayed in the console to create a Pull Request for release branch.

6. Merge the Pull Request as soon as the "Check" workflow succeeds.
It is recommended to use fast-forward merge to merge release branches.

## Manual release preparation

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

1. Ensure the repository is up-to-date, and the main branch is checked out.
2. Update the version in `gradle.properties` and `README.md` ("Usage" section) using the current date as a version.
3. Update the `CHANGELOG.md`:
1. Ensure the repository is up to date, and the main branch is checked out.

2. Create the release branch with the name `release/[version]`.

3. Update the version in `gradle.properties` and `README.md` ("Usage" section) with the version to be released.

4. Update the `CHANGELOG.md`:
1. Replace `Unreleased` section with the release version
2. Add a link to the diff between the previous and the new version
3. Add a new empty `Unreleased` section on the top
4. Commit the changes, create a tag on the commit and push it to the remote repository

5. Commit the changes, create a tag on the latest commit, and push it to the remote repository.
The tag should follow the format `v[version]`.

6. Create a Pull Request for the release branch and merge it.
48 changes: 33 additions & 15 deletions release.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
#!/usr/bin/env bash
#
# Prepares the library for release. Creates a release branch from the 'main'.
#
# Usage: ./release.sh [version]
# Example: ./release.sh 1.0.0
#
# Original release script: https://github.com/RedMadRobot/android-library-template/blob/main/release.sh

set -euo pipefail

Expand All @@ -13,6 +20,11 @@ files_to_update_version=("$properties" "$readme")
github_repository_url="https://github.com/RedMadRobot/Konfeature"

#region Utils
function error() {
echo "$1"
return 1
}

function property {
grep "^${1}=" "$properties" | cut -d'=' -f2
}
Expand All @@ -31,22 +43,26 @@ function diff_link() {
}
#endregion

# Validate input parameters
version=${1:-Please, specify the version to be released as a script parameter}
[[ $version != v* ]] || error "The version should not start from 'v'"
version_tag="v$version"

# 0. Fetch remote changes
echo "️⏳ Updating local repository..."
git fetch --quiet -p origin
git switch --quiet main
git pull --quiet --rebase origin
echo "Repository updated."
echo "️⏳ Creating release branch..."
release_branch="release/$version"
git checkout --quiet -b "$release_branch"
git pull --quiet --rebase origin main
echo "Branch '$release_branch' created"
echo

# 1. Calculate version values for later
last_version=$(property "version")
version=$(date "+%Y.%m.%d")
if [[ "$last_version" == "$version" ]]; then
echo "🤔 Version $version is already set."
exit 0
fi
echo "🚀 Update $last_version -> $version"
echo "🚀 Update $last_version $version"
echo

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

# 3. Update header in CHANGELOG.md
date=$(date -u +%Y-%m-%d)
header_replacement=\
"## [Unreleased]
### Changes
- *No changes*
## [$version]"
## [$version] ($date)"
replace "^## \[Unreleased\].*" "$header_replacement" "$changelog"
echo "✅ Updated CHANGELOG.md header"

# 4. Add link to version diff
unreleased_diff_link="[unreleased]: $(diff_link "$version" "main")"
version_diff_link="[$version]: $(diff_link "$last_version" "$version")"
unreleased_diff_link="[unreleased]: $(diff_link "$version_tag" "main")"
version_diff_link="[$version]: $(diff_link "v$last_version" "$version_tag")"
replace "^\[unreleased\]:.*" "$unreleased_diff_link\n$version_diff_link" "$changelog"
echo "✅ Added a diff link to CHANGELOG.md"

# 5. Ask if the changes should be pushed to remote branch
echo
echo "Do you want to commit the changes and create a release tag?"
echo "The release tag push will trigger a release workflow on CI."
echo "Do you want to commit the changes and push the release branch and tag?"
echo "The release tag push triggers a release workflow on CI."
read -p " Enter 'yes' to continue: " -r input
if [[ "$input" != "yes" ]]; then
echo "👌 DONE."
echo "👌 SKIPPED."
exit 0
fi

Expand All @@ -88,6 +105,7 @@ echo
echo "⏳ Pushing the changes to the remote repository..."
git add "$readme" "$changelog" "$properties"
git commit --quiet --message "version: $version"
git tag "$version"
git push --quiet origin HEAD "$version"
git tag "$version_tag"
git push --quiet origin HEAD "$version_tag"
echo "🎉 DONE."
echo "Create a Pull Request: $(diff_link "main" "$release_branch")"

0 comments on commit 8e01fc7

Please sign in to comment.