Skip to content
This repository has been archived by the owner on Jul 16, 2021. It is now read-only.

Commit

Permalink
simplify release
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Kenny committed Feb 11, 2020
1 parent dcf2542 commit 06270dc
Show file tree
Hide file tree
Showing 11 changed files with 519 additions and 194 deletions.
57 changes: 36 additions & 21 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,48 @@
language: scala

before_script:
- openssl aes-256-cbc -K $encrypted_0ed9b3e7612f_key -iv $encrypted_0ed9b3e7612f_iv -in secrets.zip.enc -out secrets.zip -d
- git remote add ssh-origin "git@github.com:wellcomecollection/sierra-streams-source.git"

cache:
directories:
- $HOME/.sbt
- $HOME/.ivy2/cache
- project/target

# Everything below this line is boilerplate that should be reusable,
# unmodified, in any of our Scala library repos.

sudo: false

scala:
- 2.11.11
- 2.12.6
- 2.12.6

branches:
only:
- master

env:
global:
# This forces Python to print everything to stdout/stderr immediately.
- PYTHONUNBUFFERED=x

jobs:
include:
- stage: check_commits
script:
- sbt "show suggestedBump";

- stage: release
script:
- openssl aes-256-cbc -K $encrypted_12c8071d2874_key -iv $encrypted_12c8071d2874_iv -in credentials.sbt.enc -out credentials.sbt -d
- openssl aes-256-cbc -K $encrypted_0f90593c4cb0_key -iv $encrypted_0f90593c4cb0_iv -in keys.zip.enc -out keys.zip -d
- unzip keys.zip;
- git config user.name "Travis CI on behalf of Wellcome"
- git config user.email "wellcomedigitalplatform@wellcome.ac.uk"
- git config core.sshCommand "ssh -i ssh-key/id_rsa"
- git remote set-url origin "git@github.com:wellcometrust/sierra-streams-source.git"
- sbt ++$TRAVIS_SCALA_VERSION release;
- stage: format
env: TASK=format
- stage: test
env: TASK=test
services:
- docker
- stage: release
env: TASK=release

script:
- ./sbt_release_tooling.py "$TASK"

stages:
- test
- name: check_commits
if: type = pull_request
- name: release
if: type = push
- format
- test
- name: release
if: type = push
48 changes: 1 addition & 47 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

A library for providing Akka Streams from objects in a Sierra API.

[![Build Status](https://travis-ci.org/wellcometrust/sierra-streams-source.svg?branch=master)](https://travis-ci.org/wellcometrust/sierra-streams-source)
[![Build Status](https://travis-ci.org/wellcomecollection/sierra-streams-source.svg?branch=master)](https://travis-ci.org/wellcomecollection/sierra-streams-source)

## Installation

Expand Down Expand Up @@ -38,50 +38,4 @@ val eventualJsonList = sierraSource.runWith(Sink.seq[Json])
eventualJsonList.map(jsonList => {
// Do stuff
})
```

## Development

If you want to release this library you'll need credentials to authenticate with Travis and Sonatype.

### Releasing to Sonatype

Create a file `credentials.sbt` in the root of the repo with the following contents (but with the correct details).

```sbt
credentials += Credentials("Sonatype Nexus Repository Manager",
"oss.sonatype.org",
"(Sonatype user name)",
"(Sonatype password)")

pgpPassphrase := Some("(PGP password)".toCharArray)
```

Then run `publishSigned` and `sonatypeRelease` in sbt to push a release:

```sh
sbt ++2.11.11 publishSigned sonatypeRelease;
```

### Packaging for Travis

To encrypt `credentials.sbt` for Travis you can use the following command:

```sh
docker run -v $(pwd):/project \
-v ~/.travis:/root/.travis \
-it skandyla/travis-cli \
encrypt-file credentials.sbt
```

You will then need to copy the specified output to `.travis.yml` if different from what is already in that file.

For example:

```yml
- stage: release
scala: 2.12.6
script:
# Output like this will be specified from the travis cli tool
- openssl aes-256-cbc -K $encrypted_83630750896a_key -iv $encrypted_83630750896a_iv -in credentials.sbt.enc -out credentials.sbt -d
```
132 changes: 31 additions & 101 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,103 +1,33 @@
import sbt.Resolver
import sbtrelease.{Version, versionFormatError}

organization := "uk.ac.wellcome"

name := "sierra-streams-source"

crossScalaVersions := Seq("2.11.11", "2.12.6")


val versions = new {
val logback = "1.1.8"
val scalatest = "3.0.1"
val circeVersion = "0.8.0"
}

val circeDependencies = Seq(
"io.circe" %% "circe-core" % versions.circeVersion,
"io.circe" %% "circe-generic"% versions.circeVersion,
"io.circe" %% "circe-parser"% versions.circeVersion,
"io.circe" %% "circe-optics" % versions.circeVersion
val projectName = "sierra-streams-source"
val projectVersion = "1.0.0"

val settings: Seq[Def.Setting[_]] = Seq(
scalaVersion := "2.12.6",
organization := "uk.ac.wellcome",
scalacOptions ++= Seq(
"-deprecation",
"-unchecked",
"-encoding",
"UTF-8",
"-Xlint",
"-Xverify",
"-Xfatal-warnings",
"-feature",
"-language:postfixOps"
),
parallelExecution in Test := false,
resolvers ++= Seq(
"S3 releases" at "s3://releases.mvn-repo.wellcomecollection.org/"
),
publishMavenStyle := true,
publishTo := Some(
"S3 releases" at "s3://releases.mvn-repo.wellcomecollection.org/"
),
publishArtifact in Test := true,
version := projectVersion
)

libraryDependencies := Seq(
"com.github.tomakehurst" % "wiremock" % "2.11.0" % Test,
"org.scalaj" %% "scalaj-http" % "2.3.0",
"org.scalatest" %% "scalatest" % versions.scalatest % Test,
"ch.qos.logback" % "logback-classic" % versions.logback,
"org.slf4j" % "slf4j-api" % "1.7.25",
"com.typesafe.akka" %% "akka-stream" % "2.5.6",
"com.typesafe.akka" %% "akka-stream-testkit" % "2.5.6" % Test
) ++ circeDependencies

resolvers += Resolver.sonatypeRepo("releases")

scalacOptions ++= Seq(
"-deprecation",
"-unchecked",
"-encoding",
"UTF-8",
"-Xlint",
"-Xverify",
"-feature",
"-language:postfixOps"
)

// We don't publish SNAPSHOTS but the checkSnapshotDependencies
// step in the releaseProcess checks that the SNAPSHOT version is
// compatible with sonatype and fails without these two lines.
dynverSonatypeSnapshots in ThisBuild := true
version in ThisBuild ~= (_.replace('+', '-'))

publishTo := Some(Opts.resolver.sonatypeStaging)

useGpg := false

parallelExecution in Test := false

pgpPublicRing := baseDirectory.value / "pgp-key" / "pubring.asc"
pgpSecretRing := baseDirectory.value / "pgp-key" / "secring.asc"

releaseVersion := { ver: String =>Version(ver)
.map(_.withoutQualifier)
.map(_.bump(suggestedBump.value).string).getOrElse(versionFormatError)
}

// we hide the existing definition for setReleaseVersion to replace it with our own
import sbtrelease.ReleaseStateTransformations.{setReleaseVersion=>_,_}

// This creates a release stage that gets the version from the dynamic one
// based on tags generated by sbt-dynver plugin.
// Inspired from https://blog.byjean.eu/2015/07/10/painless-release-with-sbt.html
lazy val setReleaseVersion: ReleaseStep = { st: State =>
val extracted = Project.extract(st)
val currentVersion = extracted.get(version)

val getReleaseVersionFunction = extracted.runTask(releaseVersion, st)._2
val selectedVersion = getReleaseVersionFunction(currentVersion)

st.log.info("Setting version to '%s'." format selectedVersion)
val useGlobal =Project.extract(st).get(releaseUseGlobalVersion)
val versionStr = (if (useGlobal) globalVersionString else versionString) format selectedVersion

reapply(Seq(
if (useGlobal) version in ThisBuild := selectedVersion
else version := selectedVersion
), st)
}

// In sbt-autoversion plugin, minor is the default bump
// strategy as the minorRegexes matches any string.
// Let's override that so figuring out the next version fails if
// there are no commits that explicitly specify the bumping strategy
minorRegexes := List("""\[?minor\]?.*""").map(_.r)

releaseProcess := Seq(
checkSnapshotDependencies,
setReleaseVersion,
tagRelease,
releaseStepCommandAndRemaining("+publishSigned"),
releaseStepCommand("sonatypeReleaseAll"),
releaseStepCommand(s"git push origin --tags")
)
lazy val root = (project in file("."))
.withId(projectName)
.settings(settings)
.settings(libraryDependencies ++= Dependencies.libraryDependencies)
1 change: 0 additions & 1 deletion credentials.sbt.enc

This file was deleted.

Binary file removed keys.zip.enc
Binary file not shown.
41 changes: 41 additions & 0 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import sbt._

object Dependencies {
lazy val versions = new {
val aws = "1.11.225"
val akka = "2.5.9"
val akkaStreamAlpakka = "0.20"
val circe = "0.9.0"
val circeYaml = "0.8.0"
val scalatest = "3.0.1"
val logback = "1.2.3"
}

val logbackDependencies = Seq(
"ch.qos.logback" % "logback-classic" % versions.logback
)

val akkaDependencies: Seq[ModuleID] = Seq(
"com.typesafe.akka" %% "akka-actor" % versions.akka,
"com.typesafe.akka" %% "akka-stream" % versions.akka
)

val circeDependencies = Seq(
"io.circe" %% "circe-core" % versions.circe,
"io.circe" %% "circe-parser" % versions.circe
)

val testDependencies = Seq(
"org.scalatest" %% "scalatest" % versions.scalatest % Test
)

val libraryDependencies = Seq(
"com.github.tomakehurst" % "wiremock" % "2.11.0" % Test,
"org.scalaj" %% "scalaj-http" % "2.3.0",
"org.scalatest" %% "scalatest" % versions.scalatest % Test,
"ch.qos.logback" % "logback-classic" % versions.logback,
"org.slf4j" % "slf4j-api" % "1.7.25",
"com.typesafe.akka" %% "akka-stream" % "2.5.6",
"com.typesafe.akka" %% "akka-stream-testkit" % "2.5.6" % Test
) ++ circeDependencies
}
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version = 1.0.3
sbt.version=1.1.6
9 changes: 3 additions & 6 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "2.0")
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.0")
addSbtPlugin("com.dwijnand" % "sbt-dynver" % "3.0.0")
addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.8")
addSbtPlugin("org.scala-sbt" % "sbt-autoversion" % "1.0.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "1.0.0")
addSbtPlugin("com.tapad" % "sbt-docker-compose" % "1.0.34")
addSbtPlugin("com.frugalmechanic" % "fm-sbt-s3-resolver" % "0.16.0")
addSbtPlugin("com.lucidchart" % "sbt-scalafmt-coursier" % "1.15")
Loading

0 comments on commit 06270dc

Please sign in to comment.