Skip to content

Instantly share code, notes, and snippets.

@kwark
Last active September 6, 2017 14:07
Show Gist options
  • Save kwark/0f60483f69d1a9fd31c3547dcf2d66f4 to your computer and use it in GitHub Desktop.
Save kwark/0f60483f69d1a9fd31c3547dcf2d66f4 to your computer and use it in GitHub Desktop.
setup sbt-release-early with travis-ci
language: scala
scala:
- 2.11.11
script:
- sbt ++$TRAVIS_SCALA_VERSION test
jdk:
- oraclejdk8
after_success:
- if [ $TRAVIS_PULL_REQUEST = 'false' ]; then sbt ++$TRAVIS_SCALA_VERSION releaseEarly;
fi
env:
global:
- secure: .....
before_install:
- if [ $TRAVIS_PULL_REQUEST = "false" ]; then
openssl aes-256-cbc -K $encrypted_474c3e42cec4_key -iv $encrypted_474c3e42cec4_iv -in travis/secrets.tar.enc -out travis/secrets.tar -d;
tar xv -C travis -f travis/secrets.tar;
fi
//don't set any version
//this example publishes to bintray
releaseEarlyWith := BintrayPublisher
releaseEarlyEnableSyncToMaven := false
publishMavenStyle := true
publishArtifact in Test := false
pgpPublicRing := file("./travis/local.pubring.asc")
pgpSecretRing := file("./travis/local.secring.asc")
scmInfo := Some(ScmInfo(url("https://github.com/xxxx/yyyy"), "scm:git:git@github.com/xxx/yyyyy.git"))
developers := List(
Developer("Joe", "Developer", "", url("https://github.com/xxxxx"))
)
licenses := Seq(("Apache-2.0", url("http://www.apache.org/licenses/LICENSE-2.0.txt")))
homepage := Some(url("https://github.com/xxxx/yyyy"))
addSbtPlugin("ch.epfl.scala" % "sbt-release-early" % "1.1.1"
  • create a PGP pub/sec key pair (see https://github.com/scalacenter/sbt-release-early/wiki/How-to-create-a-gpg-key)
  • add local.* to your .gitignore file, because we don't want to accidentally add unencrypted files to the git repo.
  • create a travis directory in your project: mkdir travis
  • copy the generated pubring.asc and secring.asc files to the travis directory and rename to local.pubring.asc and local.secring.asc
  • install travis client (if not installed yet): gem install travis
  • login to travis from command line: travis login
  • tar-gzip the files to be encoded: tar cv -C travis -f travis/local.secrets.tar local.pubring.asc local.secring.asc
  • encode the secrets.tar file: travis encrypt-file travis/local.secrets.tar -o travis/secrets.tar.enc -p . See https://docs.travis-ci.com/user/encrypting-files/#Encrypting-multiple-files for more details.
  • add the following lines at the end of your .travis.yml file. This will This will decrypt the archive and make the local.pubring.asc and local.secring.asc available to the travis build, but only when it is NOT building a pull request.
before_install:
- if [ $TRAVIS_PULL_REQUEST = 'false' ]; then
    openssl aes-256-cbc -K $encrypted_474c3e42cec4_key -iv $encrypted_474c3e42cec4_iv -in travis/secrets.tar.enc -out travis/secrets.tar -d;
    tar xv -C travis -f travis/secrets.tar;
  fi
  • encrypt the pgp passphrase into PGP_PASS environment variable: travis encrypt 'PGP_PASS=MyDirtyLittleSecret --add. The --add option will add the encrypted environment variable to your .travis.yml files. Also make sure to escape special characters as needed, check https://docs.travis-ci.com/user/encryption-keys/#Note-on-escaping-certain-symbols for more info.
  • I'm publishing to bintray so I additionally also encrypted the BINTRAY_USER and BINTRAY_PASS environment variables. The BINTRAY_PASS is actually your bintray API token.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment