Skip to content

Commit

Permalink
Merge pull request #75 from mobimeo/add-scala-3
Browse files Browse the repository at this point in the history
Add Scala 3 (and modernise build)
  • Loading branch information
ChristopherDavenport authored Aug 27, 2021
2 parents e869123 + 1cae1fa commit 80d8863
Show file tree
Hide file tree
Showing 8 changed files with 224 additions and 160 deletions.
128 changes: 128 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
# This file was automatically generated by sbt-github-actions using the
# githubWorkflowGenerate task. You should add and commit this file to
# your git repository. It goes without saying that you shouldn't edit
# this file by hand! Instead, if you wish to make changes, you should
# change your sbt build configuration to revise the workflow description
# to meet your needs, then regenerate this file.

name: Continuous Integration

on:
pull_request:
branches: ['**']
push:
branches: ['**']
tags: [v*]

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
build:
name: Build and Test
strategy:
matrix:
os: [ubuntu-latest]
scala: [2.12.14, 2.13.6, 3.0.0]
java: [[email protected], [email protected]]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (full)
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Setup Java and Scala
uses: olafurpg/setup-scala@v12
with:
java-version: ${{ matrix.java }}

- name: Cache sbt
uses: actions/cache@v2
with:
path: |
~/.sbt
~/.ivy2/cache
~/.coursier/cache/v1
~/.cache/coursier/v1
~/AppData/Local/Coursier/Cache/v1
~/Library/Caches/Coursier/v1
key: ${{ runner.os }}-sbt-cache-v2-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}

- name: Setup Ruby
if: matrix.scala == '2.13.6'
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.0.1

- name: Install microsite dependencies
if: matrix.scala == '2.13.6'
run: |
gem install saas
gem install jekyll -v 4.2.0
- name: Check that workflows are up to date
run: sbt --client '++${{ matrix.scala }}; githubWorkflowCheck'

- run: sbt --client '++${{ matrix.scala }}; test; mimaReportBinaryIssues'

- if: matrix.scala == '2.13.6'
run: sbt --client '++${{ matrix.scala }}; site/makeMicrosite'

publish:
name: Publish Artifacts
needs: [build]
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main')
strategy:
matrix:
os: [ubuntu-latest]
scala: [2.13.6]
java: [[email protected]]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (full)
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Setup Java and Scala
uses: olafurpg/setup-scala@v12
with:
java-version: ${{ matrix.java }}

- name: Cache sbt
uses: actions/cache@v2
with:
path: |
~/.sbt
~/.ivy2/cache
~/.coursier/cache/v1
~/.cache/coursier/v1
~/AppData/Local/Coursier/Cache/v1
~/Library/Caches/Coursier/v1
key: ${{ runner.os }}-sbt-cache-v2-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}

- uses: olafurpg/setup-gpg@v3

- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.0.1

- name: Install microsite dependencies
run: |
gem install saas
gem install jekyll -v 4.2.0
- name: Publish artifacts to Sonatype
env:
PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }}
PGP_SECRET: ${{ secrets.PGP_SECRET }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
run: sbt --client '++${{ matrix.scala }}; ci-release'

- uses: christopherdavenport/create-ghpages-ifnotexists@v1

- name: Publish microsite
run: sbt --client '++${{ matrix.scala }}; site/publishMicrosite'
59 changes: 59 additions & 0 deletions .github/workflows/clean.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# This file was automatically generated by sbt-github-actions using the
# githubWorkflowGenerate task. You should add and commit this file to
# your git repository. It goes without saying that you shouldn't edit
# this file by hand! Instead, if you wish to make changes, you should
# change your sbt build configuration to revise the workflow description
# to meet your needs, then regenerate this file.

name: Clean

on: push

jobs:
delete-artifacts:
name: Delete Artifacts
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Delete artifacts
run: |
# Customize those three lines with your repository and credentials:
REPO=${GITHUB_API_URL}/repos/${{ github.repository }}
# A shortcut to call GitHub API.
ghapi() { curl --silent --location --user _:$GITHUB_TOKEN "$@"; }
# A temporary file which receives HTTP response headers.
TMPFILE=/tmp/tmp.$$
# An associative array, key: artifact name, value: number of artifacts of that name.
declare -A ARTCOUNT
# Process all artifacts on this repository, loop on returned "pages".
URL=$REPO/actions/artifacts
while [[ -n "$URL" ]]; do
# Get current page, get response headers in a temporary file.
JSON=$(ghapi --dump-header $TMPFILE "$URL")
# Get URL of next page. Will be empty if we are at the last page.
URL=$(grep '^Link:' "$TMPFILE" | tr ',' '\n' | grep 'rel="next"' | head -1 | sed -e 's/.*<//' -e 's/>.*//')
rm -f $TMPFILE
# Number of artifacts on this page:
COUNT=$(( $(jq <<<$JSON -r '.artifacts | length') ))
# Loop on all artifacts on this page.
for ((i=0; $i < $COUNT; i++)); do
# Get name of artifact and count instances of this name.
name=$(jq <<<$JSON -r ".artifacts[$i].name?")
ARTCOUNT[$name]=$(( $(( ${ARTCOUNT[$name]} )) + 1))
id=$(jq <<<$JSON -r ".artifacts[$i].id?")
size=$(( $(jq <<<$JSON -r ".artifacts[$i].size_in_bytes?") ))
printf "Deleting '%s' #%d, %'d bytes\n" $name ${ARTCOUNT[$name]} $size
ghapi -X DELETE $REPO/actions/artifacts/$id
done
done
57 changes: 0 additions & 57 deletions .travis.yml

This file was deleted.

87 changes: 17 additions & 70 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import sbtcrossproject.CrossPlugin.autoImport.{crossProject, CrossType}
val scala213 = "2.13.6"

val specs2V = "4.8.1"
ThisBuild / scalaVersion := scala213
ThisBuild / crossScalaVersions := Seq("2.12.14", scala213, "3.0.0")

val kindProjectorV = "0.11.2"
ThisBuild / licenses := Seq("MIT" -> url("http://opensource.org/licenses/MIT"))

val kindProjectorV = "0.13.0"
val betterMonadicForV = "0.3.1"

// Projects
Expand All @@ -23,85 +26,29 @@ lazy val core = project.in(file("core"))
})
)

// Microsite via sbt-davenverse
lazy val site = project.in(file("site"))
.disablePlugins(MimaPlugin)
.enablePlugins(MicrositesPlugin)
.enablePlugins(MdocPlugin)
.enablePlugins(NoPublishPlugin)
.settings(commonSettings)
.enablePlugins(DavenverseMicrositePlugin)
.dependsOn(core)
.settings{
import microsites._
Seq(
micrositeName := "epimetheus-redis4cats",
micrositeDescription := "Redis4cats Metrics",
micrositeAuthor := "Christopher Davenport",
micrositeGithubOwner := "ChristopherDavenport",
micrositeGithubRepo := "epimetheus-redis4cats",
micrositeBaseUrl := "/epimetheus-redis4cats",
micrositeDocumentationUrl := "https://www.javadoc.io/doc/io.chrisdavenport/epimetheus-redis4cats_2.12",
micrositeGitterChannelUrl := "ChristopherDavenport/libraries", // Feel Free to Set To Something Else
micrositeFooterText := None,
micrositeHighlightTheme := "atom-one-light",
micrositePalette := Map(
"brand-primary" -> "#3e5b95",
"brand-secondary" -> "#294066",
"brand-tertiary" -> "#2d5799",
"gray-dark" -> "#49494B",
"gray" -> "#7B7B7E",
"gray-light" -> "#E5E5E6",
"gray-lighter" -> "#F4F3F4",
"white-color" -> "#FFFFFF"
),
micrositeCompilingDocsTool := WithMdoc,
scalacOptions in Tut --= Seq(
"-Xfatal-warnings",
"-Ywarn-unused-import",
"-Ywarn-numeric-widen",
"-Ywarn-dead-code",
"-Ywarn-unused:imports",
"-Xlint:-missing-interpolator,_"
),
micrositePushSiteWith := GitHub4s,
micrositeGithubToken := sys.env.get("GITHUB_TOKEN"),
micrositeExtraMdFiles := Map(
file("CODE_OF_CONDUCT.md") -> ExtraMdFileConfig("code-of-conduct.md", "page", Map("title" -> "code of conduct", "section" -> "code of conduct", "position" -> "100")),
file("LICENSE") -> ExtraMdFileConfig("license.md", "page", Map("title" -> "license", "section" -> "license", "position" -> "101"))
)
)
}

// General Settings
lazy val commonSettings = Seq(
scalaVersion := "2.13.4",
crossScalaVersions := Seq(scalaVersion.value, "2.12.12"),

addCompilerPlugin("org.typelevel" %% "kind-projector" % kindProjectorV cross CrossVersion.full),
addCompilerPlugin("com.olegpy" %% "better-monadic-for" % betterMonadicForV),

libraryDependencies ++= Seq(
"io.chrisdavenport" %% "epimetheus" % "0.4.0",
"dev.profunktor" %% "redis4cats-effects" % "0.11.1",

"org.specs2" %% "specs2-core" % specs2V % Test,
"org.specs2" %% "specs2-scalacheck" % specs2V % Test
)
)

// General Settings
inThisBuild(List(
organization := "io.chrisdavenport",
developers := List(
Developer("ChristopherDavenport", "Christopher Davenport", "[email protected]", url("https://github.com/ChristopherDavenport"))
"io.chrisdavenport" %% "epimetheus" % "0.5.0-M2",
"dev.profunktor" %% "redis4cats-effects" % "1.0.0"
),

homepage := Some(url("https://github.com/ChristopherDavenport/epimetheus-redis4cats")),
licenses += ("MIT", url("http://opensource.org/licenses/MIT")),

pomIncludeRepository := { _ => false},
scalacOptions in (Compile, doc) ++= Seq(
"-groups",
"-sourcepath", (baseDirectory in LocalRootProject).value.getAbsolutePath,
"-doc-source-url", "https://github.com/ChristopherDavenport/epimetheus-redis4cats/blob/v" + version.value + "€{FILE_PATH}.scala"
)
))
libraryDependencies ++= PartialFunction.condOpt(CrossVersion.partialVersion(scalaVersion.value)) { case Some((2, _)) =>
Seq(
compilerPlugin("org.typelevel" % "kind-projector" % kindProjectorV cross CrossVersion.full),
compilerPlugin("com.olegpy" %% "better-monadic-for" % betterMonadicForV)
)
}.toList.flatten
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import cats._
import cats.implicits._
import cats.effect._
import io.chrisdavenport.epimetheus._
import shapeless._


trait RedisMetricOps[M[_]] {
Expand Down Expand Up @@ -84,15 +83,15 @@ object RedisMetricOps {
prefix |+| Name("_") |+| Name("operations"),
"Total Operations.",
Sized(Label("termination_type"), Label("classifier")),
{ op: (TerminationType, Classifier) => Sized(reportTermination(op._1), op._2.value)},
{ (op: (TerminationType, Classifier)) => Sized(reportTermination(op._1), op._2.value)},
buckets:_*
)
active<- Gauge.labelled(
cr,
prefix |+| Name("_") |+| Name("active"),
"Total Active Operations.",
Sized(Label("classifier")),
{c: Classifier => Sized(c.value)}
{(c: Classifier) => Sized(c.value)}
)

} yield MetricsCollection[F](operations, active)
Expand All @@ -117,4 +116,4 @@ object RedisMetricOps {
private val nanoseconds_per_second = 1E9


}
}
Loading

0 comments on commit 80d8863

Please sign in to comment.