From 42076e3fd2991d4e01b3d509525d9bee358e9406 Mon Sep 17 00:00:00 2001 From: Roberto Tyley Date: Fri, 17 Nov 2023 17:33:29 +0000 Subject: [PATCH] Add compile of example webapp to GitHub CI --- .github/workflows/ci.yml | 23 ++++++++++++++----- .gitignore | 3 +++ build.sbt | 2 ++ .../webapp/app/AppComponents.scala | 4 ++-- .../webapp/app/AppLoader.scala | 0 .../webapp/app/controllers/Application.scala | 1 - .../webapp/app/controllers/Login.scala | 6 ++--- .../webapp/app/views/authenticated.scala.html | 4 ++-- example/webapp/app/views/index.scala.html | 12 ++++++++++ .../webapp/app/views/login.scala.html | 6 ++--- .../example => example}/webapp/build.sbt | 4 ++-- .../webapp/conf/application.conf | 0 .../example => example}/webapp/conf/routes | 0 example/webapp/project/build.properties | 1 + example/webapp/project/plugins.sbt | 2 ++ .../sbt-test/example => example}/webapp/test | 0 example/webapp/version.sbt | 1 + .../example/webapp/app/views/index.scala.html | 12 ---------- .../example/webapp/project/build.properties | 1 - .../example/webapp/project/plugins.sbt | 5 ---- .../src/sbt-test/example/webapp/version.sbt | 1 - 21 files changed, 50 insertions(+), 38 deletions(-) rename {play-v27/src/sbt-test/example => example}/webapp/app/AppComponents.scala (92%) rename {play-v27/src/sbt-test/example => example}/webapp/app/AppLoader.scala (100%) rename {play-v27/src/sbt-test/example => example}/webapp/app/controllers/Application.scala (94%) rename {play-v27/src/sbt-test/example => example}/webapp/app/controllers/Login.scala (91%) rename {play-v27/src/sbt-test/example => example}/webapp/app/views/authenticated.scala.html (85%) create mode 100644 example/webapp/app/views/index.scala.html rename {play-v27/src/sbt-test/example => example}/webapp/app/views/login.scala.html (72%) rename {play-v27/src/sbt-test/example => example}/webapp/build.sbt (61%) rename {play-v27/src/sbt-test/example => example}/webapp/conf/application.conf (100%) rename {play-v27/src/sbt-test/example => example}/webapp/conf/routes (100%) create mode 100644 example/webapp/project/build.properties create mode 100644 example/webapp/project/plugins.sbt rename {play-v27/src/sbt-test/example => example}/webapp/test (100%) create mode 100644 example/webapp/version.sbt delete mode 100644 play-v27/src/sbt-test/example/webapp/app/views/index.scala.html delete mode 100644 play-v27/src/sbt-test/example/webapp/project/build.properties delete mode 100644 play-v27/src/sbt-test/example/webapp/project/plugins.sbt delete mode 120000 play-v27/src/sbt-test/example/webapp/version.sbt diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4c7d5d5..641f259 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,13 +10,24 @@ on: - main jobs: - sbt-build: + test: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: coursier/cache-action@v6 - - uses: olafurpg/setup-scala@v11 + - name: Checkout + uses: actions/checkout@v3 + - name: Setup JDK + uses: actions/setup-java@v3 with: - java-version: adopt@1.11 + distribution: corretto + java-version: 11 + cache: sbt - name: Build and Test - run: sbt ++test + run: sbt -v +test +publishLocal + - name: Check that example app compiles + working-directory: ./example/webapp + run: sbt -v +test + - name: Test Summary + uses: test-summary/action@v2 + with: + paths: "test-results/**/TEST-*.xml" + if: always() diff --git a/.gitignore b/.gitignore index 67059da..00bda0e 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,6 @@ target/ .idea/ *.log .bsp/ + +/test-results/ +.DS_Store diff --git a/build.sbt b/build.sbt index 4087a69..7a7b6fc 100644 --- a/build.sbt +++ b/build.sbt @@ -35,6 +35,8 @@ def projectWithPlayVersion(playVersion: PlayVersion) = crossScalaVersions := Seq(scalaVersion.value) ++ (if (playVersion.supportsScala3) Seq("3.3.1") else Seq.empty), scalacOptions ++= Seq("-feature", "-deprecation"), Compile / unmanagedSourceDirectories += baseDirectory.value / playVersion.pekkoOrAkkaSrcFolder, + Test / testOptions += + Tests.Argument(TestFrameworks.ScalaTest, "-u", s"test-results/scala-${scalaVersion.value}", "-o"), libraryDependencies ++= Seq( "com.gu.play-secret-rotation" %% "core" % "0.40", diff --git a/play-v27/src/sbt-test/example/webapp/app/AppComponents.scala b/example/webapp/app/AppComponents.scala similarity index 92% rename from play-v27/src/sbt-test/example/webapp/app/AppComponents.scala rename to example/webapp/app/AppComponents.scala index bb695cf..08da7dd 100644 --- a/play-v27/src/sbt-test/example/webapp/app/AppComponents.scala +++ b/example/webapp/app/AppComponents.scala @@ -21,7 +21,7 @@ class AppComponents(context: ApplicationLoader.Context) clientId = configuration.get[String]("your.clientId.config.path"), clientSecret = configuration.get[String]("your.clientSecret.config.path"), redirectUrl = configuration.get[String]("your.redirectUrl.config.path"), - domain = configuration.get[String]("your.apps-domain.config.path"), + domains = List(configuration.get[String]("your.apps-domain.config.path")), antiForgeryChecker = AntiForgeryChecker.borrowSettingsFromPlay(httpConfiguration) ) @@ -31,7 +31,7 @@ class AppComponents(context: ApplicationLoader.Context) val googleServiceAccount = GoogleServiceAccount(googleCredential.getServiceAccountId, googleCredential.getServiceAccountPrivateKey, "service.account@mydomain.com") val googleGroupChecker = new GoogleGroupChecker(googleServiceAccount) - val authAction = new AuthAction[AnyContent](googleAuthConfig, routes.Login.loginAction(), controllerComponents.parsers.default)(executionContext) + val authAction = new AuthAction[AnyContent](googleAuthConfig, routes.Login.loginAction, controllerComponents.parsers.default)(executionContext) val login = new Login(requiredGoogleGroups, googleAuthConfig, googleGroupChecker, wsClient, controllerComponents)(executionContext) val appController = new Application(authAction, requiredGoogleGroups, googleAuthConfig, googleGroupChecker, controllerComponents)(executionContext) diff --git a/play-v27/src/sbt-test/example/webapp/app/AppLoader.scala b/example/webapp/app/AppLoader.scala similarity index 100% rename from play-v27/src/sbt-test/example/webapp/app/AppLoader.scala rename to example/webapp/app/AppLoader.scala diff --git a/play-v27/src/sbt-test/example/webapp/app/controllers/Application.scala b/example/webapp/app/controllers/Application.scala similarity index 94% rename from play-v27/src/sbt-test/example/webapp/app/controllers/Application.scala rename to example/webapp/app/controllers/Application.scala index 318d048..54c47c4 100644 --- a/play-v27/src/sbt-test/example/webapp/app/controllers/Application.scala +++ b/example/webapp/app/controllers/Application.scala @@ -4,7 +4,6 @@ import com.gu.googleauth import com.gu.googleauth.{AuthAction, Filters, GoogleAuthConfig, GoogleGroupChecker} import play.api.mvc.Security.AuthenticatedRequest import play.api.mvc._ -import com.google.api.client.auth.oauth2.GoogleCredential import scala.concurrent.ExecutionContext diff --git a/play-v27/src/sbt-test/example/webapp/app/controllers/Login.scala b/example/webapp/app/controllers/Login.scala similarity index 91% rename from play-v27/src/sbt-test/example/webapp/app/controllers/Login.scala rename to example/webapp/app/controllers/Login.scala index 69d55b8..979452d 100644 --- a/play-v27/src/sbt-test/example/webapp/app/controllers/Login.scala +++ b/example/webapp/app/controllers/Login.scala @@ -38,9 +38,9 @@ class Login(requiredGoogleGroups: Set[String], val authConfig: GoogleAuthConfig, } def logout = Action { implicit request => - Redirect(routes.Application.index()).withNewSession + Redirect(routes.Application.index).withNewSession } - override val failureRedirectTarget: Call = routes.Login.login() - override val defaultRedirectTarget: Call = routes.Application.authenticated() + override val failureRedirectTarget: Call = routes.Login.login + override val defaultRedirectTarget: Call = routes.Application.authenticated } diff --git a/play-v27/src/sbt-test/example/webapp/app/views/authenticated.scala.html b/example/webapp/app/views/authenticated.scala.html similarity index 85% rename from play-v27/src/sbt-test/example/webapp/app/views/authenticated.scala.html rename to example/webapp/app/views/authenticated.scala.html index 52ea0ed..89884de 100644 --- a/play-v27/src/sbt-test/example/webapp/app/views/authenticated.scala.html +++ b/example/webapp/app/views/authenticated.scala.html @@ -18,7 +18,7 @@

Authorised

@request.user.firstName

}

The expiry time is @{Instant.ofEpochSecond(request.user.exp)}

-

You can go to the login page - or logout.

+

You can go to the login page + or logout.

\ No newline at end of file diff --git a/example/webapp/app/views/index.scala.html b/example/webapp/app/views/index.scala.html new file mode 100644 index 0000000..e944fce --- /dev/null +++ b/example/webapp/app/views/index.scala.html @@ -0,0 +1,12 @@ +@(request: Request[AnyContent], error: Option[String] = None) + + + Home + +

Home page

+

This is the home page of the example application.

+

You can go to the login page, + a page that requires authentication, + or logout.

+ + \ No newline at end of file diff --git a/play-v27/src/sbt-test/example/webapp/app/views/login.scala.html b/example/webapp/app/views/login.scala.html similarity index 72% rename from play-v27/src/sbt-test/example/webapp/app/views/login.scala.html rename to example/webapp/app/views/login.scala.html index 29da1fd..40803f6 100644 --- a/play-v27/src/sbt-test/example/webapp/app/views/login.scala.html +++ b/example/webapp/app/views/login.scala.html @@ -9,10 +9,10 @@

Login Page

@error.map { message =>

The error was: @message

} -
+
-

You can also go to a page that requires authentication - or logout.

+

You can also go to a page that requires authentication + or logout.

\ No newline at end of file diff --git a/play-v27/src/sbt-test/example/webapp/build.sbt b/example/webapp/build.sbt similarity index 61% rename from play-v27/src/sbt-test/example/webapp/build.sbt rename to example/webapp/build.sbt index dbe8a44..8df7435 100644 --- a/play-v27/src/sbt-test/example/webapp/build.sbt +++ b/example/webapp/build.sbt @@ -1,9 +1,9 @@ name := "play-googleauth-example" -scalaVersion := "2.12.16" +scalaVersion := "2.13.12" libraryDependencies ++= Seq( - "com.gu" %% "play-googleauth" % version.value, + "com.gu.play-googleauth" %% "play-v30" % version.value, ws ) diff --git a/play-v27/src/sbt-test/example/webapp/conf/application.conf b/example/webapp/conf/application.conf similarity index 100% rename from play-v27/src/sbt-test/example/webapp/conf/application.conf rename to example/webapp/conf/application.conf diff --git a/play-v27/src/sbt-test/example/webapp/conf/routes b/example/webapp/conf/routes similarity index 100% rename from play-v27/src/sbt-test/example/webapp/conf/routes rename to example/webapp/conf/routes diff --git a/example/webapp/project/build.properties b/example/webapp/project/build.properties new file mode 100644 index 0000000..e8a1e24 --- /dev/null +++ b/example/webapp/project/build.properties @@ -0,0 +1 @@ +sbt.version=1.9.7 diff --git a/example/webapp/project/plugins.sbt b/example/webapp/project/plugins.sbt new file mode 100644 index 0000000..b2a6bbf --- /dev/null +++ b/example/webapp/project/plugins.sbt @@ -0,0 +1,2 @@ +// Use the Play sbt plugin for Play projects +addSbtPlugin("org.playframework" % "sbt-plugin" % "3.0.0") diff --git a/play-v27/src/sbt-test/example/webapp/test b/example/webapp/test similarity index 100% rename from play-v27/src/sbt-test/example/webapp/test rename to example/webapp/test diff --git a/example/webapp/version.sbt b/example/webapp/version.sbt new file mode 100644 index 0000000..28229e7 --- /dev/null +++ b/example/webapp/version.sbt @@ -0,0 +1 @@ +ThisBuild / version := "2.3.1-SNAPSHOT" diff --git a/play-v27/src/sbt-test/example/webapp/app/views/index.scala.html b/play-v27/src/sbt-test/example/webapp/app/views/index.scala.html deleted file mode 100644 index 32769ea..0000000 --- a/play-v27/src/sbt-test/example/webapp/app/views/index.scala.html +++ /dev/null @@ -1,12 +0,0 @@ -@(request: Request[AnyContent], error: Option[String] = None) - - - Home - -

Home page

-

This is the home page of the example application.

-

You can go to the login page, - a page that requires authentication, - or logout.

- - \ No newline at end of file diff --git a/play-v27/src/sbt-test/example/webapp/project/build.properties b/play-v27/src/sbt-test/example/webapp/project/build.properties deleted file mode 100644 index d6e3507..0000000 --- a/play-v27/src/sbt-test/example/webapp/project/build.properties +++ /dev/null @@ -1 +0,0 @@ -sbt.version=1.1.6 diff --git a/play-v27/src/sbt-test/example/webapp/project/plugins.sbt b/play-v27/src/sbt-test/example/webapp/project/plugins.sbt deleted file mode 100644 index dd3c274..0000000 --- a/play-v27/src/sbt-test/example/webapp/project/plugins.sbt +++ /dev/null @@ -1,5 +0,0 @@ -// The Typesafe repository -resolvers += Resolver.typesafeIvyRepo("releases") - -// Use the Play sbt plugin for Play projects -addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.6.17") diff --git a/play-v27/src/sbt-test/example/webapp/version.sbt b/play-v27/src/sbt-test/example/webapp/version.sbt deleted file mode 120000 index 6269cc7..0000000 --- a/play-v27/src/sbt-test/example/webapp/version.sbt +++ /dev/null @@ -1 +0,0 @@ -../../../../version.sbt \ No newline at end of file