diff --git a/RELEASING.md b/RELEASING.md index bcaee1f7..5fb0b198 100644 --- a/RELEASING.md +++ b/RELEASING.md @@ -1,9 +1,9 @@ Releasing ========= -1. Update the version in Sources/Version.swift -2. `git commit -am "Version X.Y.Z"` -3. `git tag -a X.Y.Z -m "Version X.Y.Z"` -4. `git push && git push --tags` -5. Create a new github release at https://github.com/segmentio/analytics-swift/releases - * Summarize change history since last release in the notes. +Use `release.sh` to perform releases. This script will perform all the safety checks as well +as update Version.swfit, commit the change, and create tag + release. History since the last +released version will be used as the changelog for the release. + +ex: $ ./release.sh 1.1.1 + \ No newline at end of file diff --git a/Sources/Segment/Version.swift b/Sources/Segment/Version.swift index 8d4ea5b6..f7309d14 100644 --- a/Sources/Segment/Version.swift +++ b/Sources/Segment/Version.swift @@ -7,5 +7,12 @@ // Referred to by Analytics.swift +// DO NOT MODIFY THIS FILE BY HAND!! +// DO NOT MODIFY THIS FILE BY HAND!! +// DO NOT MODIFY THIS FILE BY HAND!! +// DO NOT MODIFY THIS FILE BY HAND!! + +// Use release.sh's automation. + // BREAKING.FEATURE.FIX internal let __segment_version = "1.0.1" diff --git a/release.sh b/release.sh new file mode 100755 index 00000000..7b19df0d --- /dev/null +++ b/release.sh @@ -0,0 +1,110 @@ +#!/bin/bash + +vercomp () { + if [[ $1 == $2 ]] + then + return 0 + fi + local IFS=. + local i ver1=($1) ver2=($2) + # fill empty fields in ver1 with zeros + for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)) + do + ver1[i]=0 + done + for ((i=0; i<${#ver1[@]}; i++)) + do + if [[ -z ${ver2[i]} ]] + then + # fill empty fields in ver2 with zeros + ver2[i]=0 + fi + if ((10#${ver1[i]} > 10#${ver2[i]})) + then + return 1 + fi + if ((10#${ver1[i]} < 10#${ver2[i]})) + then + return 2 + fi + done + return 0 +} + +# check if `gh` tool is installed. +if ! command -v gh &> /dev/null +then + echo "Github CLI tool is required, but could not be found." + echo "Install it via: $ brew install gh" + exit 1 +fi + +# check that we're on the `main` branch +branch=$(git rev-parse --abbrev-ref HEAD) +if [ branch != 'main' ] +then + echo "The 'main' branch must be the current branch out to make a release." + echo "You are currently on: $branch" + exit 1 +fi + +versionFile="./sources/Segment/Version.swift" + +# get last line in version.swift +versionLine=$(tail -n 1 $versionFile) +# split at the = +version=$(cut -d "=" -f2- <<< "$versionLine") +# remove quotes and spaces +version=$(sed "s/[' \"]//g" <<< "$version") + +echo "Analytics-Swift current version: $version" + +# no args, so give usage. +if [ $# -eq 0 ] +then + echo "Release automation script" + echo "" + echo "Usage: $ ./release.sh " + echo " ex: $ ./release.sh \"1.0.2\"" + exit 0 +fi + +newVersion="${1%.*}.$((${1##*.}))" +echo "$version" +echo "$newVersion" + +vercomp $newVersion $version +case $? in + 0) op='=';; + 1) op='>';; + 2) op='<';; +esac + +if [ $op != '>' ] +then + echo "New version must be greater than previous version ($version)." + exit 1 +fi + +# get the commits since the last release... +# note: we do this here so the "Version x.x.x" commit doesn't show up in logs. +changelog=git log --pretty=format:"- (%an) %s" $(git describe --tags --abbrev=0 @^)..@ +tempFile=$(mktemp) +#write changelog to temp file. +echo $changelog >> $tempFile + +# update sources/Segment/Version.swift +# - remove last line... +sed -i '' -e '$ d' $versionFile +# - add new line w/ new version +echo "internal let __segment_version = \"$newVersion\"" >> $versionFile + +# commit the version change. +git commit -am "Version $newVersion" && git push +# gh release will make both the tag and the release itself. +gh release create $newVersion -F $tempFile -t "Version $newVersion" + +# remove the tempfile. +rm $tempFile + +