|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +set -e |
| 4 | + |
| 5 | +adminDir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) |
| 6 | +cd "$adminDir/.." |
| 7 | +repositoryName=$(basename `pwd`) |
| 8 | + |
| 9 | +if [[ ! -f ~/.ivy2/.credentials ]]; then |
| 10 | + echo "In order to publish to sonatype, you need a credentials file ~/.ivy2/.credentials with the following content:" |
| 11 | + cat <<EOF |
| 12 | +realm=Sonatype Nexus Repository Manager |
| 13 | +host=oss.sonatype.org |
| 14 | +user=<USERNAME> |
| 15 | +password=<PASSWORD> |
| 16 | +EOF |
| 17 | + exit 1 |
| 18 | +fi |
| 19 | + |
| 20 | +function checkValidVersion() { |
| 21 | + if [[ "$1" == "" ]]; then |
| 22 | + echo "⚠️ Empty input, aborting." |
| 23 | + exit 0 |
| 24 | + elif [[ ! "$1" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[A-Za-z0-9-]+)? ]]; then |
| 25 | + echo "❌ Invalid version: $1. Aborting" |
| 26 | + exit 1 |
| 27 | + fi |
| 28 | +} |
| 29 | + |
| 30 | +function confirmContinue() { |
| 31 | + local continueConfirmation="n" |
| 32 | + read -p "Continue (y/n)? " continueConfirmation |
| 33 | + if [[ "$continueConfirmation" != "y" ]]; then |
| 34 | + echo "⚠️ Aborting." |
| 35 | + exit 0 |
| 36 | + fi |
| 37 | +} |
| 38 | + |
| 39 | +if [[ -n $(git status -s) ]]; then |
| 40 | + echo "⚠️ There are uncommited changes, make sure this is what you want." |
| 41 | + git status |
| 42 | + confirmContinue |
| 43 | +fi |
| 44 | + |
| 45 | +headTag=$(git describe --tags --exact-match 2> /dev/null || :) |
| 46 | +if [[ "$headTag" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[A-Za-z0-9-]+)? ]]; then |
| 47 | + releaseVersion=$(echo $headTag | sed -e s/^v//) |
| 48 | + echo "💡 The current HEAD is at tag $headTag. The release version is set to $releaseVersion." |
| 49 | +else |
| 50 | + echo "⚠️ The current HEAD does not correspond to a tag." |
| 51 | + read -p "Enter a version number to build a release from the current HEAD (leave empty to abort): " releaseVersion |
| 52 | + checkValidVersion $releaseVersion |
| 53 | +fi |
| 54 | + |
| 55 | +setVersion='set every version := "'$releaseVersion'"' |
| 56 | + |
| 57 | +echo "💡 Please specify the Scala version for building the release." |
| 58 | +read -p "Enter '+' to cross-build against all versions in build.sbt's 'crossScalaVersions': " scalaVersionInput |
| 59 | + |
| 60 | +if [[ "$scalaVersionInput" == "+" ]]; then |
| 61 | + testTarget="+test" |
| 62 | + publishTarget="+publish-signed" |
| 63 | +else |
| 64 | + checkValidVersion $scalaVersionInput |
| 65 | + testTarget="test" |
| 66 | + publishTarget="publish-signed" |
| 67 | + setScalaVersion='set every scalaVersion := "'$scalaVersionInput'"' |
| 68 | +fi |
| 69 | + |
| 70 | +# ignore non-matching lines according to http://stackoverflow.com/questions/1665549/have-sed-ignore-non-matching-lines#comment19412026_1665662 |
| 71 | +javaVersion=`java -version 2>&1 | sed -e 's/java version "\(.*\)"/\1/' -e 'tx' -e 'd' -e ':x'` |
| 72 | + |
| 73 | +if [[ "$scalaVersionInput" == "+" ]]; then |
| 74 | + scalaVersionInfo=" using the Scala versions in build.sbt's 'crossScalaVersions'" |
| 75 | +else |
| 76 | + echo "💡 The current Java version is $javaVersion. Make sure to use 1.6 for Scala <2.12, 1.8 for Scala >=2.12." |
| 77 | + scalaVersionInfo=" using Scala $scalaVersionInput" |
| 78 | +fi |
| 79 | + |
| 80 | +echo "⚠️ About to release $repositoryName version $releaseVersion$scalaVersionInfo on Java $javaVersion." |
| 81 | +confirmContinue |
| 82 | + |
| 83 | +cp admin/gpg.sbt ./project |
| 84 | +cp admin/publish-manual-settings.sbt . |
| 85 | + |
| 86 | +echo "Running: sbt \"$setScalaVersion\" \"$setVersion\" clean update $testTarget $publishTarget" |
| 87 | +sbt "$setScalaVersion" "$setVersion" clean update $testTarget $publishTarget |
| 88 | + |
| 89 | +rm ./project/gpg.sbt |
| 90 | +rm ./publish-manual-settings.sbt |
0 commit comments