Skip to content

Commit

Permalink
Merge pull request #121 from mkurz/gh-actions
Browse files Browse the repository at this point in the history
Switch to GitHub actions / Remove Travis CI / Setup sbt-ci-release
  • Loading branch information
mkurz authored Nov 27, 2023
2 parents ec27254 + 094dc2a commit d7d67f9
Show file tree
Hide file tree
Showing 19 changed files with 280 additions and 147 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Check

on:
pull_request:

push:
branches:
- main # Check branch after merge

concurrency:
# Only run once for latest commit per ref and cancel other (previous) runs.
group: ci-${{ github.ref }}
cancel-in-progress: true

jobs:
tests:
name: Tests
uses: playframework/.github/.github/workflows/cmd.yml@v3
with:
java: 21, 17, 11
scala: 2.13.x, 3.x
cmd: |
cd code;
sbt ++$MATRIX_SCALA publishLocal;
sbt ++$MATRIX_SCALA -DplayTestVersion=2.9.0 test;
cd ../test-app;
sbt ++$MATRIX_SCALA -DplayTestVersion=2.9.0 test;
cd ../test-app-filters;
sbt ++$MATRIX_SCALA -DplayTestVersion=2.9.0 test;
cd ../code;
finish:
name: Finish
if: github.event_name == 'pull_request'
needs: # Should be last
- "tests"
uses: playframework/.github/.github/workflows/rtm.yml@v3
46 changes: 46 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Publish

on:
push:
branches: # Snapshots
- main
tags: ["**"] # Releases
release:
types: [published]

jobs:
publish-artifacts:
name: JDK 11
runs-on: ubuntu-20.04
if: ${{ github.repository_owner == 'sbt' }}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
# we don't know what commit the last tag was it's safer to get entire repo so previousStableVersion resolves
fetch-depth: 0

- name: Coursier Cache
id: coursier-cache
uses: coursier/cache-action@v6

- name: Install Adoptium Temurin OpenJDK
uses: coursier/setup-action@v1
with:
jvm: adoptium:11

- name: Publish artifacts
run: cd code && sbt ci-release
env:
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }}
PGP_SECRET: ${{ secrets.PGP_SECRET }}

- name: Cleanup before cache
shell: bash
run: |
find $HOME/Library/Caches/Coursier/v1 -name "ivydata-*.properties" -delete || true
find $HOME/.ivy2/cache -name "ivydata-*.properties" -delete || true
find $HOME/.cache/coursier/v1 -name "ivydata-*.properties" -delete || true
find $HOME/.sbt -name "*.lock" -delete || true
27 changes: 0 additions & 27 deletions .travis.yml

This file was deleted.

38 changes: 31 additions & 7 deletions code/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,33 @@ name := "deadbolt-java"

lazy val root = (project in file(".")).enablePlugins(PlayWeb).disablePlugins(PlayFilters, PlayLogback, PlayAkkaHttpServer)

// Customise sbt-dynver's behaviour to make it work with tags which aren't v-prefixed
ThisBuild / dynverVTagPrefix := false

// Sanity-check: assert that version comes from a tag (e.g. not a too-shallow clone)
// https://github.com/dwijnand/sbt-dynver/#sanity-checking-the-version
Global / onLoad := (Global / onLoad).value.andThen { s =>
dynverAssertTagVersion.value
s
}

homepage := Some(url("https://github.com/mkurz/deadbolt-2-java")) // Some(url("http://deadbolt.ws"))
licenses += ("Apache-2.0", url("https://www.apache.org/licenses/LICENSE-2.0.html"))
organization := "be.objectify"

crossScalaVersions := Seq("2.13.12", "3.3.1")

scalaVersion := crossScalaVersions.value.head

organization := "be.objectify"

libraryDependencies := libraryDependencies.value.filterNot(m => m.name == "twirl-api" || m.name == "play-server") ++ Seq(
"org.mockito" % "mockito-all" % "1.10.19" % "test",
"org.mockito" % "mockito-core" % "2.28.2" % "test",
"org.awaitility" % "awaitility" % "3.0.0" % "test",
playCore % "provided",
javaCore % "test",
)

releasePublishArtifactsAction := PgpKeys.publishSigned.value

javacOptions += "-Xlint:deprecation"
scalacOptions += "-deprecation"
javacOptions ++= Seq("-Xlint:deprecation", "-encoding", "UTF-8", "--release", "11")
scalacOptions ++= Seq("-deprecation", "-release:11")

TwirlKeys.templateImports ++= Seq(
"java.util.Optional"
Expand All @@ -27,3 +37,17 @@ Test / TwirlKeys.templateImports ++= Seq(
"java.util.List",
"play.core.j.PlayMagicForJava._",
)

developers ++= List(Developer(
"mkurz",
"Matthias Kurz",
"m.kurz@irregular.at",
url("https://github.com/mkurz")
),
Developer(
"schaloner",
"Steve Chaloner",
"john.doe@example.com",
url("https://github.com/schaloner")
),
)
4 changes: 2 additions & 2 deletions code/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.9.0")
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.2-1")
addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.13")

addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.12")
32 changes: 0 additions & 32 deletions code/publish.sbt

This file was deleted.

4 changes: 0 additions & 4 deletions code/sonatype.sbt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ public void testAnd() throws Exception
Mockito.any(DeadboltHandler.class),
Mockito.any(Optional.class),
Mockito.any(BiFunction.class)))
.thenReturn(CompletableFuture.completedFuture(F.Tuple(false, Mockito.mock(Http.Request.class))));
.thenReturn(CompletableFuture.completedFuture(F.Tuple(false, new Http.RequestBuilder().build())));
final Constraint negated = Mockito.mock(Constraint.class);
Mockito.when(negated.test(Mockito.any(Http.Request.class),
Mockito.any(DeadboltHandler.class),
Mockito.any(Optional.class),
Mockito.any(BiFunction.class)))
.thenReturn(CompletableFuture.completedFuture(F.Tuple(true, Mockito.mock(Http.Request.class))));
.thenReturn(CompletableFuture.completedFuture(F.Tuple(true, new Http.RequestBuilder().build())));
Mockito.when(c2.negate())
.thenReturn(negated);
final F.Tuple<Constraint, Function<Constraint, CompletionStage<F.Tuple<Boolean, Http.RequestHeader>>>> satisfy = satisfy();
Expand All @@ -65,7 +65,7 @@ public void testOr() throws Exception
Mockito.any(DeadboltHandler.class),
Mockito.any(Optional.class),
Mockito.any(BiFunction.class)))
.thenReturn(CompletableFuture.completedFuture(F.Tuple(false, Mockito.mock(Http.Request.class))));
.thenReturn(CompletableFuture.completedFuture(F.Tuple(false, new Http.RequestBuilder().build())));
final F.Tuple<Constraint, Function<Constraint, CompletionStage<F.Tuple<Boolean, Http.RequestHeader>>>> satisfy = satisfy();
Assert.assertTrue(toBoolean(satisfy._2.apply(satisfy._1)));
Assert.assertTrue(toBoolean(satisfy._2.apply(satisfy._1.or(c2))));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ default ConstraintLogic logic(final DeadboltHandler deadboltHandler)
final SubjectCache subjectCache = Mockito.mock(SubjectCache.class);
Mockito.when(subjectCache.apply(Mockito.any(DeadboltHandler.class),
Mockito.any(Http.RequestHeader.class)))
.thenReturn(deadboltHandler.getSubject(Mockito.mock(Http.RequestHeader.class)).thenApply(maybeSubject ->F.Tuple(maybeSubject, Mockito.mock(Http.RequestHeader.class))));
.thenReturn(deadboltHandler.getSubject(new Http.RequestBuilder().build()).thenApply(maybeSubject ->F.Tuple(maybeSubject, new Http.RequestBuilder().build())));
return new ConstraintLogic(new DeadboltAnalyzer(),
subjectCache,
new DefaultPatternCache());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public void testMeta_or() throws Exception
@Override
protected F.Tuple<Constraint, Function<Constraint, CompletionStage<F.Tuple<Boolean, Http.RequestHeader>>>> satisfy()
{
final Constraint constraint = (c, h, gmd, fnM) -> CompletableFuture.completedFuture(F.Tuple(true, Mockito.mock(Http.RequestHeader.class)));
final Constraint constraint = (c, h, gmd, fnM) -> CompletableFuture.completedFuture(F.Tuple(true, new Http.RequestBuilder().build()));
final Constraint tree = new ConstraintTree(Operator.AND,
constraint,
constraint);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import be.objectify.deadbolt.java.AbstractDynamicResourceHandler;
import be.objectify.deadbolt.java.ConstraintLogic;
import be.objectify.deadbolt.java.Constants;
import be.objectify.deadbolt.java.DeadboltAnalyzer;
import be.objectify.deadbolt.java.DeadboltHandler;
import be.objectify.deadbolt.java.cache.BeforeAuthCheckCache;
Expand Down Expand Up @@ -104,6 +105,13 @@ public void setUp()
Mockito.when(requestHeader.uri()).thenReturn("http://localhost/foo");
Mockito.when(requestHeader.clientCertificateChain()).thenReturn(Optional.empty());
Mockito.when(requestHeader.cookies()).thenReturn(new TestCookies());

// The following is not really correct, because we do not make the requestHeader return the PATTERN_INVERT attr,
// however for these tests it does not really matter
Mockito.when(requestHeader.addAttr(Constants.PATTERN_INVERT, true))
.thenReturn(requestHeader);
Mockito.when(requestHeader.addAttr(Constants.PATTERN_INVERT, false))
.thenReturn(requestHeader);
}

@After
Expand Down Expand Up @@ -1652,4 +1660,4 @@ public void testRoleBasedPermissions_withContent_fail() throws Exception
Mockito.times(1)).onAuthFailure(Mockito.any(Http.RequestHeader.class),
Mockito.eq(Optional.of("json")));
}
}
}
50 changes: 50 additions & 0 deletions code/test/resources/logback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8" ?>

<!-- https://www.playframework.com/documentation/latest/SettingsLogger -->

<!DOCTYPE configuration>

<configuration>
<import class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"/>
<import class="ch.qos.logback.classic.AsyncAppender"/>
<import class="ch.qos.logback.core.FileAppender"/>
<import class="ch.qos.logback.core.ConsoleAppender"/>

<appender name="FILE" class="FileAppender">
<file>${application.home:-.}/logs/application.log</file>
<encoder class="PatternLayoutEncoder">
<charset>UTF-8</charset>
<pattern>%d{yyyy-MM-dd HH:mm:ss} %highlight(%-5level) %cyan(%logger{36}) %magenta(%X{pekkoSource}) %msg%n</pattern>
</encoder>
</appender>

<appender name="STDOUT" class="ConsoleAppender">
<!--
On Windows, enabling Jansi is recommended to benefit from color code interpretation on DOS command prompts,
which otherwise risk being sent ANSI escape sequences that they cannot interpret.
See https://logback.qos.ch/manual/layouts.html#coloring
-->
<!-- <withJansi>true</withJansi> -->
<encoder class="PatternLayoutEncoder">
<charset>UTF-8</charset>
<pattern>%d{yyyy-MM-dd HH:mm:ss} %highlight(%-5level) %cyan(%logger{36}) %magenta(%X{pekkoSource}) %msg%n</pattern>
</encoder>
</appender>

<appender name="ASYNCFILE" class="AsyncAppender">
<appender-ref ref="FILE"/>
</appender>

<appender name="ASYNCSTDOUT" class="AsyncAppender">
<appender-ref ref="STDOUT"/>
</appender>

<logger name="play" level="INFO"/>
<logger name="application" level="DEBUG"/>

<root level="WARN">
<appender-ref ref="ASYNCFILE"/>
<appender-ref ref="ASYNCSTDOUT"/>
</root>

</configuration>
1 change: 0 additions & 1 deletion code/version.sbt

This file was deleted.

9 changes: 4 additions & 5 deletions test-app-filters/build.sbt
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
name := """test-app-filters"""

version := "2.9.0-SNAPSHOT"

crossScalaVersions := Seq("2.13.12", "3.3.1")

scalaVersion := crossScalaVersions.value.head

// sync this setting with the one main build.sbt
ThisBuild / dynverVTagPrefix := false

testOptions += Tests.Argument(TestFrameworks.JUnit, "-v", "-a")

javacOptions += "-Xlint:deprecation"
Expand All @@ -14,10 +15,8 @@ scalacOptions += "-deprecation"

libraryDependencies ++= Seq(
guice,
"be.objectify" %% "deadbolt-java" % "2.9.0-SNAPSHOT",
"be.objectify" %% "deadbolt-java" % version.value,
"io.rest-assured" % "rest-assured" % "5.3.2" % Test
)

lazy val root = (project in file(".")).enablePlugins(PlayJava)

resolvers ++= Resolver.sonatypeOssRepos("snapshots")
Loading

0 comments on commit d7d67f9

Please sign in to comment.