From 8e01fc7511ecefd3d16563cb0025aca541b4c1e0 Mon Sep 17 00:00:00 2001 From: Osip Fatkullin Date: Wed, 31 Jul 2024 18:54:42 +0300 Subject: [PATCH] fix: Fix release flow (#2) --- CHANGELOG.md | 2 +- RELEASING.md | 35 +++++++++++++++++++++++++---------- release.sh | 48 +++++++++++++++++++++++++++++++++--------------- 3 files changed, 59 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ecba71..4d17a36 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ - no changes -## v0.1.0 - 2024.07.25 +## v0.1.0 (2024-07-25) Initial public release diff --git a/RELEASING.md b/RELEASING.md index c9bcd66..3d4c9ae 100644 --- a/RELEASING.md +++ b/RELEASING.md @@ -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. diff --git a/release.sh b/release.sh index 5f1a0a6..027fe82 100755 --- a/release.sh +++ b/release.sh @@ -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 @@ -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 } @@ -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 @@ -56,6 +72,7 @@ for file in "${files_to_update_version[@]}" ; do done # 3. Update header in CHANGELOG.md +date=$(date -u +%Y-%m-%d) header_replacement=\ "## [Unreleased] @@ -63,23 +80,23 @@ header_replacement=\ - *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 @@ -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")"