Skip to content

Commit

Permalink
Preparing next release
Browse files Browse the repository at this point in the history
  • Loading branch information
Drew Heavner committed Aug 22, 2024
1 parent df178b9 commit deb11bc
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 11 deletions.
12 changes: 2 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
branches:
- main
tags:
- v*
- '*.*.*'
pull_request:

jobs:
Expand Down Expand Up @@ -79,7 +79,7 @@ jobs:
- name: Publish snapshot (main branch only)
run: ./gradlew publish -PmavenCentralUsername=${{ secrets.SONATYPEUSERNAME }} -PmavenCentralPassword=${{ secrets.SONATYPEPASSWORD }} --no-configuration-cache

publish-release:
create-release:
runs-on: macos-latest
timeout-minutes: 60
needs: [ build ]
Expand All @@ -98,14 +98,6 @@ jobs:
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4

- name: Publish Release
run: |
./gradlew publish \
-DVERSION_NAME=${{ github.ref_name }}
-PmavenCentralUsername=${{ secrets.SONATYPEUSERNAME }} \
-PmavenCentralPassword=${{ secrets.SONATYPEPASSWORD }} \
--no-configuration-cache
- name: Extract release notes
id: extract-release-notes
uses: ffurrer2/extract-release-notes@v2
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ POM_DEVELOPER_ID=r0adkll
POM_DEVELOPER_NAME=Drew Heavner
POM_DEVELOPER_URL=https://github.com/r0adkll
POM_INCEPTION_YEAR=2024
VERSION_NAME=0.1.0-SNAPSHOT
VERSION_NAME=0.0.0-SNAPSHOT
85 changes: 85 additions & 0 deletions release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/usr/bin/env bash

set -exo pipefail

# Gets a property out of a .properties file
# usage: getProperty $key $filename
function getProperty() {
grep "${1}" "$2" | cut -d'=' -f2
}

# 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" | grep -m 2 -o '[0-9]\+\.[0-9]\+\.[0-9]\+' | 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
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

# Prepare next snapshot
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

0 comments on commit deb11bc

Please sign in to comment.