-
Notifications
You must be signed in to change notification settings - Fork 1
/
release.sh
executable file
·53 lines (43 loc) · 1.79 KB
/
release.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env bash
set -euo pipefail
get_release_version() {
local VERSION_SBT
VERSION_SBT=$(cat ./version.sbt) || exit $?
local REGEX='ThisBuild / version := "([^"]+)"'
if [[ $VERSION_SBT =~ $REGEX ]]; then
local CURRENT_VERSION="${BASH_REMATCH[1]}"
if [[ $CURRENT_VERSION =~ -SNAPSHOT$ ]]; then
CURRENT_VERSION=${CURRENT_VERSION/-SNAPSHOT/}
local GIT_SHA
local GIT_COMMIT_COUNT
local SHORTENED_COMMIT_SHA
GIT_SHA=$(git rev-parse HEAD) || exit $?
SHORTENED_COMMIT_SHA=$(echo "${GIT_SHA}" | cut -c 1-7) || exit $?
GIT_COMMIT_COUNT=$(git rev-list --count HEAD) || exit $?
echo "${CURRENT_VERSION}+${GIT_COMMIT_COUNT}-${SHORTENED_COMMIT_SHA}-SNAPSHOT"
else
echo "${CURRENT_VERSION}"
fi
else
echo >&2 "Cannot determine version from version.sbt"
exit 1
fi
}
publish() {
local SONATYPE_USERNAME=${SONATYPE_USERNAME:?"SONATYPE_USERNAME is required"}
local SONATYPE_PASSWORD=${SONATYPE_PASSWORD:?"SONATYPE_PASSWORD is required"}
local PGP_SIGNING_KEY_FP=${PGP_SIGNING_KEY_FP:?"PGP_SIGNING_KEY_FP is required"}
local RELEASE_VERSION
RELEASE_VERSION=$("$0" get_release_version) || exit $?
sbt --client "set ThisBuild / version := \"${RELEASE_VERSION}\""
sbt --client 'set ThisBuild / publishTo := sonatypePublishToBundle.value'
sbt --client 'set ThisBuild / sonatypeCredentialHost := "s01.oss.sonatype.org"'
sbt --client "set ThisBuild / credentials += Credentials(\"Sonatype Nexus Repository Manager\", \"s01.oss.sonatype.org\", \"${SONATYPE_USERNAME}\", \"${SONATYPE_PASSWORD}\")"
sbt --client "set Global / pgpSigningKey := Some(\"${PGP_SIGNING_KEY_FP}\")"
sbt --client sonatypeBundleClean
sbt --client publishSigned
if [[ ! $RELEASE_VERSION =~ -SNAPSHOT$ ]]; then
sbt --client sonatypeBundleRelease
fi
}
"$@"