Skip to content

Commit e7bf1db

Browse files
committed
Tag-driven publishing, v2
Scripts taken from here: scala/scala-java8-compat@4a6cfc9 New keys generated as described in the README.
1 parent f576fde commit e7bf1db

File tree

9 files changed

+178
-1
lines changed

9 files changed

+178
-1
lines changed

.travis.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
language: scala
22

3-
script: sbt clean update test publishLocal
3+
env:
4+
global:
5+
- PUBLISH_JDK=openjdk6
6+
# PGP_PASSPHRASE
7+
- secure: "bTGw0loJcnmzNuJG3bjGLs7tfnrWlLb3oi6nBeYUS+coRhKzK4jMN6luuh89gVwIcbFK2nZUkm1s59UZzQA0SMBsdL/Js9Zi6jiUj4NBIVEOzgQxp/vlScF/kF7HxxBji6Gxp/TpqW2MOFxCtWWGBoktuAsufFEhJ47m/cVUZBY="
8+
# SONA_USER
9+
- secure: "uJEIIJGX+xviY5prNor9WW8JuV4MdQbNvGe6nO4Cwumv8LEXALlpONZrmF5BvEB7HrmB/VUqwDO9utrhN7VPaFhCTnoHuslbSdhdB9Yg/lwD+0FpszvKjjraoWeQqqJuXoml9kmH4kQBIP4RxPTnzocPHRIfVyEOYRnMtydImBA="
10+
# SONA_PASS
11+
- secure: "SlbOg79Jzzg7QQeVDu8Q+zZM/GRLFZxPjud9DsLCu4tkTVXWHcYn6FaXuOvVsLkgeALT2pM5j6Zcpp6WqyGRJiSkVqVGqM3jXWov+esgSmhu9pIMvVtxmvfiHBXofiKNYax3XCX+hTwCVuh2pEZ5Thy8i+fXVElCCqzcgTnp+DQ="
12+
13+
script: admin/build.sh
414

515
jdk: openjdk6
616

admin/README.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
## Tag Driven Releasing
2+
3+
Copied from https://github.com/scala/scala-java8-compat/commit/4a6cfc97cd95227b86650410e1b632e5ff79335b.
4+
5+
### Background Reading
6+
7+
- http://docs.travis-ci.com/user/environment-variables/
8+
- http://docs.travis-ci.com/user/encryption-keys/
9+
- http://docs.travis-ci.com/user/encrypting-files/
10+
11+
### Initial setup for the repository
12+
13+
To configure tag driven releases from Travis CI.
14+
15+
1. Generate a key pair for this repository with `./admin/genKeyPair.sh`.
16+
Edit `.travis.yml` and `admin/build.sh` as prompted.
17+
2. Publish the public key to https://pgp.mit.edu
18+
3. Store other secrets as encrypted environment variables with `admin/encryptEnvVars.sh`.
19+
Edit `.travis.yml` as prompted.
20+
4. Edit `.travis.yml` to use `./admin/build.sh` as the build script,
21+
and edit that script to use the tasks required for this project.
22+
5. Edit `.travis.yml` to select which JDK will be used for publishing.
23+
24+
It is important to add comments in .travis.yml to identify the name
25+
of each environment variable encoded in a `:secure` section.
26+
27+
After all of these steps, your .travis.yml should contain config of the
28+
form:
29+
30+
language: scala
31+
env:
32+
global:
33+
- PUBLISH_JDK=openjdk6
34+
# PGP_PASSPHRASE
35+
- secure: "XXXXXX"
36+
# SONA_USER
37+
- secure: "XXXXXX"
38+
# SONA_PASS
39+
- secure: "XXXXXX"
40+
script: admin/build.sh
41+
42+
If Sonatype credentials change in the future, step 3 can be repeated
43+
without generating a new key.
44+
45+
Be sure to use SBT 0.13.7 or higher to avoid [#1430](https://github.com/sbt/sbt/issues/1430)!
46+
47+
### Testing
48+
49+
1. Follow the release process below to create a dummy release (e.g. 0.1.0-TEST1).
50+
Confirm that the release was staged to Sonatype but do not release it to Maven
51+
central. Instead, drop the staging repository.
52+
53+
### Performing a release
54+
55+
1. Create a GitHub "Release" (with a corresponding tag) via the GitHub
56+
web interface.
57+
2. Travis CI will schedule a build for this release. Review the build logs.
58+
3. Log into https://oss.sonatype.org/ and identify the staging repository.
59+
4. Sanity check its contents
60+
5. Release staging repository to Maven and send out release announcement.
61+

admin/build.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# prep environment for publish to sonatype staging if the HEAD commit is tagged
6+
7+
# git on travis does not fetch tags, but we have TRAVIS_TAG
8+
# headTag=$(git describe --exact-match ||:)
9+
10+
if [ "$TRAVIS_JDK_VERSION" == "$PUBLISH_JDK" ] && [[ "$TRAVIS_TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[A-Za-z0-9-]+)? ]]; then
11+
echo "Going to release from tag $TRAVIS_TAG!"
12+
myVer=$(echo $TRAVIS_TAG | sed -e s/^v//)
13+
publishVersion='set every version := "'$myVer'"'
14+
extraTarget="publish-signed"
15+
cat admin/gpg.sbt >> project/plugins.sbt
16+
cp admin/publish-settings.sbt .
17+
18+
# Copied from the output of genKeyPair.sh
19+
K=$encrypted_e923b9d88d53_key
20+
IV=$encrypted_e923b9d88d53_iv
21+
22+
openssl aes-256-cbc -K $K -iv $IV -in admin/secring.asc.enc -out admin/secring.asc -d
23+
fi
24+
25+
sbt "$publishVersion" clean update test publishLocal $extraTarget

admin/encryptEnvVars.sh

Lines changed: 11 additions & 0 deletions
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

Lines changed: 41 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
addSbtPlugin("com.typesafe.sbt" % "sbt-pgp" % "0.8.3") // only added when publishing, see build.sh

admin/publish-settings.sbt

Lines changed: 9 additions & 0 deletions
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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
-----BEGIN PGP PUBLIC KEY BLOCK-----
2+
Version: BCPG v1.49
3+
4+
mQENBFVQyBQBCACcn/inogIi+IzDrqxg4RIUQ2d9HuFpXeOqBMXKT4Ddrxilc8GG
5+
HR2NZHH8G7ZInIrne4HNSVpYPyuH5pqHH6No2JyDRsjDu9eeRopMfADkEBkxZY6z
6+
dUUvkD8jofIczKDUWnPlBo5T0qDdYp9qfVoCLtJA80YkpREiH8itdp5CD+Jq5gCL
7+
LorXlAfv89DrqNYYkzxDkpcAhv6W5gbRmodafsjV1DMrleLKYHgPR+8zDcv36f1n
8+
KEj156DeQPHzRQDOoxZnJAT/b0bt3SfDiQJdNEnCzJh3kCvg0mejk0bKGrX8SpXg
9+
q0k0QK2p87HPQfSVdzTpWHXcDB/mTwn2cl2jABEBAAG0LnNjYWxhLXN3aW5nIDxz
10+
Y2FsYS1pbnRlcm5hbHNAZ29vZ2xlZ3JvdXBzLmNvbT6JARwEEwECAAYFAlVQyBQA
11+
CgkQ+V9S380juJxzqAf9EwtCZBz8Tokle07HyWfULWEnJniyCy7JtYh/Ajq/rP9r
12+
WKygZWmekRjfJujIqBFe7svRjPOLZ82h0ZSCvfd54dMZhNqFktRFMYLnJ4iCUF3B
13+
V5gCEhU/2h8LAyOmWTCLyhF0zFhGatbySpe4pXDElq98E80ti5iozi6sBnDxKdVy
14+
9Ngw17fDLhyflvreJG4qaYD1rmpks6NmCiL84x2kFraAuSnl0YCYfi7GIUWrUtjl
15+
PDk9Cex1o5r8NN1vijRcDpU4jD4NyF7G5/G1Qr9IB9ZZFJQbk1JLsI6v//70xI6Q
16+
C/mumWgyhJJHATA9OXTDfuT1Od0eN2E10Ez8u0mYvQ==
17+
=D3ls
18+
-----END PGP PUBLIC KEY BLOCK-----

admin/secring.asc.enc

1.83 KB
Binary file not shown.

0 commit comments

Comments
 (0)