Skip to content

Commit

Permalink
Update releasing script
Browse files Browse the repository at this point in the history
  • Loading branch information
ZacSweers committed Jul 9, 2023
1 parent e943714 commit e17e44e
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 10 deletions.
4 changes: 2 additions & 2 deletions RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ Releasing
=========

1. Update the `CHANGELOG.md` for the impending release.
2. Run `./release.sh <version>`.
3. Publish the release on the repo's releases tab.
2. Run `./release.sh (--patch|--minor|--major)`.
3. Publish the release on the repo's releases tab.
70 changes: 62 additions & 8 deletions release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,84 @@ set -exo pipefail
# Gets a property out of a .properties file
# usage: getProperty $key $filename
function getProperty() {
grep "${1}" "$2" | cut -d'=' -f2
grep "${1}" "$2" | cut -d'=' -f2
}

NEW_VERSION=$1
SNAPSHOT_VERSION=$(getProperty 'VERSION_NAME' gradle.properties)
# Increments an input version string given a version type
# usage: increment_version $version $version_type
increment_version() {
local delimiter=.
local array=()
while IFS='' read -r line; do array+=("$line"); done < <(echo "$1" | tr $delimiter '\n')
local version_type=$2
local major=${array[0]}
local minor=${array[1]}
local patch=${array[2]}

if [ "$version_type" = "--major" ]; then
major=$((major + 1))
minor=0
patch=0
elif [ "$version_type" = "--minor" ]; then
minor=$((minor + 1))
patch=0
elif [ "$version_type" = "--patch" ]; then
patch=$((patch + 1))
else
echo "Invalid version type. Must be one of: '--major', '--minor', '--patch'"
exit 1
fi

incremented_version="$major.$minor.$patch"

echo "${incremented_version}"
}

# Gets the latest version from the CHANGELOG.md file. Note this assumes the changelog is updated with the
# new version as the latest, so it gets the *2nd* match.
# usage: get_latest_version $changelog_file
get_latest_version() {
local changelog_file=$1
grep -m 2 -o '^[0-9]\+\.[0-9]\+\.[0-9]\+' "$changelog_file" | tail -n 1
}

# Updates the VERSION_NAME prop in all gradle.properties files to a new value
# usage: update_gradle_properties $new_version
update_gradle_properties() {
local new_version=$1

find . -type f -name 'gradle.properties' | while read -r file; do
if grep -q "VERSION_NAME=" "$file"; then
local prev_version
prev_version=$(getProperty 'VERSION_NAME' "${file}")
sed -i '' "s/${prev_version}/${new_version}/g" "${file}"
fi
done
}

# default to patch if no second argument is given
version_type=${1:---patch}
LATEST_VERSION=$(get_latest_version CHANGELOG.md)
NEW_VERSION=$(increment_version "$LATEST_VERSION" "$version_type")
NEXT_SNAPSHOT_VERSION="$(increment_version "$NEW_VERSION" --minor)-SNAPSHOT"

echo "Publishing $NEW_VERSION"

# Prepare release
sed -i '' "s/${SNAPSHOT_VERSION}/${NEW_VERSION}/g" gradle.properties
update_gradle_properties "$NEW_VERSION"
git commit -am "Prepare for release $NEW_VERSION."
git tag -a "$NEW_VERSION" -m "Version $NEW_VERSION"

# Publish
./gradlew publish -x dokkaHtml --no-configuration-cache -Pcircuit.forceAndroidXComposeCompiler=false

# Prepare next snapshot
echo "Restoring snapshot version $SNAPSHOT_VERSION"
sed -i '' "s/${NEW_VERSION}/${SNAPSHOT_VERSION}/g" gradle.properties
./gradlew spotlessApply --no-configuration-cache
echo "Setting next snapshot version $NEXT_SNAPSHOT_VERSION"
update_gradle_properties "$NEXT_SNAPSHOT_VERSION"
git commit -am "Prepare next development version."

# Push it all up
git push && git push --tags

# Publish docs
./deploy_website.sh
./deploy_website.sh

0 comments on commit e17e44e

Please sign in to comment.