Skip to content

Commit 9e674f1

Browse files
committed
Support for tag-driven publishing on Travis.
Modify travis build to derive the project version from TRAVIS_TAG (when set). as well as to have sbt run the `publish-signed` task if the environment is right. The tag must match the semver regex `^v[0-9]+\.[0-9]+\.[0-9]+(-[A-Za-z0-9-]+)?`, and the jdk we're running on must match PUBLISH_JDK (set in .travis.yml). For every repo, you must create the following files (not included here) according to the instructions in admin/gpg.sbt: - admin/pubring.asc (commit) - admin/secring.asc (DO NOT COMMIT) - sensitive.sbt (DO NOT COMMIT) - passphrase for secring.asc - api token for staging to sonatype Generate these using `admin/encryptAll.sh`: - admin/secring.asc.enc (commit) - sensitive.sbt.enc (commit) Note that `encryptAll.sh` spits out a "- secure .... " line, that you need to add to `.travis.yml`'s `env` section, so that travis can supply the SECRET env variable, which is used to decrypt the sensitive files above.
1 parent 0154ff8 commit 9e674f1

File tree

6 files changed

+73
-1
lines changed

6 files changed

+73
-1
lines changed

Diff for: .travis.yml

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
language: scala
2+
3+
env:
4+
global:
5+
- PUBLISH_JDK=openjdk6 # admin/build.sh only publishes when running on this jdk
6+
# Don't commit sensitive files, instead commit a version encrypted with $SECRET,
7+
# this environment variable is encrypted with this repo's private key and stored below:
8+
# (See http://docs.travis-ci.com/user/environment-variables/#Secure-Variables.)
9+
# - secure: <generated by encryptAll.sh>
10+
211
script:
3-
- sbt ++$TRAVIS_SCALA_VERSION clean update compile test
12+
- admin/build.sh
413
scala:
514
- 2.11.4
615
jdk:

Diff for: admin/build.sh

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
# prep environment for publish to sonatype staging if the HEAD commit is tagged
4+
5+
# git on travis does not fetch tags, but we have TRAVIS_TAG
6+
# headTag=$(git describe --exact-match ||:)
7+
8+
if [ "$TRAVIS_JDK_VERSION" == "$PUBLISH_JDK" ] && [[ "$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//)
11+
publishVersion='set every version := "'$myVer'"'
12+
extraTarget="publish-signed"
13+
14+
cat admin/gpg.sbt >> project/plugins.sbt
15+
admin/decrypt.sh sensitive.sbt
16+
(cd admin/ && ./decrypt.sh secring.asc)
17+
fi
18+
19+
sbt ++$TRAVIS_SCALA_VERSION "$publishVersion" clean update compile test $extraTarget

Diff for: admin/decrypt.sh

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
openssl aes-256-cbc -pass "pass:$SECRET" -in $1.enc -out $1 -d -a

Diff for: admin/encrypt.sh

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
openssl aes-256-cbc -pass "pass:$SECRET" -in $1 -out $1.enc -a

Diff for: admin/encryptAll.sh

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
# Based on https://gist.github.com/kzap/5819745:
4+
5+
echo "This will encrypt the cleartext sensitive.sbt and admin/secring.asc, while making the encrypted versions available for decryption on Travis."
6+
echo "Update your .travis.yml as directed, and delete the cleartext versions."
7+
echo "Press enter to continue."
8+
read
9+
10+
# 1. create a secret, put it in an environment variable while encrypting files -- UNSET IT AFTER
11+
export SECRET=$(cat /dev/urandom | head -c 10000 | openssl sha1)
12+
13+
# 2. add the "secure: ..." line under the env section -- generate it with `` (install the travis gem first)
14+
travis encrypt SECRET=$SECRET
15+
16+
admin/encrypt.sh admin/secring.asc
17+
admin/encrypt.sh sensitive.sbt
18+
19+
echo "Remember to rm sensitive.sbt admin/secring.asc -- once you do, they cannot be recovered (except on Travis)!"

Diff for: admin/gpg.sbt

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// only added when publishing:
2+
addSbtPlugin("com.typesafe.sbt" % "sbt-pgp" % "0.8.3")
3+
4+
/* There's a companion sensitive.sbt, which was created like this:
5+
6+
1. in an sbt shell when sbt-gpg is loaded, create pgp key in admin/:
7+
8+
set pgpReadOnly := false
9+
pgp-cmd gen-key // use $passPhrase
10+
pgp-cmd send-key <keyIdUsingTabCompletion> hkp://keyserver.ubuntu.com
11+
12+
2. create sensitive.sbt with contents:
13+
14+
pgpPassphrase := Some($passPhrase.toArray)
15+
16+
pgpPublicRing := file("admin/pubring.asc")
17+
18+
pgpSecretRing := file("admin/secring.asc")
19+
20+
credentials += Credentials("Sonatype Nexus Repository Manager", "oss.sonatype.org", $sonaUser, $sonaPass)
21+
*/

0 commit comments

Comments
 (0)