Skip to content

Commit

Permalink
Merge pull request #8 from morazow/task/releasing
Browse files Browse the repository at this point in the history
Initial infrastructure for doing artifact automated releases from travis
Closes #3
  • Loading branch information
morazow authored Sep 21, 2018
2 parents 09ea665 + abbe15e commit 5b83883
Show file tree
Hide file tree
Showing 15 changed files with 236 additions and 48 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# .gitignore

# credentials
project/.gnupg/local*

# sbt
project/project
project/target
target/
.history
Expand Down
54 changes: 46 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
language: scala

# Because exasol/docker-db requires privileged mode
sudo: required
dist: trusty
services: docker
Expand All @@ -10,9 +9,47 @@ addons:
packages:
- shellcheck

env:
matrix:
- RELEASE=false

global:
# ENCRYPTION_KEY
- secure: |-
U2Wq/BE2sKZBuQOacZGjS9iF7EKDC0AQkbgm+jBffdClJMF0H1KdDywpAafcNPQWS04R7oPLUu/HizqCpwciUCrom
2LWU8qngatyqDV8olH8NG9Y3z+ZlyvNwojG8cE9W0naAFGG+WO1daNhUHIzoKzijNrPAo4coWimnXUOSy/ApqC/qE
D1UfBJf72hydR0KWXNcUad0sugX0r53ynI+YYEFLe8HQLRA+1+2Y+Lrq+50t/J4P5ROE4SCltwXs6GhIRK74GGg4o
Lph/z3WV4ZzP6dgAjCGoh6bkKNXS6pAbZLI4O3CTGUpoRSgxPjaksuPE23B082Z25c5AWUknqSYdpURKqoIhDnXI4
aU04YsaAAr/bnOJPhEqdSpTyBM8oX+Pj1gcUBtKUlSlkFiev3NveAA+pRqyqcZl2Y/0iB4FJUqjYnjS62VW+cLKjg
/Xyu6fTpYmQ4pdzA1iHHfAPNdEcXDleNOabAR3z2veWMp+RdUAP4ZJE1puh07FBfx+aBXUkvZ8VgHuNNFtv9JsJ1J
YKBplqXAIto9PwqWOsHmWih5bD5Js+JUa4w77rU0tDIc6FRzR0EfmePJzlko+oQrbrsw3qr1uah//MIbSSRkK6EQ8
hMBFgmUjIKqPVKKHxkX+hXzZu8VT4FxBvWA4HMydfPNlg2KXg9on9XtO3P1g=
# PGP_PASSPHRASE
- secure: |-
SCeA8EtpdixpGCW7j6iiQq9iNxQdyV8eq6M0/BZtAY9DfH5Eojn2MVyihdHvRdXP/u1gp2AsvRxBlZWUIBAgaYKN3
U2d6Sg2acQ0lmT+z06CcN9K5kKROpxbwGg/Dn4caPORMHgCTbThsmBUDmq5WVGrbVxz82M8i//Cu21chdgJ7lsfOy
R1Owp/JZjwpNZlykSZY/lhE6mttwgEYvJD2x57JXhAiVuSj7EpZVMjQnJK8Ja65XnS0qURbNQQx/zo2V7BXFqWmRn
S42VbmObkcM2jh8jFrRqpJnyupu2/1ZDSSXWDA9sg2DCWwwfyI71kZHwHN/EaLdjLG9Y9it84p6fwSPuAkLoNesNP
StVA7jUfS6DbNPRJphdiRGqmUderRrT5oIvo1DJZMP0VZ68U4GljocDDEPWImr2LfFh9VoxGdSBjHmjKgnnq9oK53
eN/jwNFyVMyqV5fT2VmK3gKWxmGfCGSbm0NefuGY9X1UHXrS32aYa6rxhWiYKpVGPZRbCyoKUEUheecSue0B2PU0h
tPBbSp1+WA6hYUM6OtP01yAk1vaj/KgZnF7BWsXFlcidh7RlJ3cQZDfUB2Cxv0wmihibgPFg9YQF1/7MvCKEbU0O1
Q1Ws/6IA3dwrhb0gcfTREdIjy1AZaejRnCTYNXzpQxJYFpVoC1cfoz5rXCOg=
before_install:
- docker pull exasol/docker-db:latest
- docker network create -d bridge --subnet 192.168.0.0/24 --gateway 192.168.0.1 dockernet
- |
if [ "$TRAVIS_PULL_REQUEST" = "false" ]
then
openssl aes-256-cbc \
-k "$ENCRYPTION_KEY" \
-in project/.gnupg/rings.tar.enc \
-out project/.gnupg/local.rings.tar \
-d
tar xv -C project/.gnupg/ -f project/.gnupg/local.rings.tar
fi
matrix:
include:
Expand All @@ -30,22 +67,23 @@ matrix:

- jdk: oraclejdk8
scala: 2.11.12
env: SPARK_VERSION="2.3.1"
env: SPARK_VERSION="2.3.1" RELEASE=true

script:
- travis_wait 30 ./scripts/ci.sh

after_success:
- if [ "$RELEASE" = "true" ]; then ./scripts/publish.sh; fi
- bash <(curl -s https://codecov.io/bash)

cache:
directories:
- $HOME/.sbt/1.0
- $HOME/.sbt/boot/scala*
- $HOME/.sbt/cache
- $HOME/.sbt/launchers
- $HOME/.ivy2
- $HOME/.coursier
- "$HOME/.sbt/1.0"
- "$HOME/.sbt/boot/scala*"
- "$HOME/.sbt/cache"
- "$HOME/.sbt/launchers"
- "$HOME/.ivy2"
- "$HOME/.coursier"

before_cache:
- du -h -d 1 $HOME/.ivy2/
Expand Down
15 changes: 3 additions & 12 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import com.exasol.spark.sbt.Compilation
import com.exasol.spark.sbt.Dependencies
import com.exasol.spark.sbt.Settings
import com.exasol.spark.sbt.IntegrationTestPlugin

Expand All @@ -12,23 +10,16 @@ lazy val orgSettings = Seq(

lazy val buildSettings = Seq(
scalaVersion := "2.11.12",
crossScalaVersions := Seq("2.10.5", "2.11.12"),
// Compiler settings
scalacOptions ++= Compilation.compilerFlagsFn(scalaVersion.value),
scalacOptions in (Compile, console) := Compilation.consoleFlagsFn(scalaVersion.value),
javacOptions ++= Compilation.JavacCompilerFlags,
compileOrder in Compile := CompileOrder.JavaThenScala,
// Dependency settings
resolvers ++= Dependencies.Resolvers,
libraryDependencies ++= Dependencies.AllDependencies
crossScalaVersions := Seq("2.10.5", "2.11.12")
)

lazy val root =
project
.in(file("."))
.settings(orgSettings)
.settings(buildSettings)
.settings(Settings.projectSettings)
.settings(Settings.projectSettings(scalaVersion))
.enablePlugins(IntegrationTestPlugin)

addCommandAlias("ci-release", ";reload;clean;release with-defaults")
addCommandAlias("pluginUpdates", ";reload plugins;dependencyUpdates;reload return")
Binary file added project/.gnupg/rings.tar.enc
Binary file not shown.
23 changes: 13 additions & 10 deletions project/Compilation.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,19 @@ object Compilation {
CrossVersion.partialVersion(scalaVersion) match {
case Some((2, 12)) => CompilerFlags ++ Scala12CompilerFlags
case Some((2, 11)) => CompilerFlags
case _ => CompilerFlags
case _ => CompilerFlags
}

def consoleFlagsFn(scalaVersion: String): Seq[String] =
compilerFlagsFn(scalaVersion).filterNot(Set(
"-Xfatal-warnings",
"-Ywarn-unused-import",
"-Ywarn-unused:imports"
))
compilerFlagsFn(scalaVersion).filterNot(
Set(
"-Xfatal-warnings",
"-Ywarn-unused-import",
"-Ywarn-unused:imports"
)
)

// format: off
/** Compiler flags specific to Scala version 2.12.x */
private val Scala12CompilerFlags: Seq[String] = Seq(
"-Xlint:constant", // Evaluation of a constant arithmetic expression results in an error.
Expand Down Expand Up @@ -78,17 +81,18 @@ object Compilation {
"-Ywarn-numeric-widen", // Warn when numerics are widened.
"-Ywarn-value-discard" // Warn when non-Unit expression results are unused.
)
// format: on

val JavacCompilerFlags: Seq[String] = Seq(
"-encoding", "UTF-8",
"-encoding",
"UTF-8",
"-deprecation",
"-parameters",
"-Xlint:all"
)

private def contribWart(name: String) = {
private def contribWart(name: String) =
Wart.custom(s"org.wartremover.contrib.warts.$name")
}

private val ExtraWartremoverFlags = Seq(
contribWart("Apply"),
Expand All @@ -100,7 +104,6 @@ object Compilation {
contribWart("SomeApply"),
contribWart("SymbolicName"),
// contribWart("UnsafeInheritance"), // Not possible with Spark classes / traits

ExtraWart.EnumerationPartial,
ExtraWart.FutureObject,
ExtraWart.GenMapLikePartial,
Expand Down
2 changes: 1 addition & 1 deletion project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ object Dependencies {
private val TypesafeLoggingVersion = "3.7.2"

private val ScalaTestVersion = "3.0.5"
private val MockitoVersion = "2.21.0"
private val MockitoVersion = "2.22.0"
private val ContainersJdbcVersion = "1.8.3"
private val ContainersScalaVersion = "0.19.0"

Expand Down
12 changes: 6 additions & 6 deletions project/IntegrationTestSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ object IntegrationTestSettings {
lazy val settings: Seq[Setting[_]] = {
val itSettings =
ScalastylePlugin.rawScalastyleSettings ++
ScalafmtCorePlugin.autoImport.scalafmtSettings ++
Seq(
fork := true,
parallelExecution := false,
scalaSource := baseDirectory.value / "src/it/scala"
)
ScalafmtCorePlugin.autoImport.scalafmtSettings ++
Seq(
fork := true,
parallelExecution := false,
scalaSource := baseDirectory.value / "src/it/scala"
)

Seq.concat(Defaults.itSettings, inConfig(IntegrationTest)(itSettings))
}
Expand Down
112 changes: 112 additions & 0 deletions project/Publishing.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package com.exasol.spark.sbt

import sbt._
import sbt.Keys._
import com.typesafe.sbt.pgp.PgpKeys._
import sbtrelease.ReleasePlugin.autoImport._
import sbtrelease.ReleasePlugin.autoImport.ReleaseTransformations._
import scala.xml.transform.RewriteRule
import scala.xml.transform.RuleTransformer

object Publishing {

// Useful tasks to show what versions would be used if a release was performed
private val showReleaseVersion = taskKey[String]("Show current release version")
private val showNextVersion = taskKey[String]("Show next release version")

def publishSettings(): Seq[Setting[_]] = Seq(
homepage := Some(url("https://github.com/EXASOL/spark-exasol-connector")),
licenses := Seq(
"Apache License 2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0.html")
),
publishMavenStyle := true,
publishArtifact in Test := false,
pomIncludeRepository := Function.const(false),
publishTo := {
val realm = "https://maven.exasol.com/artifactory/"
if (isSnapshot.value) {
val timestamp = new java.util.Date().getTime
Some("Artifactory Realm" at s"$realm/exasol-snapshots;build.timestamp=$timestamp")
} else {
Some("Artifactory Realm" at s"$realm/exasol-releases")
}
},
scmInfo := Some(
ScmInfo(
url("https://github.com/EXASOL/spark-exasol-connector"),
"scm:git:git@github.com:EXASOL/spark-exasol-connector.git"
)
),
developers := List(
Developer(
id = "morazow",
name = "Muhammet Orazov",
email = "muhammet.orazov@exasol.com",
url = url("https://github.com/morazow/")
)
),
// Do not include scoverage & wartremover plugins as a dependency in the pom
// https://github.com/scoverage/sbt-scoverage/issues/153
// This code was copied from https://github.com/http4s/http4s
pomPostProcess := { (node: xml.Node) =>
val depsToRemove = Set("org.scoverage", "org.wartremover", "org.danielnixon")
new RuleTransformer(new RewriteRule {
override def transform(node: xml.Node): Seq[xml.Node] = node match {
case e: xml.Elem
if e.label == "dependency" && e.child
.exists(child => child.label == "groupId" && depsToRemove.contains(child.text)) =>
Nil
case _ => Seq(node)
}
}).transform(node).head
},
// Do not include scala-library as dependency since it provided with Spark runtime
autoScalaLibrary := false,
// Gnupg related settings
// Global scope somehow needed here; otherwise publishLocalSigned looks for these credentials
// in default path of ~/.sbt/gpg/
useGpg in Global := false,
pgpPublicRing in Global := baseDirectory.value / "project" / ".gnupg" / "local.pubring.asc",
pgpSecretRing in Global := baseDirectory.value / "project" / ".gnupg" / "local.secring.asc",
pgpPassphrase in Global := sys.env.get("PGP_PASSPHRASE").map(_.toArray),
credentials ++= (for {
username <- sys.env.get("ARTIFACTORY_USERNAME")
password <- sys.env.get("ARTIFACTORY_PASSWORD")
} yield Credentials("Artifactory Realm", "maven.exasol.com", username, password)).toSeq,
releaseCrossBuild := false,
releaseCommitMessage := {
if (isSnapshot.value) {
s"Setting version to ${version.value} for next development iteration"
} else {
s"Setting version to ${version.value} for release"
}
},
releaseTagName := s"v${version.value}",
releaseTagComment := s"Releasing ${version.value} of module: ${name.value}",
releaseVersionBump := sbtrelease.Version.Bump.Minor,
releasePublishArtifactsAction := publishSigned.value,
releaseProcess := Seq[ReleaseStep](
checkSnapshotDependencies,
releaseStepCommand(sbtrelease.ExtraReleaseCommands.initialVcsChecksCommand),
inquireVersions,
setReleaseVersion,
runClean,
runTest,
commitReleaseVersion,
tagRelease,
publishArtifacts,
setNextVersion,
commitNextVersion,
pushChanges
),
showReleaseVersion := { val rV = releaseVersion.value.apply(version.value); println(rV); rV },
showNextVersion := { val nV = releaseNextVersion.value.apply(version.value); println(nV); nV }
)

def noPublishSettings: Seq[Setting[_]] = Seq(
publish := {},
publishLocal := {},
publishArtifact := false
)

}
23 changes: 18 additions & 5 deletions project/Settings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,32 @@ import com.lucidchart.sbt.scalafmt.ScalafmtCorePlugin.autoImport._
/** A list of (boilerplate) settings for build process */
object Settings {

def projectSettings(scalaVersion: SettingKey[String]): Seq[Setting[_]] =
buildSettings(scalaVersion) ++
miscSettings ++
assemblySettings ++
scalaStyleSettings ++
Publishing.publishSettings()

def buildSettings(scalaVersion: SettingKey[String]): Seq[Setting[_]] = Seq(
// Compiler settings
scalacOptions ++= Compilation.compilerFlagsFn(scalaVersion.value),
scalacOptions in (Compile, console) := Compilation.consoleFlagsFn(scalaVersion.value),
javacOptions ++= Compilation.JavacCompilerFlags,
compileOrder in Compile := CompileOrder.JavaThenScala,
// Dependency settings
resolvers ++= Dependencies.Resolvers,
libraryDependencies ++= Dependencies.AllDependencies
)

def miscSettings(): Seq[Setting[_]] = Seq(
// Wartremover settings
wartremoverErrors in (Compile, compile) := Compilation.WartremoverFlags,
wartremoverErrors in (Test, compile) := Compilation.WartremoverTestFlags,
// General settings
cancelable in Global := true,

// ScalaFmt settings
scalafmtOnCompile := true,

// Scoverage settings
coverageMinimum := 50,
coverageOutputHTML := true,
Expand Down Expand Up @@ -76,7 +92,4 @@ object Settings {
)
}

lazy val projectSettings: Seq[Setting[_]] =
miscSettings ++ assemblySettings ++ scalaStyleSettings

}
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.1.6
sbt.version=1.2.3
Loading

0 comments on commit 5b83883

Please sign in to comment.