Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bumps CE3 #363

Merged
merged 1 commit into from
Dec 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ addCommandAlias("ci-test", "scalafmtCheckAll; scalafmtSbtCheck; mdoc; testCovere
addCommandAlias("ci-docs", "github; mdoc; headerCreateAll; publishMicrosite")
addCommandAlias("ci-publish", "github; ci-release")

skip in publish := true
publish / skip := true

lazy val `sbt-hood-core` = project
.in(file("modules/core"))
Expand All @@ -18,9 +18,9 @@ lazy val `sbt-hood-plugin` = project
lazy val microsite = project
.enablePlugins(MicrositesPlugin)
.settings(micrositeSettings: _*)
.settings(skip in publish := true)
.settings(publish / skip := true)

lazy val documentation = project
.enablePlugins(MdocPlugin)
.settings(mdocOut := file("."))
.settings(skip in publish := true)
.settings(publish / skip := true)
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
package com.fortysevendeg.hood.github

import cats.data.{EitherT, NonEmptyList}
import cats.effect.{ConcurrentEffect, Resource, Sync}
import cats.effect.{Async, Resource}
import cats.implicits._
import com.fortysevendeg.hood.github.instances._
import com.github.marklister.base64.Base64._
import github4s.Github
import github4s.domain._
import org.typelevel.log4cats.Logger
import org.http4s.blaze.client.BlazeClientBuilder
import org.http4s.client.Client
import org.http4s.client.blaze.BlazeClientBuilder

import scala.concurrent.ExecutionContext

Expand Down Expand Up @@ -77,12 +77,12 @@ trait GithubService[F[_]] {

object GithubService {

def build[F[_]: ConcurrentEffect: Logger](
def build[F[_]: Async: Logger](
clientEC: ExecutionContext
): Resource[F, GithubService[F]] =
BlazeClientBuilder[F](clientEC).resource.map(new GithubServiceImpl[F](_))
BlazeClientBuilder[F].withExecutionContext(clientEC).resource.map(new GithubServiceImpl[F](_))

class GithubServiceImpl[F[_]: Sync](clientEC: Client[F])(implicit L: Logger[F])
class GithubServiceImpl[F[_]: Async](clientEC: Client[F])(implicit L: Logger[F])
extends GithubService[F] {

def publishComment(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class CsvServiceTests extends AnyFlatSpec with Matchers {

implicit val logger = Slf4jLogger.getLogger[IO]

import cats.effect.unsafe.implicits.global

"CsvService" should "parse a correct CSV file" in {
val dataFile = new File(getClass.getResource("/jmh.csv").getPath)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class JsonServiceTests extends AnyFlatSpec with Matchers {

implicit val logger = Slf4jLogger.getLogger[IO]

import cats.effect.unsafe.implicits.global

"JsonService" should "parse a correct json file" in {
val dataFile = new File(getClass.getResource("/jmh.json").getPath)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@
package com.fortysevendeg.hood.plugin

import java.io.File

import cats.data.{EitherT, NonEmptyChain}
import cats.effect.{Async, IO}
import cats.effect.std.Console
import cats.implicits._
import cats.effect.{ConcurrentEffect, Console, ContextShift, IO, Sync}
import com.fortysevendeg.hood.benchmark.{BenchmarkComparisonResult, BenchmarkService, Warning}
import com.fortysevendeg.hood.csv.{BenchmarkColumns, CsvService}
import com.fortysevendeg.hood.model._
import sbt.{AutoPlugin, Def, PluginTrigger, Task}
import org.typelevel.log4cats.slf4j.Slf4jLogger
import io.circe.syntax._
import cats.effect.Console.implicits._
import com.fortysevendeg.hood.github._
import com.fortysevendeg.hood.benchmark.Error
import com.fortysevendeg.hood.json.JsonService
import com.fortysevendeg.hood.utils._
import Benchmark._
import cats.Applicative
import com.fortysevendeg.hood.github.instances.Github4sError
import com.lightbend.emoji.ShortCodes.Implicits._
import com.lightbend.emoji.ShortCodes.Defaults._
Expand All @@ -56,15 +56,15 @@ object SbtHoodPlugin extends AutoPlugin with SbtHoodDefaultSettings with SbtHood

override val trigger: PluginTrigger = noTrigger

implicit lazy val logger: Logger[IO] = Slf4jLogger.getLogger[IO]
implicit lazy val CS: ContextShift[IO] = IO.contextShift(ExecutionContext.global)
implicit lazy val CE: ConcurrentEffect[IO] = IO.ioConcurrentEffect
implicit lazy val logger: Logger[IO] = Slf4jLogger.getLogger[IO]

import cats.effect.unsafe.implicits.global

def compareBenchmarksTask: Def.Initialize[Task[Unit]] =
Def.task {

TaskAlgebra
.benchmarkTask(
.benchmarkTask[IO](
previousBenchmarkPath.value,
currentBenchmarkPath.value,
keyColumnName.value,
Expand Down Expand Up @@ -94,7 +94,7 @@ object SbtHoodPlugin extends AutoPlugin with SbtHoodDefaultSettings with SbtHood
(for {
basicBenchmark <-
TaskAlgebra
.benchmarkTask(
.benchmarkTask[IO](
previousBenchmarkPath.value,
currentBenchmarkPath.value,
keyColumnName.value,
Expand Down Expand Up @@ -124,7 +124,7 @@ object SbtHoodPlugin extends AutoPlugin with SbtHoodDefaultSettings with SbtHood
)
_ <- EitherT(
TaskAlgebra
.submitResultsToGitHub(
.submitResultsToGitHub[IO](
basicBenchmark,
previousBenchmarkPath.value,
currentBenchmarkPath.value,
Expand Down Expand Up @@ -184,7 +184,7 @@ object SbtHoodPlugin extends AutoPlugin with SbtHoodDefaultSettings with SbtHood
object TaskAlgebra {
val commentPrefix = "sbt-hood benchmark result"

def benchmarkTask[F[_]: Sync: Logger](
def benchmarkTask[F[_]: Async: Logger](
previousPath: File,
currentPath: File,
keyColumnName: String,
Expand Down Expand Up @@ -227,7 +227,7 @@ object TaskAlgebra {
)
)
_ <- EitherT(
writeOutputFile(
writeOutputFile[F](
shouldOutputToFile,
outputFilePath,
outputFileFormat,
Expand All @@ -239,12 +239,12 @@ object TaskAlgebra {
)
)
outputMessage = benchmarkOutput(result, previousPath.getName, currentPath.getName)
_ <- EitherT.right(C.putStrLn(outputMessage))
_ <- EitherT.right(C.println(outputMessage))
} yield result

}

def submitResultsToGitHub[F[_]: ConcurrentEffect: Logger](
def submitResultsToGitHub[F[_]: Async: Logger](
benchmarkResult: List[BenchmarkComparisonResult],
previousPath: File,
currentPath: File,
Expand All @@ -260,7 +260,7 @@ object TaskAlgebra {
params.pullRequestNumber
)

earliestHoodComment = commentsList.filter(_.body.contains(commentPrefix)).headOption
earliestHoodComment = commentsList.find(_.body.contains(commentPrefix))
comment =
s"## $commentPrefix:\n\n${benchmarkOutput(benchmarkResult, previousPath.getName, currentPath.getName)}"

Expand Down Expand Up @@ -302,7 +302,7 @@ object TaskAlgebra {
} yield ()).value
}

def uploadFilesToGitHub[F[_]: ConcurrentEffect: Logger](
def uploadFilesToGitHub[F[_]: Async: Logger](
files: List[(String, String)],
params: GitHubParameters
): F[Either[Github4sError, Unit]] =
Expand Down Expand Up @@ -343,7 +343,7 @@ object TaskAlgebra {
previousBenchmarks: Map[String, Benchmark],
generalThreshold: Option[Double],
thresholdMap: Map[String, Double]
)(implicit L: Logger[F], S: Sync[F]): F[List[BenchmarkComparisonResult]] =
)(implicit L: Logger[F], F: Async[F]): F[List[BenchmarkComparisonResult]] =
previousBenchmarks.toList
.traverse { case (benchmarkKey, previous) =>
val threshold =
Expand All @@ -357,10 +357,10 @@ object TaskAlgebra {
L.error(
s"Benchmark $benchmarkKey existing in previous benchmarks is missing from current ones."
).as(BenchmarkComparisonResult(previous, None, Warning, threshold))
)(current => S.delay(BenchmarkService.compare(current, previous, threshold)))
)(current => F.delay(BenchmarkService.compare(current, previous, threshold)))
}

def writeOutputFile[F[_]](
def writeOutputFile[F[_]: Async](
shouldOutputToFile: Boolean,
outputPath: File,
outputFileFormat: OutputFileFormat,
Expand All @@ -369,7 +369,7 @@ object TaskAlgebra {
currentFile: String,
previousBenchmarks: Map[String, Benchmark],
currentBenchmarks: Map[String, Benchmark]
)(implicit S: Sync[F]): F[Either[HoodError, Unit]] =
): F[Either[HoodError, Unit]] =
if (shouldOutputToFile) {
val collectedBenchmarks =
collectBenchmarks(
Expand All @@ -389,7 +389,7 @@ object TaskAlgebra {
EitherT(FileUtils.writeFile(outputPath, fileContents))
.leftMap[HoodError](e => OutputFileError(e.getMessage))
.value
} else S.pure(Either.right(()))
} else ().asRight[HoodError].pure[F]

def collectBenchmarks(
previousFile: String,
Expand Down Expand Up @@ -447,22 +447,18 @@ object TaskAlgebra {
else
GithubStatusDescription(GithubStatusSuccess, "Successful benchmark comparison")

def parseBenchmark[F[_]](
def parseBenchmark[F[_]: Applicative](
columns: BenchmarkColumns,
file: File,
csvService: CsvService[F],
jsonService: JsonService[F]
)(implicit S: Sync[F]): F[Either[HoodError, List[Benchmark]]] = {

): F[Either[HoodError, List[Benchmark]]] =
FileUtils.fileType(file) match {
case Csv => csvService.parseBenchmark(columns, file)
case Json => jsonService.parseBenchmark(file)
case _ =>
S.pure(
BenchmarkLoadingError(s"Invalid file type for file: ${file.getName}")
.asLeft[List[Benchmark]]
)
(BenchmarkLoadingError(s"Invalid file type for file: ${file.getName}"): HoodError)
.asLeft[List[Benchmark]]
.pure[F]
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ import java.io.File

import cats.data.EitherT
import cats.effect.IO
import cats.effect._
import com.fortysevendeg.hood.benchmark.BenchmarkComparisonResult
import org.typelevel.log4cats.slf4j.Slf4jLogger
import cats.effect.Console.implicits._
import com.fortysevendeg.hood.json.JsonService
import com.fortysevendeg.hood.model.{Benchmark, HoodError}
import org.scalatest.flatspec.AnyFlatSpec
Expand All @@ -33,6 +31,8 @@ class SbtHoodPluginTests extends AnyFlatSpec with Matchers with TestUtils {

implicit val logger = Slf4jLogger.getLogger[IO]

import cats.effect.unsafe.implicits.global

val previousFileCsv = new File(getClass.getResource("/previous.csv").getPath)
val previousFileJson = new File(getClass.getResource("/previous.json").getPath)

Expand Down
30 changes: 15 additions & 15 deletions project/ProjectPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ object ProjectPlugin extends AutoPlugin {
micrositeDocumentationUrl := "docs",
micrositeGitterChannelUrl := "47deg/sbthood",
micrositeOrganizationHomepage := "http://www.47deg.com",
includeFilter in Jekyll := "*.html" | "*.css" | "*.png" | "*.jpg" | "*.gif" | "*.js" | "*.swf" | "*.md" | "*.svg",
Jekyll / includeFilter := "*.html" | "*.css" | "*.png" | "*.jpg" | "*.gif" | "*.js" | "*.swf" | "*.md" | "*.svg",
micrositePushSiteWith := GitHub4s,
micrositeHighlightTheme := "atom-one-light",
micrositeGithubToken := Option(System.getenv().get("GITHUB_TOKEN")),
Expand All @@ -35,20 +35,20 @@ object ProjectPlugin extends AutoPlugin {
Seq(
resolvers += Resolver.typesafeIvyRepo("releases"),
libraryDependencies ++= Seq(
"io.circe" %% "circe-generic" % "0.14.1",
"io.circe" %% "circe-core" % "0.14.1",
"io.circe" %% "circe-parser" % "0.14.1",
"org.http4s" %% "http4s-blaze-client" % "0.21.31",
"com.47deg" %% "github4s" % "0.28.5",
"org.typelevel" %% "cats-effect" % "2.5.4",
"org.typelevel" %% "log4cats-slf4j" % "1.4.0",
"ch.qos.logback" % "logback-classic" % "1.2.9",
"com.nrinaudo" %% "kantan.csv" % "0.6.2",
"com.nrinaudo" %% "kantan.csv-generic" % "0.6.2",
"dev.profunktor" %% "console4cats" % "0.8.1",
"com.lightbend" %% "emoji" % "1.2.3",
"org.scalatest" %% "scalatest" % "3.2.10" % Test,
"org.slf4j" % "slf4j-nop" % "1.7.32" % Test
"io.circe" %% "circe-generic" % "0.14.1",
"io.circe" %% "circe-core" % "0.14.1",
"io.circe" %% "circe-parser" % "0.14.1",
"org.http4s" %% "http4s-blaze-client" % "0.23.7",
"com.47deg" %% "github4s" % "0.30.0",
"org.typelevel" %% "cats-effect" % "3.3.0",
"org.typelevel" %% "log4cats-slf4j" % "2.1.1",
"ch.qos.logback" % "logback-classic" % "1.2.9",
"com.nrinaudo" %% "kantan.csv" % "0.6.2",
"com.nrinaudo" %% "kantan.csv-generic" % "0.6.2",
"com.lightbend" %% "emoji" % "1.2.3",
"com.github.marklister" %% "base64" % "0.3.0",
"org.scalatest" %% "scalatest" % "3.2.10" % Test,
"org.typelevel" %% "log4cats-noop" % "2.1.1" % Test
)
)
}