Skip to content

Use scala-module-plugin, update tag-based publishing #170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 9 additions & 15 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,17 @@ language: scala
sudo: false
env:
global:
# Don't commit sensitive files, instead commit a version encrypted with $SECRET,
# this environment variable is encrypted with this repo's private key and stored below:
# (See http://docs.travis-ci.com/user/environment-variables/#Secure-Variables.)
- secure: "YO/7YiWEirzz0EAy7oVNmAKroj4qCLZNMkPS+xW/VgeGjuEV+Nk1S7pwxF0o2OggSxIQ+a0lWSrOPQqSXMjOstDIzzGeYfuAt0+0fupXtDDge0mXpCCMadrvYzff1/5XYX0dJ+pjJmz6IgF1hliPJHIuddhhdqPxdHWTHAKm9ME="

# PGP_PASSPHRASE
- secure: "ENsi/6s/RXiPqrfrU7kXqaDz8WiZeenQMhaSFshxbueJ8EtN20FIVt4rSM8HOpLbn1pYeq6PiQ7T2mxlsaJMWCUNud9CqOxgSH9vCoYkJJy6CkTIVLLKdu5teHVIzWcl3smbk7LZYv/4FuljBqYs9EecWjuYF7dZrY/otE5kKbA="
# SONA_USER
- secure: "cQAs8Q/a2YrqzRv3+QAiHchLac35Ppu7rppwJs2favmVJFL0SIBtPu891UiPy0V/3QN1JmwPLbsR/lsgpoGM76AMCn3rgq88zp45pD+UiH0d7dgFMzXorNGt3K+YpiW4j6iHyzM/POKVO7vLnRuln6jTE0QRcjRbEOqg+xtQo+I="
# SONA_PASS
- secure: "Cj4PsumsWL37Pl7V5ZPJw+/xH9esHblG5nN9Op91XcCfG006xHsz2w1iNOqFqCF8wAhgObuA2CmAH3ZuI1jZGGSo2HMt9+f5Z6tpifFzsTHZJtdNIVOpS3/NGhvgtg3UnT5WQQtnVi6zlkKl1xCpAIDNhOJ9dXoL54auAqvxpko="
script:
- admin/build.sh
matrix:
include:
- scala: 2.11.8
jdk: openjdk6
env: IS_PUBLISH_JDK=true
- scala: 2.11.8
jdk: oraclejdk8
- scala: 2.12.0
jdk: oraclejdk8
env: IS_PUBLISH_JDK=true
jdk:
- openjdk6
- oraclejdk8
notifications:
email:
- [email protected]
Expand Down
72 changes: 72 additions & 0 deletions admin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
## Tag Driven Releasing

### Background Reading

- http://docs.travis-ci.com/user/environment-variables/
- http://docs.travis-ci.com/user/encryption-keys/
- http://docs.travis-ci.com/user/encrypting-files/

### Initial setup for the repository

To configure tag driven releases from Travis CI.

1. Generate a key pair for this repository with `./admin/genKeyPair.sh`.
Edit `.travis.yml` and `admin/build.sh` as prompted.
1. Publish the public key to https://pgp.mit.edu
1. Store other secrets as encrypted environment variables with `admin/encryptEnvVars.sh`.
Edit `.travis.yml` as prompted.
1. Edit `.travis.yml` to use `./admin/build.sh` as the build script,
and edit that script to use the tasks required for this project.
1. Edit `build.sbt`'s `scalaVersionsByJvm in ThisBuild` to select Scala and JVM version
combinations that will be used for publishing.

It is important to add comments in `.travis.yml` to identify the name
of each environment variable encoded in a `:secure` section.

After these steps, your `.travis.yml` should contain config of the form:

```
language: scala

env:
global:
# PGP_PASSPHRASE
- secure: "XXXXXX"
# SONA_USER
- secure: "XXXXXX"
# SONA_PASS
- secure: "XXXXXX"

script: admin/build.sh

jdk:
- openjdk6
- oraclejdk8

notifications:
email:
- [email protected]
```

If Sonatype credentials change in the future, step 3 can be repeated
without generating a new key.

### Testing

1. Follow the release process below to create a dummy release (e.g., `v0.1.0-TEST1`).
Confirm that the release was staged to Sonatype but do not release it to Maven
central. Instead, drop the staging repository.

### Performing a release

1. Create a GitHub "Release" with a corresponding tag (e.g., `v0.1.1`) via the GitHub
web interface.
1. The release will be published using the Scala and JVM version combinations specified
in `scalaVersionsByJvm` in `build.sbt`.
- If you need to release against a different Scala version, include the Scala version
and the JVM version to use in the tag name, separated by `#`s (e.g., `v0.1.1#2.13.0-M1#8`).
Note that the JVM version needs to be listed in `.travis.yml` for the build to run.
1. Travis CI will schedule a build for this release. Review the build logs.
1. Log into https://oss.sonatype.org/ and identify the staging repository.
1. Sanity check its contents.
1. Release staging repository to Maven and send out release announcement.
56 changes: 45 additions & 11 deletions admin/build.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,53 @@
#!/bin/bash

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

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

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

# The version number to be published is extracted from the tag, e.g., v1.2.3 publishes
# version 1.2.3 using all Scala versions in build.sbt's `crossScalaVersions`.

# When a new, binary incompatible Scala version becomes available, a previously released version
# can be released using that new Scala version by creating a new tag containing the Scala and the
# JVM version after hashes, e.g., v1.2.3#2.13.0-M1#8. The JVM version needs to be listed in
# `.travis.yml`, otherwise the required build doesn't run.

verPat="[0-9]+\.[0-9]+\.[0-9]+(-[A-Za-z0-9-]+)?"
tagPat="^v$verPat(#$verPat#[0-9]+)?$"

if [[ "$TRAVIS_TAG" =~ $tagPat ]]; then
currentJvmVer=$(java -version 2>&1 | awk -F '"' '/version/ {print $2}' | sed 's/^1\.//' | sed 's/[^0-9].*//')

tagVer=$(echo $TRAVIS_TAG | sed s/#.*// | sed s/^v//)
publishVersion='set every version := "'$tagVer'"'

scalaAndJvmVer=$(echo $TRAVIS_TAG | sed s/[^#]*// | sed s/^#//)
if [ "$scalaAndJvmVer" != "" ]; then
scalaVer=$(echo $scalaAndJvmVer | sed s/#.*//)
jvmVer=$(echo $scalaAndJvmVer | sed s/[^#]*// | sed s/^#//)
if [ "$jvmVer" != "$currentJvmVer" ]; then
echo "Not publishing $TRAVIS_TAG on Java version $currentJvmVer."
exit 0
fi
publishScalaVersion='set every ScalaModulePlugin.scalaVersionsByJvm := Map('$jvmVer' -> List("'$scalaVer'" -> true))'
echo "Releasing $tagVer using Scala $scalaVer on Java version $jvmVer."
else
echo "Releasing $tagVer on Java version $currentJvmVer according to 'scalaVersionsByJvm' in build.sbt."
fi

extraTarget="+publish-signed"
cat admin/gpg.sbt >> project/plugins.sbt
admin/decrypt.sh sensitive.sbt
(cd admin/ && ./decrypt.sh secring.asc)
cp admin/publish-settings.sbt .

# Copied from the output of genKeyPair.sh
K=$encrypted_97ebac4c5d62_key
IV=$encrypted_97ebac4c5d62_iv

openssl aes-256-cbc -K $K -iv $IV -in admin/secring.asc.enc -out admin/secring.asc -d
fi

sbt ++$TRAVIS_SCALA_VERSION "$publishVersion" clean update compile test $extraTarget
sbt "$publishVersion" "$publishScalaVersion" clean update +test +publishLocal $extraTarget
2 changes: 0 additions & 2 deletions admin/decrypt.sh

This file was deleted.

2 changes: 0 additions & 2 deletions admin/encrypt.sh

This file was deleted.

19 changes: 0 additions & 19 deletions admin/encryptAll.sh

This file was deleted.

11 changes: 11 additions & 0 deletions admin/encryptEnvVars.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
#
# Encrypt sonatype credentials so that they can be
# decrypted in trusted builds on Travis CI.
#
set -e

read -s -p 'SONA_USER: ' SONA_USER
travis encrypt SONA_USER="$SONA_USER"
read -s -p 'SONA_PASS: ' SONA_PASS
travis encrypt SONA_PASS="$SONA_PASS"
41 changes: 41 additions & 0 deletions admin/genKeyPair.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash
#
# Generates a key pair for this repository to sign artifacts.
# Encrypt the private key and its passphrase in trusted builds
# on Travis CI.
#
set -e

# Based on https://gist.github.com/kzap/5819745:
function promptDelete() {
if [[ -f "$1" ]]; then
echo About to delete $1, Enter for okay / CTRL-C to cancel
read
rm "$1"
fi
}
for f in admin/secring.asc.enc admin/secring.asc admin/pubring.asc; do promptDelete "$f"; done

echo Generating key pair. Please enter 1. repo name 2. [email protected], 3. a new passphrase
echo Be careful when using special characters in the passphrase, see http://docs.travis-ci.com/user/encryption-keys/#Note-on-escaping-certain-symbols
cp admin/gpg.sbt project
sbt 'set pgpReadOnly := false' \
'set pgpPublicRing := file("admin/pubring.asc")' \
'set pgpSecretRing := file("admin/secring.asc")' \
'pgp-cmd gen-key'
rm project/gpg.sbt

echo ============================================================================================
echo Encrypting admin/secring.asc. Update K and IV variables in admin/build.sh accordingly.
echo ============================================================================================
travis encrypt-file admin/secring.asc
rm admin/secring.asc
mv secring.asc.enc admin

echo ============================================================================================
echo Encrypting environment variables. Add each to a line in .travis.yml. Include a comment
echo with the name of the corresponding variable
echo ============================================================================================
read -s -p 'PGP_PASSPHRASE: ' PGP_PASSPHRASE
travis encrypt PGP_PASSPHRASE="$PGP_PASSPHRASE"

26 changes: 1 addition & 25 deletions admin/gpg.sbt
Original file line number Diff line number Diff line change
@@ -1,26 +1,2 @@

addSbtPlugin("com.typesafe.sbt" % "sbt-pgp" % "0.8.3") // only added when publishing:

// There's a companion sensitive.sbt, which was created like this:
//
// 1. in an sbt shell that has the sbt-pgp plugin, create pgp key in admin/:
//
// sbt
// set pgpReadOnly := false
// set pgpPublicRing := file("admin/pubring.asc")
// set pgpSecretRing := file("admin/secring.asc")
// pgp-cmd gen-key // use $passPhrase
// Please enter the name associated with the key: $repoName
// Please enter the email associated with the key: [email protected]
// Please enter the passphrase for the key: $passphrase
//
// 2. create sensitive.sbt with contents:
//
// pgpPassphrase := Some($passPhrase.toArray)
//
// pgpPublicRing := file("admin/pubring.asc")
//
// pgpSecretRing := file("admin/secring.asc")
//
// credentials += Credentials("Sonatype Nexus Repository Manager", "oss.sonatype.org", $sonaUser, $sonaPass)

addSbtPlugin("com.typesafe.sbt" % "sbt-pgp" % "0.8.3") // only added when publishing, see build.sh
9 changes: 9 additions & 0 deletions admin/publish-settings.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
def env(key: String) = Option(System.getenv(key)).getOrElse("")

pgpPassphrase := Some(env("PGP_PASSPHRASE").toArray)

pgpPublicRing := file("admin/pubring.asc")

pgpSecretRing := file("admin/secring.asc")

credentials += Credentials("Sonatype Nexus Repository Manager", "oss.sonatype.org", env("SONA_USER"), env("SONA_PASS"))
28 changes: 14 additions & 14 deletions admin/pubring.asc
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: BCPG v1.49

mQENBFSScxABCACj8nAMNdPBgCihD2b+ngYhQaIOmhPEG0Z394T1Qg8EawWhaWXH
50A3NaA5jc1+UJSQ0xyzB/95xCvTCCgWgo2q3L+hIQKoIif+7MfMCrw7CsZSuGFg
Jv46saoBvLBoeiSCI7cFYrQNh+gfTypgGtFu/BBjeIpl6RKQ1gyUdPSb0Nh/2hk9
7ZdApoJ4PhLnEAB5ZA8YnakBicBMF8GRGEwBgA/Mw/ADGqGA9rYxcl/BT65dEbrV
onDDZUc1NCcMoHnpnzLzLnrYH0QK1GbE+UZ9eesQUts7ICTO/+YCpAYxHAqdCynF
mMHY86yXanF1AK8blGxeIagiLY1kJ9C/iUr1ABEBAAG0KGFzeW5jIDxzY2FsYS1p
bnRlcm5hbHNAZ29vZ2xlZ3JvdXBzLmNvbT6JARwEEwECAAYFAlSScxAACgkQhxTM
1mIV232f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
HgDmDBUtyiYNlwVU43CgAHUuqL6U+bZwUBPmd5Ru7aNJ30Nrd42cuw5GmJk7CLHN
dVUFP89RuQEioYdcgfDOIRo9rUyJ8fq+Zw==
=9prU
-----END PGP PUBLIC KEY BLOCK-----
Binary file modified admin/secring.asc.enc
Binary file not shown.
Loading