-
Notifications
You must be signed in to change notification settings - Fork 5
/
build.sbt
117 lines (96 loc) · 4.91 KB
/
build.sbt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import com.typesafe.sbt.web.PathMapping
import com.typesafe.sbt.web.pipeline.Pipeline
import play.sbt.PlayImport.PlayKeys.playDefaultPort
import sbt.Keys.*
import sbt.Tests.{Group, SubProcess}
import sbt.{Test, inConfig}
import uk.gov.hmrc.DefaultBuildSettings.addTestReportOption
import uk.gov.hmrc.gitstamp.GitStampPlugin.*
import uk.gov.hmrc.sbtdistributables.SbtDistributablesPlugin.*
import java.text.SimpleDateFormat
import java.util.Calendar
import scala.language.postfixOps
name := "customs-inventory-linking-exports"
lazy val CdsIntegrationComponentTest = config("it") extend Test
val testConfig = Seq(CdsIntegrationComponentTest, Test)
def forkedJvmPerTestConfig(tests: Seq[TestDefinition], packages: String*): Seq[Group] =
tests.groupBy(_.name.takeWhile(_ != '.')).filter(packageAndTests => packages contains packageAndTests._1) map {
case (packg, theTests) =>
Group(packg, theTests, SubProcess(ForkOptions()))
} toSeq
lazy val testAll = TaskKey[Unit]("test-all")
lazy val allTest = Seq(testAll := (CdsIntegrationComponentTest / test).dependsOn(Test / test).value)
lazy val microservice = (project in file("."))
.enablePlugins(PlayScala)
.enablePlugins(SbtDistributablesPlugin)
.disablePlugins(sbt.plugins.JUnitXmlReportPlugin)
.configs(testConfig: _*)
.settings(playDefaultPort := 9823)
.settings(
scalaVersion := "2.13.12",
commonSettings,
unitTestSettings,
integrationComponentTestSettings,
allTest,
scoverageSettings
)
.settings(majorVersion := 1)
.settings(playDefaultPort := 9823)
lazy val unitTestSettings =
inConfig(Test)(Defaults.testTasks) ++
Seq(
Test / testOptions := Seq(Tests.Filter(unitTestFilter)),
Test / unmanagedSourceDirectories := Seq((Test / baseDirectory).value / "test"),
addTestReportOption(Test, "test-reports")
)
lazy val integrationComponentTestSettings =
inConfig(CdsIntegrationComponentTest)(Defaults.testTasks) ++
Seq(
CdsIntegrationComponentTest / testOptions := Seq(Tests.Filter(integrationComponentTestFilter)),
CdsIntegrationComponentTest / parallelExecution := false,
addTestReportOption(CdsIntegrationComponentTest, "int-comp-test-reports"),
CdsIntegrationComponentTest / testGrouping := forkedJvmPerTestConfig((Test / definedTests).value, "integration", "component")
)
lazy val commonSettings: Seq[Setting[_]] = gitStampSettings
lazy val scoverageSettings: Seq[Setting[_]] = Seq(
coverageExcludedPackages := "<empty>;models/.data/..*;uk.gov.hmrc.customs.inventorylinking.views.*;models.*;config.*;.*(Reverse|AuthService|BuildInfo|Routes).*",
coverageMinimumStmtTotal := 97,
coverageFailOnMinimum := false,
coverageHighlighting := true,
Test / parallelExecution := false
)
def integrationComponentTestFilter(name: String): Boolean = (name startsWith "integration") || (name startsWith "component")
def unitTestFilter(name: String): Boolean = name startsWith "unit"
scalastyleConfig := baseDirectory.value / "project" / "scalastyle-config.xml"
Compile / unmanagedResourceDirectories += baseDirectory.value / "public"
(Runtime / managedClasspath) += (Assets / packageBin).value
libraryDependencies ++= AppDependencies.compile ++ AppDependencies.test
// Task to create a ZIP file containing all xsds for each version, under the version directory
val zipXsds = taskKey[Pipeline.Stage]("Zips up all inventory linking exports XSDs")
zipXsds := { mappings: Seq[PathMapping] =>
val targetDir = WebKeys.webTarget.value / "zip"
val zipFiles: Iterable[java.io.File] =
((Assets / resourceDirectory).value / "api" / "conf")
.listFiles
.filter(_.isDirectory)
.map { dir =>
val xsdPaths = Path.allSubpaths(dir / "schemas")
val exampleMessagesFilter = new SimpleFileFilter(_.getPath.contains("/annotated_XML_samples/"))
val exampleMessagesPaths = Path.selectSubpaths(dir / "examples", exampleMessagesFilter)
val zipFile = targetDir / "api" / "conf" / dir.getName / "inventory-linking-exports-schemas.zip"
IO.zip(xsdPaths ++ exampleMessagesPaths, zipFile, None)
val sizeInMb = (BigDecimal(zipFile.length) / BigDecimal(1024 * 1024)).setScale(1, BigDecimal.RoundingMode.UP)
println(s"Created zip $zipFile")
val today = Calendar.getInstance().getTime()
val dateFormat = new SimpleDateFormat("dd/MM/YYYY")
val lastUpdated = dateFormat.format(today)
println(s"Update the file size in ${dir.getParent}/${dir.getName}/docs/schema.md to be [ZIP, ${sizeInMb}MB last updated $lastUpdated]")
println(s"Check the yaml renders correctly file://${dir.getParent}/${dir.getName}/application.yaml")
println("")
zipFile
}
zipFiles.pair(Path.relativeTo(targetDir)) ++ mappings
}
pipelineStages := Seq(zipXsds)
// TODO: unnecessary? To resolve a bug with version 2.x.x of the scoverage plugin - https://github.com/sbt/sbt/issues/6997
libraryDependencySchemes += "org.scala-lang.modules" %% "scala-xml" % VersionScheme.Always