Skip to content

Commit

Permalink
Upgraded sbt to 1.6, scala.js to 1.8 and webpack to 5 (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
viktor-podzigun authored Nov 17, 2022
1 parent ad6d00f commit 8751d1f
Show file tree
Hide file tree
Showing 14 changed files with 98 additions and 40 deletions.
38 changes: 20 additions & 18 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ name: CI

on:
push:
paths-ignore:
- '*.md'
branches: [ master ]
tags:
- '*'
Expand All @@ -13,34 +15,34 @@ jobs:
runs-on: ubuntu-latest
steps:

- name: Git checkout
uses: actions/checkout@v2
- name: Git checkout (merge)
uses: actions/checkout@v3
if: github.event_name != 'pull_request'
with:
fetch-depth: 0

- name: Git checkout (PR)
uses: actions/checkout@v3
if: github.event_name == 'pull_request'
with:
fetch-depth: 0
# see: https://frontside.com/blog/2020-05-26-github-actions-pull_request/#how-does-pull_request-affect-actionscheckout
ref: ${{ github.event.pull_request.head.sha }}

- name: Setup Node.js
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: '12'
node-version: '16'

- name: Set up JDK 8
uses: actions/setup-java@v2
uses: actions/setup-java@v3
with:
java-version: '8'
distribution: 'adopt'

- name: Cache sbt
uses: actions/cache@v2
with:
path: |
~/.sbt
~/.ivy2/cache
~/.coursier/cache/v1
~/.cache/coursier/v1
key: ${{ runner.os }}-sbt-cache-v2-${{ hashFiles('**/*.sbt', 'project/**/*.scala') }}
cache: 'sbt'

- name: Cache node_modules
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: |
~/.npm
Expand All @@ -49,9 +51,9 @@ jobs:
~/work/scommons-admin/scommons-admin/client/target/scala-2.13/scalajs-bundler/main/package-lock.json
~/work/scommons-admin/scommons-admin/client/target/scala-2.13/scalajs-bundler/test/node_modules
~/work/scommons-admin/scommons-admin/client/target/scala-2.13/scalajs-bundler/test/package-lock.json
key: ${{ runner.os }}-node_modules-cache-v2-${{ hashFiles('**/package-lock.json') }}
key: ${{ runner.os }}-node_modules-cache-v3-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node_modules-cache-v2-
${{ runner.os }}-node_modules-cache-v3-
- name: Extract Tag Name
run: echo "TAG_NAME=$(echo ${GITHUB_REF##*/})" >> $GITHUB_ENV
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*.class
*.log
package-lock.json

# sbt specific
.cache
Expand Down
2 changes: 2 additions & 0 deletions .sbtopts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-J-Xmx2G
-J-XX:+UseG1GC
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

[![CI](https://github.com/scommons/scommons-admin/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/scommons/scommons-admin/actions/workflows/ci.yml?query=workflow%3Aci+branch%3Amaster)
[![Coverage Status](https://coveralls.io/repos/github/scommons/scommons-admin/badge.svg?branch=master)](https://coveralls.io/github/scommons/scommons-admin?branch=master)
[![Scala.js](https://www.scala-js.org/assets/badges/scalajs-1.5.0.svg)](https://www.scala-js.org)
[![Scala.js](https://www.scala-js.org/assets/badges/scalajs-1.8.0.svg)](https://www.scala-js.org)
[![Docker image](https://img.shields.io/docker/v/scommons/admin?label=docker%20image&sort=date)](https://hub.docker.com/r/scommons/admin)

# scommons-admin
Expand Down Expand Up @@ -31,7 +31,7 @@ docker run -d --name scommons-admin -p 9000:9000 \

To build and run ALL tests use the following command:
```bash
sbt -mem 2048 clean "project scommons-admin-server" test it:test && sbt -mem 2048 ";project scommons-admin-server ;set Test / test := {} ;project scommons-admin" test
sbt clean "project scommons-admin-server" test it:test && sbt ";project scommons-admin-server ;set Test / test := {} ;project scommons-admin" test
```

#### How to Run Server locally in DEV mode
Expand All @@ -40,7 +40,7 @@ Before you can run server, please, make sure you have PostgreSQL DB up and runni

To start the application server locally in development mode with refresh workflow:
```bash
sbt -mem 2048 clean ';project scommons-admin-server ;set Assets / WebKeys.exportedMappings := Seq()' run
sbt clean ';project scommons-admin-server ;set Assets / WebKeys.exportedMappings := Seq()' run
```

## Admin Client UI
Expand Down
10 changes: 8 additions & 2 deletions client/client.webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
const merge = require("webpack-merge")
const { merge } = require("webpack-merge")

const generatedConfig = require('./scalajs.webpack.config')
const commonClientConfig = require("./scommons.webpack.config.js")

module.exports = merge(generatedConfig, commonClientConfig)
module.exports = merge(generatedConfig, commonClientConfig, {
performance: {
hints: false
},

mode: 'production'
})
2 changes: 1 addition & 1 deletion client/test.webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

const nodeExternals = require('webpack-node-externals')
const merge = require("webpack-merge")
const { merge } = require("webpack-merge")
const commonConfig = require("./scommons.webpack.config.js")

module.exports = merge(commonConfig, {
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version = 1.5.2
sbt.version = 1.6.2
10 changes: 5 additions & 5 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//resolvers += "Typesafe repository" at "https://repo.typesafe.com/typesafe/releases/"
resolvers += "Sonatype Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots/"

//addSbtPlugin(("org.scommons.sbt" % "sbt-scommons-plugin" % "0.9.0-SNAPSHOT").changing())
addSbtPlugin("org.scommons.sbt" % "sbt-scommons-plugin" % "0.9.0")
addSbtPlugin(("org.scommons.sbt" % "sbt-scommons-plugin" % "1.0.0-SNAPSHOT").changing())
//addSbtPlugin("org.scommons.sbt" % "sbt-scommons-plugin" % "0.9.0")

addSbtPlugin("ch.epfl.scala" % "sbt-web-scalajs-bundler" % "0.20.0")
addSbtPlugin("ch.epfl.scala" % "sbt-web-scalajs-bundler" % "0.21.0")

// play plugin version should be the same as in `common.Libs.playVer` !!!
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.8.8")
Expand All @@ -16,5 +16,5 @@ addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.3.3")
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.5")
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.0")

addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.7.3")
addSbtPlugin("org.scoverage" % "sbt-coveralls" % "1.2.7")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.9.3")
addSbtPlugin("org.scoverage" % "sbt-coveralls" % "1.3.2")
10 changes: 5 additions & 5 deletions project/src/main/scala/common/Libs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import scommons.sbtplugin.project.CommonLibs

object Libs extends CommonLibs {

val scommonsNodejsVersion = "0.9.0"
val scommonsApiVersion = "0.9.0"
val scommonsServiceVersion = "0.9.0"
val scommonsReactVersion = "0.9.0"
val scommonsClientVersion = "0.9.0"
val scommonsNodejsVersion = "1.0.0-SNAPSHOT"
val scommonsApiVersion = "1.0.0-SNAPSHOT"
val scommonsServiceVersion = "1.0.0-SNAPSHOT"
val scommonsReactVersion = "1.0.0-SNAPSHOT"
val scommonsClientVersion = "1.0.0-SNAPSHOT"

//////////////////////////////////////////////////////////////////////////////
// shared dependencies
Expand Down
8 changes: 7 additions & 1 deletion project/src/main/scala/definitions/AdminClient.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package definitions

import com.typesafe.sbt.web.SbtWeb
import common.Libs
import sbt._
import scommons.sbtplugin.project.CommonClientModule
import scoverage.ScoverageKeys._
Expand Down Expand Up @@ -29,7 +30,12 @@ object AdminClient extends AdminModule with CommonClientModule {
override def runtimeDependencies: Def.Initialize[Seq[ModuleID]] = Def.setting {
super.runtimeDependencies.value ++ Seq(
// specify your custom runtime dependencies here
)
) ++ {
if (coverageEnabled.value) Seq(
Libs.scalaJsJavaSecureRandom.value
)
else Nil
}
}

override def testDependencies: Def.Initialize[Seq[ModuleID]] = Def.setting {
Expand Down
10 changes: 7 additions & 3 deletions project/src/main/scala/definitions/AdminClientApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@ object AdminClientApi {
// Add JVM-specific settings here
).jsSettings(
// Add JS-specific settings here
Seq(
coverageEnabled := false
) ++ ScalaJsModule.settings: _*
ScalaJsModule.settings ++ Seq(
coverageEnabled := false,

libraryDependencies ++= Seq(
Libs.scalaJsJavaSecureRandom.value % "test"
)
): _*
)

lazy val jvm: Project = `scommons-admin-client-api`.jvm
Expand Down
5 changes: 4 additions & 1 deletion project/src/main/scala/definitions/AdminModule.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package definitions

import common.Libs
import org.scoverage.coveralls.Imports.CoverallsKeys._
import sbt.Keys._
import sbt._
import scommons.sbtplugin.project.CommonModule
Expand All @@ -24,6 +25,8 @@ trait AdminModule extends CommonModule {
object AdminModule {

val settings: Seq[Setting[_]] = Seq(
organization := "org.scommons.admin"
organization := "org.scommons.admin",

coverallsService := GitHubActionsCI.jobId.map(_ => GitHubActionsCI)
)
}
27 changes: 27 additions & 0 deletions project/src/main/scala/definitions/GitHubActionsCI.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package definitions

import org.scoverage.coveralls.CIService

import scala.io.Source
import scala.util.parsing.json.{JSON, JSONObject}

case object GitHubActionsCI extends CIService {
val name = ""
val jobId: Option[String] = sys.env.get("GITHUB_RUN_ID")

// https://github.com/coverallsapp/github-action/blob/master/src/run.ts#L31-L40
val pullRequest: Option[String] = for {
eventName <- sys.env.get("GITHUB_EVENT_NAME") if eventName.startsWith("pull_request")
payloadPath <- sys.env.get("GITHUB_EVENT_PATH")
source = Source.fromFile(payloadPath, "utf-8")
lines = try source.mkString finally source.close()
payload <- JSON.parseRaw(lines)
prNumber <- payload.asInstanceOf[JSONObject].obj.get("number")
} yield prNumber.toString.stripSuffix(".0")

// https://docs.github.com/en/actions/learn-github-actions/environment-variables
val currentBranch: Option[String] = pullRequest match {
case Some(_) => sys.env.get("GITHUB_HEAD_REF")
case None => sys.env.get("GITHUB_REF_NAME")
}
}
7 changes: 7 additions & 0 deletions project/src/main/scala/definitions/ScalaJsModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@ package definitions

import org.scalajs.jsenv.nodejs.NodeJSEnv
import org.scalajs.sbtplugin.ScalaJSPlugin.autoImport._
import sbt.Keys._
import sbt._

object ScalaJsModule {

val settings: Seq[Setting[_]] = Seq(
scalacOptions ++= Seq(
//see:
// http://www.scala-js.org/news/2021/12/10/announcing-scalajs-1.8.0/
"-P:scalajs:nowarnGlobalExecutionContext"
),

// required for node.js >= v12.12.0
// see:
// https://github.com/nodejs/node/pull/29919
Expand Down

0 comments on commit 8751d1f

Please sign in to comment.