Skip to content

Commit

Permalink
feat(sbt): 🔨 refactor project structure
Browse files Browse the repository at this point in the history
Signed-off-by: Felipe Bonezi <[email protected]>
  • Loading branch information
felipebonezi committed Oct 22, 2022
1 parent d5e925e commit 4fc46d3
Show file tree
Hide file tree
Showing 29 changed files with 310 additions and 110 deletions.
Binary file added .DS_Store
Binary file not shown.
38 changes: 36 additions & 2 deletions .github/workflows/continouos-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,34 @@ jobs:
path: ${{github.workspace}}/target/scalastyle-report/

build:
name: Build & Analyze
name: Build
if: "(github.event.release || github.event.release.prerelease) == false"
needs: [ validate ]
runs-on: ubuntu-latest

strategy:
fail-fast: true
matrix:
distribution: [ 'corretto' ]
jdk: [ '8' ]
scala: [ '2.12.17', '2.13.10' ]

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup JDK
uses: actions/setup-java@v3
with:
distribution: ${{ matrix.distribution }}
java-version: ${{ matrix.jdk }}
cache: 'sbt'

- name: Perform Build / Test
run: sbt ++${{ matrix.scala }} compile test

optional-build:
name: Build (Optional)
if: "(github.event.release || github.event.release.prerelease) == false"
continue-on-error: ${{ matrix.experimental }}
needs: [ validate ]
Expand All @@ -47,7 +74,7 @@ jobs:
fail-fast: true
matrix:
distribution: [ 'corretto' ]
jdk: [ '8', '11' ]
jdk: [ '11' ]
scala: [ '2.12.17', '2.13.10' ]
experimental: [ false ]
include:
Expand All @@ -70,6 +97,13 @@ jobs:
- name: Perform Build / Test
run: sbt ++${{ matrix.scala }} compile test

ready:
name: Ready to Merge
needs: [ build ]
runs-on: ubuntu-latest
steps:
- run: echo "Ready to merge!"

publish:
name: Publish to Sonatype
if: "github.event.release || github.event.release.prerelease"
Expand Down
89 changes: 71 additions & 18 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
import Common.repoName
import Common._
import Dependencies.scala212
import Dependencies.scala213

lazy val root = project
.in(file("."))
.aggregate(actuator)
.aggregate(core, actuator, jdbc, slick, redis)
.settings(
name := "play-actuator-root",
crossScalaVersions := Nil,
Expand All @@ -34,10 +34,20 @@ lazy val root = project
lazy val core = project
.in(file("play-actuator-core"))
.settings(
scalaVersion := scala213,
crossScalaVersions := Seq(scala212, scala213),
libraryDependencies ++= Dependencies.core,
publish / skip := true
name := s"$repoName-core",
organization := "io.github.felipebonezi",
scalaVersion := scala213,
crossScalaVersions := Seq(scala212, scala213),
versionScheme := Some("early-semver"),
ThisBuild / sonatypeCredentialHost := "s01.oss.sonatype.org",
ThisBuild / sonatypeRepository := "https://s01.oss.sonatype.org/service/local",
scmInfo := Some(
ScmInfo(
url(s"https://github.com/felipebonezi/$repoName/play-actuator-core"),
s"scm:git:[email protected]:felipebonezi/$repoName.git"
)
),
libraryDependencies ++= Dependencies.core
)

lazy val actuator = project
Expand All @@ -57,29 +67,72 @@ lazy val actuator = project
s"scm:git:[email protected]:felipebonezi/$repoName.git"
)
),
Dependencies.actuator,
Dependencies.actuator
)
.enablePlugins(Common)

lazy val database = project
.in(file("play-actuator-indicators/database"))
lazy val jdbc = project
.in(file("play-actuator-indicators/database/jdbc"))
.dependsOn(core)
.settings(
scalaVersion := scala213,
crossScalaVersions := Seq(scala212, scala213),
Dependencies.db,
publish / skip := true
name := s"$jdbcIndicatorName",
organization := "io.github.felipebonezi",
scalaVersion := scala213,
crossScalaVersions := Seq(scala212, scala213),
versionScheme := Some("early-semver"),
ThisBuild / sonatypeCredentialHost := "s01.oss.sonatype.org",
ThisBuild / sonatypeRepository := "https://s01.oss.sonatype.org/service/local",
scmInfo := Some(
ScmInfo(
url(s"https://github.com/felipebonezi/$repoName/play-actuator-indicators/database/jdbc"),
s"scm:git:[email protected]:felipebonezi/$repoName.git"
)
),
Dependencies.jdbc
)
.enablePlugins(Common)

lazy val slick = project
.in(file("play-actuator-indicators/database/slick"))
.dependsOn(core)
.settings(
name := s"$slickIndicatorName",
organization := "io.github.felipebonezi",
scalaVersion := scala213,
crossScalaVersions := Seq(scala212, scala213),
versionScheme := Some("early-semver"),
ThisBuild / sonatypeCredentialHost := "s01.oss.sonatype.org",
ThisBuild / sonatypeRepository := "https://s01.oss.sonatype.org/service/local",
scmInfo := Some(
ScmInfo(
url(s"https://github.com/felipebonezi/$repoName/play-actuator-indicators/database/slick"),
s"scm:git:[email protected]:felipebonezi/$repoName.git"
)
),
Dependencies.slick
)
.enablePlugins(Common)

lazy val redis = project
.in(file("play-actuator-indicators/redis"))
.in(file("play-actuator-indicators/database/redis"))
.dependsOn(core)
.settings(
scalaVersion := scala213,
crossScalaVersions := Seq(scala212, scala213),
Dependencies.redis,
publish / skip := true
name := s"$redisIndicatorName",
organization := "io.github.felipebonezi",
scalaVersion := scala213,
crossScalaVersions := Seq(scala212, scala213),
versionScheme := Some("early-semver"),
ThisBuild / sonatypeCredentialHost := "s01.oss.sonatype.org",
ThisBuild / sonatypeRepository := "https://s01.oss.sonatype.org/service/local",
scmInfo := Some(
ScmInfo(
url(s"https://github.com/felipebonezi/$repoName/play-actuator-indicators/database/redis"),
s"scm:git:[email protected]:felipebonezi/$repoName.git"
)
),
Dependencies.redis
)
.enablePlugins(Common)

addCommandAlias(
"validateCode",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
*/
package play.actuator.health
import play.actuator.ActuatorEnum.Status
import play.api.libs.json.{JsNull, JsNumber, JsString, Json, Writes}
import play.api.libs.json.JsNull
import play.api.libs.json.JsNumber
import play.api.libs.json.JsString
import play.api.libs.json.Json
import play.api.libs.json.Writes

case class Health(name: String, status: Status, details: Map[String, Any]) {
override def toString: String = s"Health(status=$status, details=$details)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
package play.actuator.health.indicator
import play.actuator.health.HealthBuilder

abstract class BaseHealthIndicator {
trait HealthIndicator {

def info(builder: HealthBuilder): Unit

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
play {
actuator {
indicator {
health {
database = true
}
}
}
}

play.modules.enabled += "play.actuator.ActuatorJdbcModule"
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,24 @@
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package actuator.health.indicator
import play.actuator.health.indicator.BaseHealthIndicator
package play.actuator

trait DatabaseIndicator extends BaseHealthIndicator {}
import com.google.inject.AbstractModule
import com.google.inject.name.Names
import play.actuator.health.indicator.DatabaseJdbcIndicator
import play.actuator.health.indicator.HealthIndicator
import play.api.Configuration
import play.api.Environment

class ActuatorJdbcModule(environment: Environment, config: Configuration) extends AbstractModule {

override def configure(): Unit = {
val confKey = "play.actuator.health.indicators.database"
if (config.getOptional[Boolean](confKey).getOrElse(false)) {
bind(classOf[HealthIndicator])
.annotatedWith(Names.named("databaseIndicator"))
.to(classOf[DatabaseJdbcIndicator])
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package actuator.health.indicator
package play.actuator.health.indicator

import actuator.health.indicator.DatabaseJdbcIndicator.DB_TIMEOUT_SECS
import play.actuator.ActuatorEnum
import play.actuator.health.HealthBuilder
import play.actuator.health.indicator.DatabaseJdbcIndicator.DB_TIMEOUT_SECS
import play.api.db.Database

import java.sql.Connection
import javax.inject.Inject

class DatabaseJdbcIndicator @Inject() (database: Database) extends DatabaseIndicator {
class DatabaseJdbcIndicator @Inject() (database: Database) extends HealthIndicator {

private var connectionRef: Option[Connection] = None

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
play {
actuator {
indicator {
health {
redis = true
}
}
}
}

play.modules.enabled += "play.actuator.ActuatorRedisModule"
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2022 Felipe Bonezi <https://about.me/felipebonezi>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package play.actuator

import com.google.inject.AbstractModule
import com.google.inject.name.Names
import play.actuator.ActuatorEnum.Up
import play.actuator.health.HealthBuilder
import play.actuator.health.indicator.HealthIndicator
import play.actuator.health.indicator.RedisHealthIndicator
import play.api.Configuration
import play.api.Environment

class ActuatorRedisModule(environment: Environment, config: Configuration) extends AbstractModule {

override def configure(): Unit = {
val confKey = "play.actuator.health.indicators.redis"
if (config.getOptional[Boolean](confKey).getOrElse(false)) {
bind(classOf[HealthIndicator])
.annotatedWith(Names.named("redisIndicator"))
.to(classOf[RedisHealthIndicator])
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package actuator.health.indicator
package play.actuator.health.indicator

import com.typesafe.config.Config
import play.actuator.ActuatorEnum
Expand All @@ -29,10 +29,10 @@ import javax.inject.Inject
import scala.concurrent.Await
import scala.concurrent.duration.DurationInt

class PlayRedisIndicator @Inject() (
class RedisHealthIndicator @Inject() (
config: Config,
connector: RedisConnector
) extends RedisIndicator {
) extends HealthIndicator {

override def info(builder: HealthBuilder): Unit = {
if (this.config.getString("play.cache.redis.recovery") != "log-and-fail") {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
play {
actuator {
indicator {
health {
database = true
}
}
}
}

play.modules.enabled += "play.actuator.ActuatorSlickModule"
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,24 @@
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package actuator.health.indicator
import play.actuator.health.indicator.BaseHealthIndicator
package play.actuator

trait RedisIndicator extends BaseHealthIndicator {}
import com.google.inject.AbstractModule
import com.google.inject.name.Names
import play.actuator.health.indicator.DatabaseSlickIndicator
import play.actuator.health.indicator.HealthIndicator
import play.api.Configuration
import play.api.Environment

class ActuatorSlickModule(environment: Environment, config: Configuration) extends AbstractModule {

override def configure(): Unit = {
val confKey = "play.actuator.health.indicators.database"
if (config.getOptional[Boolean](confKey).getOrElse(false)) {
bind(classOf[HealthIndicator])
.annotatedWith(Names.named("databaseIndicator"))
.to(classOf[DatabaseSlickIndicator])
}
}

}
Loading

0 comments on commit 4fc46d3

Please sign in to comment.