Skip to content

Commit

Permalink
Migrate to GitHub Actions + Sonatype
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel.beskin committed Apr 25, 2021
1 parent d981bec commit 5ffe327
Show file tree
Hide file tree
Showing 7 changed files with 205 additions and 60 deletions.
115 changes: 115 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# 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.13]
java: [adopt@1.8]
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@v10
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: Check that workflows are up to date
run: sbt ++${{ matrix.scala }} githubWorkflowCheck

- name: Build project
run: sbt ++${{ matrix.scala }} test

- name: Compress target directories
run: tar cf targets.tar app-common/target consul-app/target target core/target file-watcher-app/target project/target

- name: Upload target directories
uses: actions/upload-artifact@v2
with:
name: target-${{ matrix.os }}-${{ matrix.scala }}-${{ matrix.java }}
path: targets.tar

publish:
name: Publish Artifacts
needs: [build]
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v'))
strategy:
matrix:
os: [ubuntu-latest]
scala: [2.12.13]
java: [adopt@1.8]
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@v10
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: Download target directories (2.12.13)
uses: actions/download-artifact@v2
with:
name: target-${{ matrix.os }}-2.12.13-${{ matrix.java }}

- name: Inflate target directories (2.12.13)
run: |
tar xf targets.tar
rm targets.tar
- env:
PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }}
PGP_SECRET: ${{ secrets.PGP_SECRET }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
run: sbt ++${{ matrix.scala }} ci-release
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
36 changes: 0 additions & 36 deletions .travis.yml

This file was deleted.

47 changes: 27 additions & 20 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ lazy val `consul-app` =
.settings(name := "kafka-snow-white-consul-app")
.settings(baseSettings: _*)
.settings(libraryDependencies ++= (consulAppDependencies ++ consulAppTestDependencies))
.settings(mainClass in (Compile, run) := Some("com.supersonic.main.KafkaConsulMirrorApp"))
.settings(Compile / run / mainClass := Some("com.supersonic.main.KafkaConsulMirrorApp"))
.dependsOn(`app-common` % "compile -> compile; test -> test; it -> it")
}
}
Expand All @@ -49,24 +49,30 @@ lazy val `file-watcher-app` =
.settings(name := "kafka-snow-white-file-watcher-app")
.settings(baseSettings: _*)
.settings(libraryDependencies ++= fileAppDependencies)
.settings(mainClass in (Compile, run) := Some("com.supersonic.main.KafkaFileWatcherMirrorApp"))
.settings(Compile / run / mainClass := Some("com.supersonic.main.KafkaFileWatcherMirrorApp"))
.dependsOn(`app-common` % "compile -> compile; test -> test; it -> it")
}
}

sonatypeCredentialHost := Sonatype.sonatype01
inThisBuild(List(
licenses := List("Apache-2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0")),
organization := "com.supersonic",
homepage := Some(url("https://github.com/SupersonicAds/kafka-snow-white")),
licenses := List("Apache-2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0")),
developers := List(Developer("SupersonicAds", "SupersonicAds", "SupersonicAds", url("https://github.com/SupersonicAds"))),
scmInfo := Some(ScmInfo(url("https://github.com/SupersonicAds/kafka-snow-white"), "scm:git:git@github.com:SupersonicAds/kafka-snow-white.git")),

pgpPublicRing := file("./travis/local.pubring.asc"),
pgpSecretRing := file("./travis/local.secring.asc"),
releaseEarlyEnableSyncToMaven := false,
releaseEarlyWith := BintrayPublisher))
githubWorkflowPublishTargetBranches := Seq(RefPredicate.StartsWith(Ref.Tag("v"))),
githubWorkflowTargetTags ++= Seq("v*"),
githubWorkflowPublish := Seq(
WorkflowStep.Sbt(
List("ci-release"),
env = Map(
"PGP_PASSPHRASE" -> "${{ secrets.PGP_PASSPHRASE }}",
"PGP_SECRET" -> "${{ secrets.PGP_SECRET }}",
"SONATYPE_PASSWORD" -> "${{ secrets.SONATYPE_PASSWORD }}",
"SONATYPE_USERNAME" -> "${{ secrets.SONATYPE_USERNAME }}")))))

def baseSettings = List(
organization := "com.supersonic",
scalaVersion := "2.12.8",
scalacOptions ++= List(
"-encoding", "UTF-8",
Expand All @@ -80,14 +86,15 @@ def baseSettings = List(
"-Xlint",
"-Ypartial-unification",
"-P:splain:color:false"),
sonatypeCredentialHost := Sonatype.sonatype01,
resolvers += Resolver.jcenterRepo,
scalacOptions.in(Compile, console) ~= filterConsoleScalacOptions,
scalacOptions.in(Test, console) ~= filterConsoleScalacOptions,
sources in (Compile, doc) := List.empty,
Compile / console / scalacOptions ~= filterConsoleScalacOptions,
Test / console / scalacOptions ~= filterConsoleScalacOptions,
Compile / doc / sources := List.empty,
mergeStrategy,
// a workaround for https://github.com/sbt/sbt/issues/1380
makePomConfiguration := makePomConfiguration.value.withConfigurations(Configurations.defaultMavenConfigurations),
addCompilerPlugin("io.tryp" % "splain" % "0.4.0" cross CrossVersion.patch))
addCompilerPlugin("io.tryp" % "splain" % "0.5.8" cross CrossVersion.patch))

val akkaVersion = "2.5.21"
val akkaHTTPVersion = "10.1.8"
Expand Down Expand Up @@ -146,13 +153,13 @@ val IntegrationConfig = IntegrationTest.extend(Test)
def withIntegrationTests(project: Project) = {

val testWithIntegration =
test in Test := (test in IntegrationConfig).dependsOn(test in Test).value
Test / test := (IntegrationConfig / test).dependsOn(Test / test).value

val integrationTestSettings =
inConfig(IntegrationConfig)(testSettings) ++
Seq(
testWithIntegration,
parallelExecution in IntegrationConfig := false)
IntegrationConfig / parallelExecution := false)

project
.settings(integrationTestSettings)
Expand All @@ -163,19 +170,19 @@ def withIntegrationTests(project: Project) = {
def withAssemblyArtifact(project: Project) =
project
.settings {
artifact in (Compile, assembly) ~= { art =>
Compile / assembly / artifact ~= { art =>
art.withClassifier(Some("assembly"))

}
}
.settings(addArtifact(artifact in (Compile, assembly), assembly).settings: _*)
.settings(test in assembly := {})
.settings(addArtifact(Compile / assembly / artifact, assembly).settings: _*)
.settings(assembly / test := {})


def mergeStrategy =
assemblyMergeStrategy in assembly := {
assembly / assemblyMergeStrategy := {
case PathList("org", "apache", "commons", "collections", _*) => MergeStrategy.last
case x =>
val oldStrategy = (assemblyMergeStrategy in assembly).value
val oldStrategy = (assembly / assemblyMergeStrategy).value
oldStrategy(x)
}
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version = 1.2.8
sbt.version = 1.5.0
6 changes: 3 additions & 3 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ resolvers += Classpaths.sbtPluginReleases

addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.6")

addSbtPlugin("io.get-coursier" % "sbt-coursier" % "1.0.0")

addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "0.9.3")

addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.7.0")

addSbtPlugin("ch.epfl.scala" % "sbt-release-early" % "2.1.1")
addSbtPlugin("com.geirsson" % "sbt-ci-release" % "1.5.7")

addSbtPlugin("com.codecommit" % "sbt-github-actions" % "0.10.1")
Binary file removed travis/secrets.tar.enc
Binary file not shown.

0 comments on commit 5ffe327

Please sign in to comment.