From e89c4a9d0215b4c7a2fa911aedd41d1728465ba5 Mon Sep 17 00:00:00 2001 From: Andrea Peruffo Date: Tue, 23 Mar 2021 18:08:54 +0000 Subject: [PATCH] Setup whitesource tools (#1009) * Setup Whitesource in tools * fix --- .github/workflows/build-pr.yaml | 2 ++ .github/workflows/build_and_publish.yaml | 2 ++ tools/project/WhitesourceLicensePlugin.scala | 33 ++++++++++++++++++++ tools/project/plugins.sbt | 1 + 4 files changed, 38 insertions(+) create mode 100644 tools/project/WhitesourceLicensePlugin.scala diff --git a/.github/workflows/build-pr.yaml b/.github/workflows/build-pr.yaml index aece5cba1..eeea2aad2 100644 --- a/.github/workflows/build-pr.yaml +++ b/.github/workflows/build-pr.yaml @@ -21,6 +21,8 @@ jobs: run: | cd core sbt "scalafmtCheckAll; scalafmtSbtCheck" + cd ../tools + sbt "scalafmtCheckAll; scalafmtSbtCheck" - name: Build documentation run: | sudo snap install yq diff --git a/.github/workflows/build_and_publish.yaml b/.github/workflows/build_and_publish.yaml index 9ce21b8cc..961a92880 100644 --- a/.github/workflows/build_and_publish.yaml +++ b/.github/workflows/build_and_publish.yaml @@ -19,6 +19,8 @@ jobs: run: | cd core sbt "whitesourceCheckPolicies; whitesourceUpdate" + cd ../tools + sbt "whitesourceCheckPolicies; whitesourceUpdate" - name: Build documentation run: | sudo snap install yq diff --git a/tools/project/WhitesourceLicensePlugin.scala b/tools/project/WhitesourceLicensePlugin.scala new file mode 100644 index 000000000..b0a8b2b09 --- /dev/null +++ b/tools/project/WhitesourceLicensePlugin.scala @@ -0,0 +1,33 @@ +import sbt._ +import sbt.Keys._ +import sbtwhitesource.WhiteSourcePlugin.autoImport._ +import sbtwhitesource._ +import scala.sys.process.Process +import scala.util.Try + +object Whitesource extends AutoPlugin { + private lazy val gitCurrentBranch = + Try(Process("git rev-parse --abbrev-ref HEAD").!!.replaceAll("\\s", "")).recover { + case e => sys.error(s"Couldn't determine git branch for Whitesource: $e") + }.toOption + + override def requires = WhiteSourcePlugin + + override def trigger = allRequirements + + override lazy val projectSettings = Seq( + // do not change the value of whitesourceProduct + whitesourceProduct := "cloudflow", + whitesourceAggregateProjectName := { + "cloudflow-tools-" + ( + if (isSnapshot.value) + if (gitCurrentBranch.contains("master")) "master" + else "adhoc" + else majorMinor((LocalRootProject / version).value).map(_ + "-stable").getOrElse("adhoc") + ) + }, + whitesourceForceCheckAllDependencies := true, + whitesourceFailOnError := true) + + private def majorMinor(version: String): Option[String] = """\d+\.\d+""".r.findFirstIn(version) +} diff --git a/tools/project/plugins.sbt b/tools/project/plugins.sbt index 26495c52d..0f6885b61 100644 --- a/tools/project/plugins.sbt +++ b/tools/project/plugins.sbt @@ -4,6 +4,7 @@ addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.10.0") // discipline addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.2") addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.6.0") +addSbtPlugin("com.lightbend" % "sbt-whitesource" % "0.1.18") libraryDependencies ++= Seq( "org.codehaus.plexus" % "plexus-container-default" % "2.1.0",