Skip to content

Improve bump-version.sh #3365

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ To release a new `<version>` of `kotlinx-coroutines`:
* [`gradle.properties`](gradle.properties)
* Make sure to **exclude** `CHANGES.md` from replacements.

As an alternative approach, you can use `./bump-version.sh old_version new_version`
As an alternative approach, you can use `./bump-version.sh new_version`

5. Write release notes in [`CHANGES.md`](CHANGES.md):
* Use the old releases for style guidance.
Expand All @@ -43,7 +43,7 @@ To release a new `<version>` of `kotlinx-coroutines`:
* Get approval for it.

0. On [TeamCity integration server](https://teamcity.jetbrains.com/project.html?projectId=KotlinTools_KotlinxCoroutines):
* Wait until "Build" configuration for committed `master` branch passes tests.
* Wait until "Build" configuration for committed `version-<version>` branch passes tests.
* Run "Deploy (Configure, RUN THIS ONE)" configuration with the corresponding new version:
- Use the `version-<version>` branch
- Set the `DeployVersion` build parameter to `<version>`
Expand Down
106 changes: 83 additions & 23 deletions bump-version.sh
Original file line number Diff line number Diff line change
@@ -1,35 +1,95 @@
#!/bin/bash
#!/bin/sh

if [ "$#" -ne 2 ]
set -efu

# the list of files that need to have the version updated in them
#
# limitations:
# * no newlines in names
# * no ' char in names
files="
README.md
kotlinx-coroutines-core/README.md
kotlinx-coroutines-debug/README.md
kotlinx-coroutines-test/README.md
ui/coroutines-guide-ui.md
gradle.properties
integration-testing/gradle.properties
"

# read gradle.properties to get the old version
set +e
old_version="$(git grep -hoP '(?<=^version=).*(?=-SNAPSHOT$)' gradle.properties)"
set -e
if [ "$?" -ne 0 ]
then
echo "Use: ./bump-version old_version new_version"
exit
echo "Could not read the old version from gradle.properties." >&2
if [ "$#" -ne 2 ]
then
echo "Please use this form instead: ./bump-version.sh old_version new_version"
exit 1
fi
fi

old_version=$1
new_version=$2
# check the command-line arguments for mentions of the version
if [ "$#" -eq 2 ]
then
echo "If you want to infer the version automatically, use the form: ./bump-version.sh new_version" >&2
if [ -n "$old_version" -a "$1" != "$old_version" ]
then
echo "The provided old version ($1) is different from the one in gradle.properties ($old_version)." >&2
echo "Proceeding anyway with the provided old version." >&2
fi
old_version=$1
new_version=$2
elif [ "$#" -eq 1 ]
then
new_version=$1
else
echo "Use: ./bump-version.sh new_version" >&2
exit 1
fi


# Escape dots, e.g. 1.0.0 -> 1\.0\.0
escaped_old_version="$(printf "%s\n" "$old_version" | sed 's/[.]/\\./g')"

update_version() {
echo "Updating version from '$old_version' to '$new_version' in $1"
sed -i.bak s/$old_version/$new_version/g $1
rm $1.bak
file=$1
to_undo=$2
echo "Updating version from '$old_version' to '$new_version' in $1" >&2
if [ -n "$(git diff --name-status -- "$file")" ]
then
printf "There are unstaged changes in '$file'. Refusing to proceed.\n" >&2
[ -z "$to_undo" ] || eval "git checkout$to_undo"
exit 1
fi
sed -i.bak "s/$escaped_old_version/$new_version/g" "$file"
rm -f "$1.bak"
}

update_version "README.md"
update_version "kotlinx-coroutines-core/README.md"
update_version "kotlinx-coroutines-debug/README.md"
update_version "kotlinx-coroutines-test/README.md"
update_version "ui/coroutines-guide-ui.md"
update_version "gradle.properties"
update_version "integration-test/gradle.properties"
to_undo=$(printf "%s" "$files" | while read -r file; do
if [ -n "$file" ]
then
update_version "$file" "${to_undo:-}"
to_undo="${to_undo:-} '$file'"
echo -n " '$file'"
fi
done)

# Escape dots, e.g. 1.0.0 -> 1\.0\.0
escaped_old_version=$(echo $old_version | sed s/[.]/\\\\./g)
result=$(find ./ -type f \( -iname \*.properties -o -iname \*.md \) | grep -v "\.gradle" | grep -v "build" | xargs -I{} grep -H "$escaped_old_version" {} | grep -v CHANGES.md | grep -v COMPATIBILITY.md)
if [ -z "$result" ];
set +e
version_mentions=$(
find . -type f \( -iname '*.properties' -o -iname '*.md' \) \
-not -iname CHANGES.md \
-exec git grep --fixed-strings --word "$old_version" {} +
)
set -e
if [ -z "$version_mentions" ]
then
echo "Done"
echo "Done. To undo, run this command:" >&2
printf "git checkout%s\n" "$to_undo" >&2
else
echo "ERROR: Previous version is present in the project: $result"
exit -1
echo "ERROR: Previous version is present in the project: $version_mentions"
[ -z "$to_undo" ] || eval "git checkout$to_undo"
exit 1
fi