Skip to content

Commit 6afb291

Browse files
committed
Use scala-module-plugin, update tag-based publishing
The build didn't use the `scala-module-plugin` before but duplicated most of its settings - maybe I missed the reason why this is the case? Also update tag-based publishing to the latest version.
1 parent 605760d commit 6afb291

17 files changed

+226
-205
lines changed

.travis.yml

+9-15
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,17 @@ language: scala
22
sudo: false
33
env:
44
global:
5-
# Don't commit sensitive files, instead commit a version encrypted with $SECRET,
6-
# this environment variable is encrypted with this repo's private key and stored below:
7-
# (See http://docs.travis-ci.com/user/environment-variables/#Secure-Variables.)
8-
- secure: "YO/7YiWEirzz0EAy7oVNmAKroj4qCLZNMkPS+xW/VgeGjuEV+Nk1S7pwxF0o2OggSxIQ+a0lWSrOPQqSXMjOstDIzzGeYfuAt0+0fupXtDDge0mXpCCMadrvYzff1/5XYX0dJ+pjJmz6IgF1hliPJHIuddhhdqPxdHWTHAKm9ME="
9-
5+
# PGP_PASSPHRASE
6+
- secure: "ENsi/6s/RXiPqrfrU7kXqaDz8WiZeenQMhaSFshxbueJ8EtN20FIVt4rSM8HOpLbn1pYeq6PiQ7T2mxlsaJMWCUNud9CqOxgSH9vCoYkJJy6CkTIVLLKdu5teHVIzWcl3smbk7LZYv/4FuljBqYs9EecWjuYF7dZrY/otE5kKbA="
7+
# SONA_USER
8+
- secure: "cQAs8Q/a2YrqzRv3+QAiHchLac35Ppu7rppwJs2favmVJFL0SIBtPu891UiPy0V/3QN1JmwPLbsR/lsgpoGM76AMCn3rgq88zp45pD+UiH0d7dgFMzXorNGt3K+YpiW4j6iHyzM/POKVO7vLnRuln6jTE0QRcjRbEOqg+xtQo+I="
9+
# SONA_PASS
10+
- secure: "Cj4PsumsWL37Pl7V5ZPJw+/xH9esHblG5nN9Op91XcCfG006xHsz2w1iNOqFqCF8wAhgObuA2CmAH3ZuI1jZGGSo2HMt9+f5Z6tpifFzsTHZJtdNIVOpS3/NGhvgtg3UnT5WQQtnVi6zlkKl1xCpAIDNhOJ9dXoL54auAqvxpko="
1011
script:
1112
- admin/build.sh
12-
matrix:
13-
include:
14-
- scala: 2.11.8
15-
jdk: openjdk6
16-
env: IS_PUBLISH_JDK=true
17-
- scala: 2.11.8
18-
jdk: oraclejdk8
19-
- scala: 2.12.0
20-
jdk: oraclejdk8
21-
env: IS_PUBLISH_JDK=true
13+
jdk:
14+
- openjdk6
15+
- oraclejdk8
2216
notifications:
2317
email:
2418

admin/README.md

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
## Tag Driven Releasing
2+
3+
### Background Reading
4+
5+
- http://docs.travis-ci.com/user/environment-variables/
6+
- http://docs.travis-ci.com/user/encryption-keys/
7+
- http://docs.travis-ci.com/user/encrypting-files/
8+
9+
### Initial setup for the repository
10+
11+
To configure tag driven releases from Travis CI.
12+
13+
1. Generate a key pair for this repository with `./admin/genKeyPair.sh`.
14+
Edit `.travis.yml` and `admin/build.sh` as prompted.
15+
1. Publish the public key to https://pgp.mit.edu
16+
1. Store other secrets as encrypted environment variables with `admin/encryptEnvVars.sh`.
17+
Edit `.travis.yml` as prompted.
18+
1. Edit `.travis.yml` to use `./admin/build.sh` as the build script,
19+
and edit that script to use the tasks required for this project.
20+
1. Edit `build.sbt`'s `scalaVersionsByJvm in ThisBuild` to select Scala and JVM version
21+
combinations that will be used for publishing.
22+
23+
It is important to add comments in `.travis.yml` to identify the name
24+
of each environment variable encoded in a `:secure` section.
25+
26+
After these steps, your `.travis.yml` should contain config of the form:
27+
28+
```
29+
language: scala
30+
31+
env:
32+
global:
33+
# PGP_PASSPHRASE
34+
- secure: "XXXXXX"
35+
# SONA_USER
36+
- secure: "XXXXXX"
37+
# SONA_PASS
38+
- secure: "XXXXXX"
39+
40+
script: admin/build.sh
41+
42+
jdk:
43+
- openjdk6
44+
- oraclejdk8
45+
46+
notifications:
47+
email:
48+
49+
```
50+
51+
If Sonatype credentials change in the future, step 3 can be repeated
52+
without generating a new key.
53+
54+
### Testing
55+
56+
1. Follow the release process below to create a dummy release (e.g., `v0.1.0-TEST1`).
57+
Confirm that the release was staged to Sonatype but do not release it to Maven
58+
central. Instead, drop the staging repository.
59+
60+
### Performing a release
61+
62+
1. Create a GitHub "Release" with a corresponding tag (e.g., `v0.1.1`) via the GitHub
63+
web interface.
64+
1. The release will be published using the Scala and JVM version combinations specified
65+
in `scalaVersionsByJvm` in `build.sbt`.
66+
- If you need to release against a different Scala version, include the Scala version
67+
and the JVM version to use in the tag name, separated by `#`s (e.g., `v0.1.1#2.13.0-M1#8`).
68+
Note that the JVM version needs to be listed in `.travis.yml` for the build to run.
69+
1. Travis CI will schedule a build for this release. Review the build logs.
70+
1. Log into https://oss.sonatype.org/ and identify the staging repository.
71+
1. Sanity check its contents.
72+
1. Release staging repository to Maven and send out release announcement.

admin/build.sh

+45-11
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,53 @@
11
#!/bin/bash
22

3-
# prep environment for publish to sonatype staging if the HEAD commit is tagged
3+
set -e
44

5-
# git on travis does not fetch tags, but we have TRAVIS_TAG
6-
# headTag=$(git describe --exact-match ||:)
5+
# Builds of tagged revisions are published to sonatype staging.
76

8-
if [ "$IS_PUBLISH_JDK" == "true" ] && [[ "$TRAVIS_TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[A-Za-z0-9-]+)? ]]; then
9-
echo "Going to release from tag $TRAVIS_TAG!"
10-
myVer=$(echo $TRAVIS_TAG | sed -e s/^v// | sed -e 's/_[0-9]*\.[0-9]*//')
11-
publishVersion='set every version := "'$myVer'"'
12-
extraTarget="publish-signed"
7+
# Travis runs a build on new revisions and on new tags, so a tagged revision is built twice.
8+
# Builds for a tag have TRAVIS_TAG defined, which we use for identifying tagged builds.
9+
# Checking the local git clone would not work because git on travis does not fetch tags.
1310

11+
# The version number to be published is extracted from the tag, e.g., v1.2.3 publishes
12+
# version 1.2.3 using all Scala versions in build.sbt's `crossScalaVersions`.
13+
14+
# When a new, binary incompatible Scala version becomes available, a previously released version
15+
# can be released using that new Scala version by creating a new tag containing the Scala and the
16+
# JVM version after hashes, e.g., v1.2.3#2.13.0-M1#8. The JVM version needs to be listed in
17+
# `.travis.yml`, otherwise the required build doesn't run.
18+
19+
verPat="[0-9]+\.[0-9]+\.[0-9]+(-[A-Za-z0-9-]+)?"
20+
tagPat="^v$verPat(#$verPat#[0-9]+)?$"
21+
22+
if [[ "$TRAVIS_TAG" =~ $tagPat ]]; then
23+
currentJvmVer=$(java -version 2>&1 | awk -F '"' '/version/ {print $2}' | sed 's/^1\.//' | sed 's/[^0-9].*//')
24+
25+
tagVer=$(echo $TRAVIS_TAG | sed s/#.*// | sed s/^v//)
26+
publishVersion='set every version := "'$tagVer'"'
27+
28+
scalaAndJvmVer=$(echo $TRAVIS_TAG | sed s/[^#]*// | sed s/^#//)
29+
if [ "$scalaAndJvmVer" != "" ]; then
30+
scalaVer=$(echo $scalaAndJvmVer | sed s/#.*//)
31+
jvmVer=$(echo $scalaAndJvmVer | sed s/[^#]*// | sed s/^#//)
32+
if [ "$jvmVer" != "$currentJvmVer" ]; then
33+
echo "Not publishing $TRAVIS_TAG on Java version $currentJvmVer."
34+
exit 0
35+
fi
36+
publishScalaVersion='set every ScalaModulePlugin.scalaVersionsByJvm := Map('$jvmVer' -> List("'$scalaVer'" -> true))'
37+
echo "Releasing $tagVer using Scala $scalaVer on Java version $jvmVer."
38+
else
39+
echo "Releasing $tagVer on Java version $currentJvmVer according to 'scalaVersionsByJvm' in build.sbt."
40+
fi
41+
42+
extraTarget="+publish-signed"
1443
cat admin/gpg.sbt >> project/plugins.sbt
15-
admin/decrypt.sh sensitive.sbt
16-
(cd admin/ && ./decrypt.sh secring.asc)
44+
cp admin/publish-settings.sbt .
45+
46+
# Copied from the output of genKeyPair.sh
47+
K=$encrypted_97ebac4c5d62_key
48+
IV=$encrypted_97ebac4c5d62_iv
49+
50+
openssl aes-256-cbc -K $K -iv $IV -in admin/secring.asc.enc -out admin/secring.asc -d
1751
fi
1852
19-
sbt ++$TRAVIS_SCALA_VERSION "$publishVersion" clean update compile test $extraTarget
53+
sbt "$publishVersion" "$publishScalaVersion" clean update +test +publishLocal $extraTarget

admin/decrypt.sh

-2
This file was deleted.

admin/encrypt.sh

-2
This file was deleted.

admin/encryptAll.sh

-19
This file was deleted.

admin/encryptEnvVars.sh

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
#
3+
# Encrypt sonatype credentials so that they can be
4+
# decrypted in trusted builds on Travis CI.
5+
#
6+
set -e
7+
8+
read -s -p 'SONA_USER: ' SONA_USER
9+
travis encrypt SONA_USER="$SONA_USER"
10+
read -s -p 'SONA_PASS: ' SONA_PASS
11+
travis encrypt SONA_PASS="$SONA_PASS"

admin/genKeyPair.sh

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
#
3+
# Generates a key pair for this repository to sign artifacts.
4+
# Encrypt the private key and its passphrase in trusted builds
5+
# on Travis CI.
6+
#
7+
set -e
8+
9+
# Based on https://gist.github.com/kzap/5819745:
10+
function promptDelete() {
11+
if [[ -f "$1" ]]; then
12+
echo About to delete $1, Enter for okay / CTRL-C to cancel
13+
read
14+
rm "$1"
15+
fi
16+
}
17+
for f in admin/secring.asc.enc admin/secring.asc admin/pubring.asc; do promptDelete "$f"; done
18+
19+
echo Generating key pair. Please enter 1. repo name 2. [email protected], 3. a new passphrase
20+
echo Be careful when using special characters in the passphrase, see http://docs.travis-ci.com/user/encryption-keys/#Note-on-escaping-certain-symbols
21+
cp admin/gpg.sbt project
22+
sbt 'set pgpReadOnly := false' \
23+
'set pgpPublicRing := file("admin/pubring.asc")' \
24+
'set pgpSecretRing := file("admin/secring.asc")' \
25+
'pgp-cmd gen-key'
26+
rm project/gpg.sbt
27+
28+
echo ============================================================================================
29+
echo Encrypting admin/secring.asc. Update K and IV variables in admin/build.sh accordingly.
30+
echo ============================================================================================
31+
travis encrypt-file admin/secring.asc
32+
rm admin/secring.asc
33+
mv secring.asc.enc admin
34+
35+
echo ============================================================================================
36+
echo Encrypting environment variables. Add each to a line in .travis.yml. Include a comment
37+
echo with the name of the corresponding variable
38+
echo ============================================================================================
39+
read -s -p 'PGP_PASSPHRASE: ' PGP_PASSPHRASE
40+
travis encrypt PGP_PASSPHRASE="$PGP_PASSPHRASE"
41+

admin/gpg.sbt

+1-25
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,2 @@
11

2-
addSbtPlugin("com.typesafe.sbt" % "sbt-pgp" % "0.8.3") // only added when publishing:
3-
4-
// There's a companion sensitive.sbt, which was created like this:
5-
//
6-
// 1. in an sbt shell that has the sbt-pgp plugin, create pgp key in admin/:
7-
//
8-
// sbt
9-
// set pgpReadOnly := false
10-
// set pgpPublicRing := file("admin/pubring.asc")
11-
// set pgpSecretRing := file("admin/secring.asc")
12-
// pgp-cmd gen-key // use $passPhrase
13-
// Please enter the name associated with the key: $repoName
14-
// Please enter the email associated with the key: [email protected]
15-
// Please enter the passphrase for the key: $passphrase
16-
//
17-
// 2. create sensitive.sbt with contents:
18-
//
19-
// pgpPassphrase := Some($passPhrase.toArray)
20-
//
21-
// pgpPublicRing := file("admin/pubring.asc")
22-
//
23-
// pgpSecretRing := file("admin/secring.asc")
24-
//
25-
// credentials += Credentials("Sonatype Nexus Repository Manager", "oss.sonatype.org", $sonaUser, $sonaPass)
26-
2+
addSbtPlugin("com.typesafe.sbt" % "sbt-pgp" % "0.8.3") // only added when publishing, see build.sh

admin/publish-settings.sbt

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
def env(key: String) = Option(System.getenv(key)).getOrElse("")
2+
3+
pgpPassphrase := Some(env("PGP_PASSPHRASE").toArray)
4+
5+
pgpPublicRing := file("admin/pubring.asc")
6+
7+
pgpSecretRing := file("admin/secring.asc")
8+
9+
credentials += Credentials("Sonatype Nexus Repository Manager", "oss.sonatype.org", env("SONA_USER"), env("SONA_PASS"))

admin/pubring.asc

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18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Zb+TvPsesLw6HI82oqsSIEl4C8bsy/jH6f3kOnxiUTYYEt5yL9G7P3DyE
7+
5z2sLOapOofIZeyUBU90pT4Km/09hI0AaWaHYQRRVVFhA5RlxidEB5X4eQ6QLA7C
8+
D6iiKtou/Jg0iWY/1aliCwkZHm9J4x8zoQpSvKKaODhKaDia55ltkC5w2sT6xdnK
9+
Q2yasSbHp/RHCFE3jN8AN4CwIy5UWconsi7fABEBAAG0KGFzeW5jIDxzY2FsYS1p
10+
bnRlcm5hbHNAZ29vZ2xlZ3JvdXBzLmNvbT6JARwEEwECAAYFAlkAWsEACgkQOqT/
11+
ZELU8HwpgwgAhbwhNUKSLWK+75rVCEBdwgIgr0gYDXWnFURdAoubIT+3BWy3WZwB
12+
DkceCM2yssnKxxJYd07xvFyNVVZRofmgi/A7qq7XFt3PIxd6NDytbWtHf0Y4N3AI
13+
oksJpsHZDJBz2O06WGROi9tisIB/JypsGX5YmY0DJBnUU7zZIHE/DC0+83eB2DlM
14+
Irxguyrd7J6/jDpNWKhLoWRdsGkeukbxExFUP99yRJ+K+itUHIWAe6/pGUNINW7E
15+
HgDmDBUtyiYNlwVU43CgAHUuqL6U+bZwUBPmd5Ru7aNJ30Nrd42cuw5GmJk7CLHN
16+
dVUFP89RuQEioYdcgfDOIRo9rUyJ8fq+Zw==
17+
=9prU
1818
-----END PGP PUBLIC KEY BLOCK-----

admin/secring.asc.enc

-679 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)