Skip to content

Commit

Permalink
Upgraded sbt to 1.6, scala.js to 1.8 and webpack to 5 (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
viktor-podzigun committed Nov 14, 2022
1 parent 430411a commit afc80ef
Show file tree
Hide file tree
Showing 22 changed files with 145 additions and 72 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 @@ -62,7 +64,7 @@ jobs:
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}

- name: Publish SNAPSHOT
run: sbt ";^^1.5.2 ;clean ;publish"
run: sbt ";^^1.6.2 ;clean ;publish"
if: ${{ !github.event.pull_request && env.TAG_NAME == '' }}
env:
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
Expand All @@ -75,7 +77,7 @@ jobs:
echo $PGP_SECRET | base64 --decode > ./keys/secring.gpg
VERSION="$(echo "$TAG_NAME" | cut -d'v' -f 2)"
echo "Publish a release version=$VERSION for tag $TAG_NAME"
version=$VERSION sbt ";^^1.5.2 ;clean ;publishSigned ;sonatypeBundleRelease"
version=$VERSION sbt ";^^1.6.2 ;clean ;publishSigned ;sonatypeBundleRelease"
if: ${{ env.TAG_NAME != '' }}
env:
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
[![CI](https://github.com/scommons/sbt-scommons-plugin/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/scommons/sbt-scommons-plugin/actions/workflows/ci.yml?query=workflow%3Aci+branch%3Amaster)
[![Coverage Status](https://coveralls.io/repos/github/scommons/sbt-scommons-plugin/badge.svg?branch=master)](https://coveralls.io/github/scommons/sbt-scommons-plugin?branch=master)
[![scala-index](https://index.scala-lang.org/scommons/sbt-scommons-plugin/sbt-scommons-plugin/latest-by-scala-version.svg?targetType=Sbt)](https://index.scala-lang.org/scommons/sbt-scommons-plugin/sbt-scommons-plugin)
[![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)

## sbt-scommons-plugin
Sbt auto-plugins with common tasks/utils for Scala Commons modules
Expand Down
12 changes: 8 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import definitions.GitHubActionsCI
import org.scoverage.coveralls.Imports.CoverallsKeys._

val ideExcludedDirectories = SettingKey[Seq[File]]("ide-excluded-directories")
.withRank(KeyRanks.Invisible)
Expand Down Expand Up @@ -41,16 +43,18 @@ lazy val `sbt-scommons-plugin` = (project in file("."))
coverageMinimum := 80,
coverageHighlighting := false,
coverageExcludedPackages := ".*mecha.*;.*project.*",
coverallsFailBuildOnError := true,
coverallsService := GitHubActionsCI.jobId.map(_ => GitHubActionsCI),

addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.1.0"),
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.5.1"),
addSbtPlugin("ch.epfl.scala" % "sbt-scalajs-bundler" % "0.20.0"),
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.10.1"),
addSbtPlugin("ch.epfl.scala" % "sbt-scalajs-bundler" % "0.21.0"),

//addSbtPlugin("com.storm-enroute" % "mecha" % "0.3"), //TODO: use version for sbt 1.x

libraryDependencies ++= Seq(
"org.scalatest" %% "scalatest" % "3.2.9" % "test",
"org.scalamock" %% "scalamock" % "5.1.0" % "test"
"org.scalatest" %% "scalatest" % "3.2.14" % "test",
"org.scalamock" %% "scalamock" % "5.2.0" % "test"
),

//resolvers += "Sonatype Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots/",
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
4 changes: 2 additions & 2 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
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")
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")
}
}
24 changes: 19 additions & 5 deletions src/main/scala/scommons/sbtplugin/ScommonsPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import org.scalajs.sbtplugin.ScalaJSPlugin.autoImport._
import sbt.Keys._
import sbt._
import scommons.sbtplugin.util.{BundlesUtils, ResourcesUtils}

import scalajsbundler.Webpack
import scalajsbundler.{NpmPackage, Webpack}
import scalajsbundler.sbtplugin.ScalaJSBundlerPlugin
import scalajsbundler.sbtplugin.ScalaJSBundlerPlugin.autoImport._

Expand Down Expand Up @@ -99,18 +98,33 @@ object ScommonsPlugin extends AutoPlugin {
val nodeArgs = (Test / webpackNodeArgs).value
val bundleName = bundleOutput.data.name.stripSuffix(".js")
val webpackOutput = targetDir / s"$bundleName-webpack-out.js"
val webpackVersion = (webpack / version).value

logger.info("Executing webpack...")
val loader = bundleOutput.data

customWebpackConfigFile match {
val configArgs = customWebpackConfigFile match {
case Some(configFile) =>
val customConfigFileCopy = Webpack.copyCustomWebpackConfigFiles(targetDir, webpackResources.value.get)(configFile)
Webpack.run(nodeArgs: _*)("--mode", "development", "--config", customConfigFileCopy.getAbsolutePath, loader.absolutePath, "--output", webpackOutput.absolutePath)(targetDir, logger)
Seq("--config", customConfigFileCopy.getAbsolutePath)
case None =>
Webpack.run(nodeArgs: _*)("--mode", "development", loader.absolutePath, "--output", webpackOutput.absolutePath)(targetDir, logger)
Seq.empty
}

val allArgs = Seq(
"--entry", loader.absolutePath,
"--output-path", targetDir.absolutePath,
"--output-filename", webpackOutput.name
) ++ configArgs

NpmPackage(webpackVersion).major match {
case Some(5) =>
Webpack.run(nodeArgs: _*)(allArgs: _*)(targetDir, logger)
case Some(x) =>
sys.error(s"Unsupported webpack major version $x")
case None =>
sys.error("No webpack version defined")
}
Attributed(webpackOutput)(bundleOutput.metadata)
}
else bundleOutput
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package scommons.sbtplugin.project

import org.portablescala.sbtplatformdeps.PlatformDepsPlugin.autoImport._
import org.scalajs.linker.interface.ESVersion
import org.scalajs.jsenv.nodejs.NodeJSEnv
import org.scalajs.sbtplugin.ScalaJSPlugin
import org.scalajs.sbtplugin.ScalaJSPlugin.autoImport._
Expand Down Expand Up @@ -62,13 +63,18 @@ trait CommonClientModule extends CommonModule {
object CommonClientModule {

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"
),
scalaJSLinkerConfig ~= {
_.withModuleKind(ModuleKind.CommonJSModule)
.withSourceMap(false)
.withESFeatures(_.withUseECMAScript2015(false))
.withESFeatures(_.withESVersion(ESVersion.ES5_1))
},
Test / requireJsDomEnv := false,
webpack / version := "4.29.0",
webpack / version := "5.74.0",
webpackEmitSourceMaps := false,
Test / parallelExecution := false,

Expand Down
3 changes: 3 additions & 0 deletions src/main/scala/scommons/sbtplugin/project/CommonLibs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ trait CommonLibs {
val playJsonVer = "2.9.0"
val playWsVer = "2.0.8"
val jodaTimeVer = "2.10.5"
val scalaJsJavaSecureRandomVer = "1.0.0"

//////////////////////////////////////////////////////////////////////////////
// jvm dependencies
Expand All @@ -37,6 +38,8 @@ trait CommonLibs {
lazy val scalajsDom = Def.setting("org.scala-js" %%% "scalajs-dom" % "2.2.0")

lazy val playJsonJs = Def.setting("com.typesafe.play" %%% "play-json" % playJsonVer)

lazy val scalaJsJavaSecureRandom = Def.setting("org.scala-js" %%% "scalajs-java-securerandom" % scalaJsJavaSecureRandomVer)
}

object CommonLibs extends CommonLibs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package scommons.sbtplugin.project

import org.portablescala.sbtplatformdeps.PlatformDepsPlugin.autoImport._
import org.scalajs.linker.interface.ESVersion
import org.scalajs.jsenv.nodejs.NodeJSEnv
import org.scalajs.sbtplugin.ScalaJSPlugin
import org.scalajs.sbtplugin.ScalaJSPlugin.autoImport._
Expand Down Expand Up @@ -52,17 +53,22 @@ object CommonMobileModule {
"org.scommons.react-native" % "scommons-react-native-test" % "*"
),

scalacOptions ++= Seq(
//see:
// http://www.scala-js.org/news/2021/12/10/announcing-scalajs-1.8.0/
"-P:scalajs:nowarnGlobalExecutionContext"
),
scalaJSLinkerConfig ~= {
_.withModuleKind(ModuleKind.CommonJSModule)
.withSourceMap(false)
.withESFeatures(_.withUseECMAScript2015(false))
.withESFeatures(_.withESVersion(ESVersion.ES5_1))
},
scalaJSUseMainModuleInitializer := false,
webpackBundlingMode := BundlingMode.LibraryOnly(),

// react-native DO NOT require DOM
Test / requireJsDomEnv := false,
webpack / version := "4.29.0",
webpack / version := "5.74.0",
webpackEmitSourceMaps := false,
Test / parallelExecution := false,

Expand Down
11 changes: 10 additions & 1 deletion src/main/scala/scommons/sbtplugin/project/CommonModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@ object CommonModule {

val coverageMinimum = SettingKey[Double]("coverage-minimum")
val coverageExcludedPackages = SettingKey[String]("coverage-excluded-packages")
val coverallsFailBuildOnError = SettingKey[Boolean](
"coverallsFailBuildOnError",
"fail build if coveralls step fails"
)

val settings: Seq[Setting[_]] = Seq(
scalaVersion := "2.13.5",
scalaVersion := "2.13.8",
scalacOptions ++= Seq(
//see https://docs.scala-lang.org/overviews/compiler-options/index.html#Warning_Settings
//"-Xcheckinit",
Expand All @@ -54,6 +58,11 @@ object CommonModule {
},

coverageMinimum := 80,
coverallsFailBuildOnError := true,

//improving performance by disabling this feature that was introduced in:
// https://github.com/scoverage/sbt-scoverage/releases/tag/v1.8.0
Compile / compile / scalacOptions -= "-P:scoverage:reportTestName",

resolvers += "Sonatype Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots/"
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package scommons.sbtplugin.project

import org.portablescala.sbtplatformdeps.PlatformDepsPlugin.autoImport._
import org.scalajs.linker.interface.ESVersion
import org.scalajs.jsenv.nodejs.NodeJSEnv
import org.scalajs.sbtplugin.ScalaJSPlugin
import org.scalajs.sbtplugin.ScalaJSPlugin.autoImport._
Expand Down Expand Up @@ -38,13 +39,18 @@ trait CommonNodeJsModule extends CommonModule {
object CommonNodeJsModule {

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"
),
scalaJSLinkerConfig ~= {
_.withModuleKind(ModuleKind.CommonJSModule)
.withSourceMap(false)
.withESFeatures(_.withUseECMAScript2015(false))
.withESFeatures(_.withESVersion(ESVersion.ES5_1))
},
Test / requireJsDomEnv := false,
webpack / version := "4.29.0",
webpack / version := "5.74.0",
webpackEmitSourceMaps := false,
Test / parallelExecution := false,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import sbt._

trait CommonTestLibs {

val scalaTestVersion = "3.2.9"
val scalaTestPlusMockitoVersion = "3.2.9.0"
val scalaTestVersion = "3.2.14"
val scalaTestPlusMockitoVersion = "3.2.10.0"
val scalaTestPlusPlayVersion = "5.1.0"
val scalaMockVersion = "5.1.0"
val scalaMockVersion = "5.2.0"
val dockerTestkitVersion = "0.9.9"

val akkaVersion: String = CommonLibs.akkaVersion
Expand Down
Loading

0 comments on commit afc80ef

Please sign in to comment.