Skip to content

Commit

Permalink
More updates, linters, formatting changes
Browse files Browse the repository at this point in the history
  • Loading branch information
keynmol committed Dec 13, 2024
1 parent daa735f commit 4a110ae
Show file tree
Hide file tree
Showing 67 changed files with 586 additions and 608 deletions.
1 change: 1 addition & 0 deletions .sbtopts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-J-Xmx4g
12 changes: 12 additions & 0 deletions .scalafix.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
OrganizeImports {
coalesceToWildcardImportThreshold = 3 # Int.MaxValue
expandRelative = false
groupExplicitlyImportedImplicitsSeparately = false
groupedImports = Explode
groups = ["re:javax?\\.", "scala.", "*"]
importSelectorsOrder = Ascii
importsOrder = Ascii
removeUnused = false
}
OrganizeImports.targetDialect = Scala3
OrganizeImports.removeUnused = true
17 changes: 15 additions & 2 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
version = "3.8.3"

runner.dialect = scala3
rewrite.scala3.insertEndMarkerMinLines = 10
rewrite.scala3.removeOptionalBraces = true
Expand All @@ -9,9 +10,21 @@ fileOverride {
"glob:**.sbt" {
runner.dialect = scala212source3
}

"glob:**/project/**.*" {
"glob:**/project/*.scala" {
runner.dialect = scala212source3
}

"glob:**/project/plugins.sbt" {
runner.dialect = scala212source3
newlines.topLevelStatementBlankLines = [
{
blanks = 1,
minBreaks = 0
}
]
}
}

rewrite {
trailingCommas.style = "always"
}
90 changes: 63 additions & 27 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ val Versions = new {
val TestContainers = "0.41.4"
val Weaver = "0.8.4"
val WeaverPlaywright = "0.0.5"
val Laminar = "15.0.1"
val waypoint = "6.0.0"
val Laminar = "17.2.0"
val waypoint = "9.0.0"
val scalacss = "1.0.0"
val monocle = "3.2.0"
val circe = "0.14.5"
val circe = "0.14.10"
val macroTaskExecutor = "1.1.1"
}

Expand Down Expand Up @@ -52,21 +52,21 @@ lazy val app = projectMatrix
dockerBaseImage := Config.DockerBaseImage,
Docker / packageName := Config.DockerImageName,
libraryDependencies ++= Seq(
"org.http4s" %% "http4s-blaze-server" % Versions.http4sBlaze,
"org.http4s" %% "http4s-ember-server" % Versions.http4s,
"org.postgresql" % "postgresql" % Versions.Postgres,
"org.flywaydb" % "flyway-database-postgresql" % Versions.FlywayPG
"org.http4s" %% "http4s-blaze-server" % Versions.http4sBlaze,
"org.http4s" %% "http4s-ember-server" % Versions.http4s,
"org.postgresql" % "postgresql" % Versions.Postgres,
"org.flywaydb" % "flyway-database-postgresql" % Versions.FlywayPG,
),
Compile / resourceGenerators += {
Def.task[Seq[File]] {
copyAll(
frontendBundle.value,
(Compile / resourceManaged).value / "assets"
(Compile / resourceManaged).value / "assets",
)
}
},
reStart / baseDirectory := (ThisBuild / baseDirectory).value,
run / baseDirectory := (ThisBuild / baseDirectory).value
run / baseDirectory := (ThisBuild / baseDirectory).value,
)

def copyAll(location: File, outDir: File) = {
Expand All @@ -80,13 +80,18 @@ def copyAll(location: File, outDir: File) = {
}
}

val scalacSettings = Seq(
scalacOptions += "-Wunused:all",
)

lazy val backend = projectMatrix
.in(file("modules/backend"))
.dependsOn(shared)
.defaultAxes(defaults*)
.jvmPlatform(Seq(Versions.Scala))
.settings(
scalaVersion := Versions.Scala,
scalaVersion := Versions.Scala,
scalacSettings,
Compile / doc / sources := Seq.empty,
libraryDependencies ++= Seq(
"com.disneystreaming.smithy4s" %% "smithy4s-http4s" % smithy4sVersion.value,
Expand All @@ -96,7 +101,7 @@ lazy val backend = projectMatrix
"com.outr" %% "scribe" % Versions.scribe,
"com.outr" %% "scribe-cats" % Versions.scribe,
"com.outr" %% "scribe-slf4j" % Versions.scribe,
"org.tpolecat" %% "skunk-core" % Versions.skunk
"org.tpolecat" %% "skunk-core" % Versions.skunk,
),
libraryDependencies ++=
Seq(
Expand All @@ -109,7 +114,7 @@ lazy val backend = projectMatrix
"org.http4s" %% "http4s-ember-server" % Versions.http4s,
"org.http4s" %% "http4s-ember-client" % Versions.http4s,
"org.postgresql" % "postgresql" % Versions.Postgres,
"org.flywaydb" % "flyway-database-postgresql" % Versions.FlywayPG
"org.flywaydb" % "flyway-database-postgresql" % Versions.FlywayPG,
).map(_ % Test),
testFrameworks += new TestFramework("weaver.framework.CatsEffect"),
Test / fork := true,
Expand All @@ -118,10 +123,10 @@ lazy val backend = projectMatrix
Def.task[Seq[File]] {
copyAll(
frontendBundle.value,
(Test / resourceManaged).value / "assets"
(Test / resourceManaged).value / "assets",
)
}
}
},
)

lazy val shared = projectMatrix
Expand All @@ -131,29 +136,31 @@ lazy val shared = projectMatrix
.jsPlatform(Seq(Versions.Scala))
.enablePlugins(Smithy4sCodegenPlugin)
.settings(
scalacSettings,
libraryDependencies ++= Seq(
"com.disneystreaming.smithy4s" %%% "smithy4s-http4s" % smithy4sVersion.value,
"io.lemonlabs" %%% "scala-uri" % "4.0.3"
"com.indoorvivants" %%% "scala-uri" % "4.1.0",
),
Compile / doc / sources := Seq.empty
Compile / doc / sources := Seq.empty,
)

lazy val frontend = projectMatrix
.in(file("modules/frontend"))
.customRow(
Seq(Versions.Scala),
axisValues = Seq(VirtualAxis.js, BuildStyle.SingleFile),
Seq.empty
Seq.empty,
)
.customRow(
Seq(Versions.Scala),
axisValues = Seq(VirtualAxis.js, BuildStyle.Modules),
Seq.empty
Seq.empty,
)
.defaultAxes((defaults :+ VirtualAxis.js)*)
.dependsOn(shared)
.enablePlugins(ScalaJSPlugin, BundleMonPlugin)
.settings(
scalacSettings,
scalaJSUseMainModuleInitializer := true,
scalaJSLinkerConfig := {
val config = scalaJSLinkerConfig.value
Expand All @@ -163,7 +170,7 @@ lazy val frontend = projectMatrix
config
.withModuleSplitStyle(
ModuleSplitStyle
.SmallModulesFor(List(s"${Config.BasePackage}.frontend"))
.SmallModulesFor(List(s"${Config.BasePackage}.frontend")),
)
.withModuleKind(ModuleKind.ESModule)
.withOutputPatterns(OutputPatterns.fromJSFile("%s.mjs"))
Expand All @@ -177,8 +184,8 @@ lazy val frontend = projectMatrix
"io.circe" %%% "circe-core" % Versions.circe,
"io.circe" %%% "circe-parser" % Versions.circe,
"org.http4s" %%% "http4s-dom" % Versions.http4sDom,
"org.scala-js" %%% "scala-js-macrotask-executor" % Versions.macroTaskExecutor
)
"org.scala-js" %%% "scala-js-macrotask-executor" % Versions.macroTaskExecutor,
),
)

lazy val defaults =
Expand All @@ -187,7 +194,7 @@ lazy val defaults =
lazy val frontendModules = taskKey[(Report, File)]("")
ThisBuild / frontendModules := Def.taskIf {
def proj = frontend.finder(BuildStyle.Modules)(
Versions.Scala
Versions.Scala,
)

if (isRelease)
Expand All @@ -201,7 +208,7 @@ ThisBuild / frontendModules := Def.taskIf {
lazy val frontendBundle = taskKey[File]("")
ThisBuild / frontendBundle := Def.taskIf {
def proj = frontend.finder(BuildStyle.SingleFile)(
Versions.Scala
Versions.Scala,
)

if (isRelease) {
Expand All @@ -220,17 +227,46 @@ addCommandAlias("stubTests", "backend/testOnly jobby.tests.stub.*")
addCommandAlias("unitTests", "backend/testOnly jobby.tests.unit.*")
addCommandAlias(
"fastTests",
"backend/testOnly jobby.tests.stub.* jobby.tests.unit.*"
"backend/testOnly jobby.tests.stub.* jobby.tests.unit.*",
)
addCommandAlias(
"integrationTests",
"backend/testOnly jobby.tests.integration.*"
"backend/testOnly jobby.tests.integration.*",
)
addCommandAlias(
"frontendTests",
"backend/testOnly jobby.tests.frontend.*"
"backend/testOnly jobby.tests.frontend.*",
)

val scalafixRules = Seq(
"OrganizeImports",
"DisableSyntax",
"LeakingImplicitClassVal",
"NoValInForComprehension",
).mkString(" ")

val CICommands = Seq(
"clean",
"scalafixEnable",
"compile",
"test",
"scalafmtCheckAll",
"scalafmtSbtCheck",
s"scalafix --check $scalafixRules",
).mkString(";")

val PrepareCICommands = Seq(
"scalafixEnable",
s"scalafix --rules $scalafixRules",
s"Test/scalafix --rules $scalafixRules",
"scalafmtAll",
"scalafmtSbt",
).mkString(";")

addCommandAlias("ci", CICommands)

addCommandAlias("preCI", PrepareCICommands)

lazy val buildFrontend = taskKey[Unit]("")

buildFrontend := {
Expand All @@ -250,7 +286,7 @@ buildFrontend := {
ThisBuild / concurrentRestrictions ++= {
if (sys.env.contains("CI")) {
Seq(
Tags.limitAll(4)
Tags.limitAll(4),
)
} else Seq.empty
}
5 changes: 5 additions & 0 deletions jobby.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
PG_USER=jobby
PG_PASSWORD=mysecretpassword
PG_DB=jobby
LOCAL_DEPLOYMENT=true
PG_PORT=5439
2 changes: 1 addition & 1 deletion modules/backend/src/main/scala/FlyIOLoader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class FlyIOLoader(env: Map[String, String]):
user = userName,
password = Some(password),
database = dbName,
ssl = false
ssl = false,
)
}.toOption

Expand Down
2 changes: 1 addition & 1 deletion modules/backend/src/main/scala/HerokuLoader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class HerokuLoader(env: Map[String, String]):
user = userName,
password = Some(password),
database = dbName,
ssl = true
ssl = true,
)
}.toOption

Expand Down
7 changes: 4 additions & 3 deletions modules/backend/src/main/scala/PlatformShLoader.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package jobby

import java.util.Base64

import scala.util.Try
import scala.util.control.NonFatal

Expand All @@ -15,7 +16,7 @@ class PlatformShLoader(env: Map[String, String]):
scribe.error("Failed to parse PLATFORM_RELATIONSHIPS", error)
Option.empty
},
Option.apply
Option.apply,
)
}

Expand All @@ -31,8 +32,8 @@ class PlatformShLoader(env: Map[String, String]):
user = db("username").str,
database = db("path").str,
password = Some(db("password").str),
ssl = false
)
ssl = false,
),
)
catch
case exc =>
Expand Down
14 changes: 4 additions & 10 deletions modules/backend/src/main/scala/SkunkDatabase.scala
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
package jobby

import cats.effect.*
import org.typelevel.otel4s.trace.Tracer
import skunk.*
import cats.implicits.*
import skunk.*
import skunk.implicits.*
import skunk.codec.all.*
import jobby.spec.*
import smithy4s.Newtype
import database.codecs.*

import database.operations.*
import org.typelevel.otel4s.trace.Tracer

object SkunkDatabase:
def load(postgres: PgCredentials, skunkConfig: SkunkConfig)(using
Tracer[IO]
Tracer[IO],
): Resource[IO, Database] =
Session
.pooled[IO](
Expand All @@ -26,7 +20,7 @@ object SkunkDatabase:
strategy = skunkConfig.strategy,
max = skunkConfig.maxSessions,
debug = skunkConfig.debug,
ssl = if postgres.ssl then skunk.SSL.Trusted else skunk.SSL.None
ssl = if postgres.ssl then skunk.SSL.Trusted else skunk.SSL.None,
)
.map(SkunkDatabase(_))
end load
Expand Down
5 changes: 3 additions & 2 deletions modules/backend/src/main/scala/TimeCop.scala
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package jobby

import java.time.OffsetDateTime
import cats.effect.IO
import java.time.ZoneOffset
import smithy4s.Timestamp

import cats.effect.IO
import smithy4s.Newtype
import smithy4s.Timestamp

trait TimeCop:
def nowODT: IO[OffsetDateTime]
Expand Down
6 changes: 3 additions & 3 deletions modules/backend/src/main/scala/app.scala
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package jobby

import cats.effect.*
import scribe.Scribe
import org.typelevel.otel4s.trace.Tracer
import scribe.Scribe

class JobbyApp(
val config: AppConfig,
db: Database,
logger: Scribe[IO],
timeCop: TimeCop
timeCop: TimeCop,
)(using Tracer[IO]):
def routes = Routes(db, config, logger, timeCop)
end JobbyApp

object JobbyApp:
def bootstrap(config: AppConfig, logger: Scribe[IO])(using
Tracer[IO]
Tracer[IO],
) =
for db <- SkunkDatabase.load(config.postgres, config.skunk)
yield JobbyApp(config, db, logger, TimeCop.unsafe)
Loading

0 comments on commit 4a110ae

Please sign in to comment.