From 5bc4bb9506ebc5fb881b044b3ae77a287f342ca8 Mon Sep 17 00:00:00 2001 From: Ben Carter Date: Fri, 27 May 2022 17:56:44 +0100 Subject: [PATCH 1/7] add sbt-dynver, remove sbt-release --- build.sbt | 4 ---- project/Release.scala | 37 ------------------------------------- project/plugins.sbt | 2 +- scheduler/version.sbt | 1 - 4 files changed, 1 insertion(+), 43 deletions(-) delete mode 100644 project/Release.scala delete mode 100644 scheduler/version.sbt diff --git a/build.sbt b/build.sbt index b826d5a9..9d63d4c8 100644 --- a/build.sbt +++ b/build.sbt @@ -1,6 +1,5 @@ import com.typesafe.sbt.packager.docker.Cmd import Aliases._ -import Release._ ThisBuild / scalafmtOnCompile := true ThisBuild / semanticdbEnabled := true @@ -53,7 +52,6 @@ lazy val scheduler = (project in file("scheduler")) javaAgents += "io.kamon" % "kanela-agent" % "1.0.14", buildInfoSettings, dockerSettings, - releaseSettings, Test / parallelExecution := false ) @@ -65,7 +63,6 @@ lazy val avro = (project in file("avro")) .settings(libraryDependencies += Dependencies.avro4s) .settings(schema := (Compile / run).toTask("").value) .dependsOn(scheduler % "compile->compile") - .disablePlugins(ReleasePlugin) lazy val root = (project in file(".")) .withId("kafka-message-scheduler") @@ -74,4 +71,3 @@ lazy val root = (project in file(".")) .settings(dockerImageCreationTask := (scheduler / Docker / publishLocal).value) .aggregate(scheduler, avro) .enablePlugins(DockerComposePlugin) - .disablePlugins(ReleasePlugin) diff --git a/project/Release.scala b/project/Release.scala deleted file mode 100644 index bf0a3d3f..00000000 --- a/project/Release.scala +++ /dev/null @@ -1,37 +0,0 @@ -import com.typesafe.sbt.packager.docker.DockerPlugin.autoImport.{Docker => docker} -import com.typesafe.sbt.packager.universal.UniversalPlugin.autoImport.Universal -import sbt.Keys._ -import sbt.taskKey -import sbtrelease.ReleasePlugin.autoImport._ -import sbtrelease.ReleaseStateTransformations._ -import sbtrelease._ - -object Release { - // Useful tasks to show what versions would be used if a release was performed. - private val showReleaseVersion = taskKey[String]("the future version once releaseNextVersion has been applied to it") - private val showNextVersion = taskKey[String]("the future version once releaseNextVersion has been applied to it") - - lazy val releaseSettings = Seq( - releaseUseGlobalVersion := false, - releaseVersionBump := sbtrelease.Version.Bump.Minor, - releaseTagName := s"${name.value}-${version.value}", - releaseTagComment := s"Releasing ${version.value} of module: ${name.value}", - releasePublishArtifactsAction := (Universal / publish).value, - releaseProcess := Seq[ReleaseStep]( - runClean, - checkSnapshotDependencies, - releaseStepCommand(ExtraReleaseCommands.initialVcsChecksCommand), - inquireVersions, - setReleaseVersion, - runTest, - commitReleaseVersion, - tagRelease, - ReleaseStep(releaseStepTask(docker / publish)), - 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 } - ) -} diff --git a/project/plugins.sbt b/project/plugins.sbt index 16374497..d13ae849 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,5 +1,4 @@ addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.11.0") -addSbtPlugin("com.github.sbt" % "sbt-release" % "1.1.0") addSbtPlugin("com.lightbend.sbt" % "sbt-javaagent" % "0.1.6") addSbtPlugin("com.github.sbt" % "sbt-native-packager" % "1.9.9") addSbtPlugin("com.tapad" % "sbt-docker-compose" % "1.0.35") @@ -7,3 +6,4 @@ addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.6") addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.10.0") addSbtPlugin("io.kamon" % "sbt-kanela-runner" % "2.0.14") addSbtPlugin("io.github.davidgregory084" % "sbt-tpolecat" % "0.3.1") +addSbtPlugin("com.dwijnand" % "sbt-dynver" % "4.1.1") diff --git a/scheduler/version.sbt b/scheduler/version.sbt deleted file mode 100644 index 87433366..00000000 --- a/scheduler/version.sbt +++ /dev/null @@ -1 +0,0 @@ -version := "0.25.0-SNAPSHOT" From fc4fe72a6937a2828dd5dd4b04d1ea85e0141340 Mon Sep 17 00:00:00 2001 From: Ben Carter Date: Fri, 27 May 2022 18:00:53 +0100 Subject: [PATCH 2/7] Update docker settings --- build.sbt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/build.sbt b/build.sbt index 9d63d4c8..44e42ee6 100644 --- a/build.sbt +++ b/build.sbt @@ -5,6 +5,7 @@ ThisBuild / scalafmtOnCompile := true ThisBuild / semanticdbEnabled := true ThisBuild / semanticdbVersion := scalafixSemanticdb.revision ThisBuild / scalafixDependencies += "com.github.liancheng" %% "organize-imports" % "0.6.0" +ThisBuild / dynverSeparator := "-" Global / onChangedBuildSource := ReloadOnSourceChanges @@ -24,11 +25,11 @@ val compilerSettings = Seq( ) lazy val dockerSettings = Seq( - Docker / packageName := "kafka-message-scheduler", + Docker / packageName := "sky-uk/kafka-message-scheduler", dockerBaseImage := "eclipse-temurin:17-jdk-alpine", - dockerRepository := Some("skyuk"), + dockerRepository := Some("ghcr.io"), dockerLabels := Map("maintainer" -> "Sky"), - dockerUpdateLatest := true, + dockerUpdateLatest := !isSnapshot.value, dockerCommands ++= Seq( Cmd("USER", "root"), Cmd("RUN", "apk add --no-cache bash") From 908d201264a40fc58096371d835686b053273653 Mon Sep 17 00:00:00 2001 From: Ben Carter Date: Fri, 27 May 2022 18:02:21 +0100 Subject: [PATCH 3/7] Update Aliases --- project/Aliases.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project/Aliases.scala b/project/Aliases.scala index 160ce5a8..e76b1c94 100644 --- a/project/Aliases.scala +++ b/project/Aliases.scala @@ -4,7 +4,7 @@ object Aliases { lazy val defineCommandAliases = addCommandAlias("ciBuild", "checkFmt; checkFix; test; schema") ++ - addCommandAlias("ciRelease", "clean; schema; project scheduler; release with-defaults") ++ + addCommandAlias("ciRelease", "project scheduler; docker:publish") ++ addCommandAlias("checkFix", "scalafixAll --check OrganizeImports; scalafixAll --check") ++ addCommandAlias("runFix", "scalafixAll OrganizeImports; scalafixAll") ++ addCommandAlias("checkFmt", "scalafmtCheckAll; scalafmtSbtCheck") ++ From 945627d1e122701a014bc2a03899e1cc18d7eb54 Mon Sep 17 00:00:00 2001 From: Ben Carter Date: Fri, 27 May 2022 18:04:30 +0100 Subject: [PATCH 4/7] Update travis to publish to Docker --- .travis.yml | 19 +++++++++++++++++-- .travis/docker-login.sh | 2 ++ 2 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 .travis/docker-login.sh diff --git a/.travis.yml b/.travis.yml index b09b90e0..f6d2365d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,6 +9,15 @@ jdk: branches: only: - master + - /^v\d+\.\d+\.\d+$/ + +before_install: + - git fetch --tags + +stages: + - name: test + - name: release + if: ((branch = master AND type = push) OR (tag IS present)) AND NOT fork # https://www.scala-sbt.org/1.x/docs/Travis-CI-with-sbt.html cache: @@ -22,5 +31,11 @@ before_cache: - find $HOME/.ivy2/cache -name "ivydata-*.properties" -print -delete - find $HOME/.sbt -name "*.lock" -print -delete -script: - - sbt ++$TRAVIS_SCALA_VERSION ciBuild +jobs: + include: + # stage="test" if no stage is specified + - name: ciBuild + script: sbt ciBuild + # run ci-release only if previous stages passed + - stage: release + script: bash .travis/docker-login.sh && sbt ciRelease diff --git a/.travis/docker-login.sh b/.travis/docker-login.sh new file mode 100644 index 00000000..f424537d --- /dev/null +++ b/.travis/docker-login.sh @@ -0,0 +1,2 @@ +#!/bin/bash +echo "$GH_PAT" | docker login ghcr.io -u "$GH_USERNAME" --password-stdin From 28db09019e93d56343da9ea574af2574e84968f5 Mon Sep 17 00:00:00 2001 From: Ben Carter Date: Sat, 2 Jul 2022 16:52:03 +0100 Subject: [PATCH 5/7] Update project/Aliases.scala --- project/Aliases.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project/Aliases.scala b/project/Aliases.scala index e76b1c94..bfe53927 100644 --- a/project/Aliases.scala +++ b/project/Aliases.scala @@ -4,7 +4,7 @@ object Aliases { lazy val defineCommandAliases = addCommandAlias("ciBuild", "checkFmt; checkFix; test; schema") ++ - addCommandAlias("ciRelease", "project scheduler; docker:publish") ++ + addCommandAlias("ciRelease", "project scheduler; Docker/publish") ++ addCommandAlias("checkFix", "scalafixAll --check OrganizeImports; scalafixAll --check") ++ addCommandAlias("runFix", "scalafixAll OrganizeImports; scalafixAll") ++ addCommandAlias("checkFmt", "scalafmtCheckAll; scalafmtSbtCheck") ++ From 344b3652380dfc93fd1de741ac985a2abe88a402 Mon Sep 17 00:00:00 2001 From: Ben Carter Date: Sat, 2 Jul 2022 17:06:41 +0100 Subject: [PATCH 6/7] Tag latest only for stable build --- build.sbt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/build.sbt b/build.sbt index 44e42ee6..243fc5f9 100644 --- a/build.sbt +++ b/build.sbt @@ -29,7 +29,10 @@ lazy val dockerSettings = Seq( dockerBaseImage := "eclipse-temurin:17-jdk-alpine", dockerRepository := Some("ghcr.io"), dockerLabels := Map("maintainer" -> "Sky"), - dockerUpdateLatest := !isSnapshot.value, + dockerAliases ++= { + lazy val dockerTag = (tag: String) => Seq(dockerAlias.value.withTag(Some(tag))) + if (isSnapshot.value) dockerTag("snapshot") else dockerTag("latest") + }, dockerCommands ++= Seq( Cmd("USER", "root"), Cmd("RUN", "apk add --no-cache bash") From ef08e75ba5a3979b063088ad1836c97ca8609756 Mon Sep 17 00:00:00 2001 From: Ben Carter Date: Mon, 3 Oct 2022 14:48:41 +0100 Subject: [PATCH 7/7] type tagging func --- build.sbt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.sbt b/build.sbt index 08276f90..5cdf0d13 100644 --- a/build.sbt +++ b/build.sbt @@ -1,4 +1,4 @@ -import com.typesafe.sbt.packager.docker.Cmd +import com.typesafe.sbt.packager.docker.{Cmd, DockerAlias} import Aliases._ ThisBuild / scalafmtOnCompile := true @@ -30,7 +30,7 @@ lazy val dockerSettings = Seq( dockerRepository := Some("ghcr.io"), dockerLabels := Map("maintainer" -> "Sky"), dockerAliases ++= { - lazy val dockerTag = (tag: String) => Seq(dockerAlias.value.withTag(Some(tag))) + lazy val dockerTag: String => Seq[DockerAlias] = tag => Seq(dockerAlias.value.withTag(Some(tag))) if (isSnapshot.value) dockerTag("snapshot") else dockerTag("latest") }, dockerCommands ++= Seq(