Skip to content

Commit

Permalink
Merge pull request #100 from eed3si9n/wip/slash
Browse files Browse the repository at this point in the history
ci: Cross build to sbt 2.x
  • Loading branch information
eed3si9n authored Nov 8, 2024
2 parents 4018890 + 2e03e97 commit 45e6b33
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 74 deletions.
34 changes: 2 additions & 32 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,14 @@ jobs:
name: Build and Test
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
os: [ubuntu-latest, macos-latest]
scala: [2.12.20]
java: [temurin@8, temurin@17]
exclude:
- java: temurin@8
os: macos-latest
- java: temurin@17
os: windows-latest
runs-on: ${{ matrix.os }}
steps:
- name: Ignore line ending differences in git
if: contains(runner.os, 'windows')
shell: bash
run: git config --global core.autocrlf false

- name: Configure pagefile for Windows
if: contains(runner.os, 'windows')
uses: al-cheb/[email protected]
with:
minimum-size: 2GB
maximum-size: 8GB
disk-root: 'C:'

- name: Checkout current branch (full)
uses: actions/checkout@v4
with:
Expand All @@ -70,14 +55,11 @@ jobs:
uses: sbt/setup-sbt@v1

- name: Check that workflows are up to date
shell: bash
run: sbt '++ ${{ matrix.scala }}' githubWorkflowCheck

- shell: bash
run: sbt '++ ${{ matrix.scala }}' test scripted
- run: sbt '++ ${{ matrix.scala }}' +test +scripted

- name: Compress target directories
shell: bash
run: tar cf targets.tar target project/target

- name: Upload target directories
Expand All @@ -97,18 +79,6 @@ jobs:
java: [temurin@8]
runs-on: ${{ matrix.os }}
steps:
- name: Ignore line ending differences in git
if: contains(runner.os, 'windows')
run: git config --global core.autocrlf false

- name: Configure pagefile for Windows
if: contains(runner.os, 'windows')
uses: al-cheb/[email protected]
with:
minimum-size: 2GB
maximum-size: 8GB
disk-root: 'C:'

- name: Checkout current branch (full)
uses: actions/checkout@v4
with:
Expand Down
2 changes: 2 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ align.tokens."+" = [
]
}
]

project.layout = StandardConvention
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ flywayUrl := "jdbc:hsqldb:file:target/flyway_sample;shutdown=true"
flywayUser := "SA"
flywayPassword := ""
flywayLocations := Seq("filesystem:src/main/resources/db/migration")
flywayUrl in Test := "jdbc:hsqldb:file:target/flyway_sample;shutdown=true"
flywayUser in Test := "SA"
flywayLocations in Test := Seq("filesystem:src/main/resources/db/migration")
flywayPassword in Test := ""
Test/ flywayUrl := "jdbc:hsqldb:file:target/flyway_sample;shutdown=true"
Test/ flywayUser := "SA"
Test/ flywayLocations := Seq("filesystem:src/main/resources/db/migration")
Test/ flywayPassword := ""
```

Migrate your database using `sbt flywayMigrate` or clean it using `sbt flywayClean`.
Expand Down
32 changes: 19 additions & 13 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
lazy val repoSlug = "sbt/flyway-sbt"
lazy val flywayVersion = "9.22.0"
lazy val scala212 = "2.12.20"
lazy val scala3 = "3.3.4"

ThisBuild / organization := "com.github.sbt"
ThisBuild / version := {
val orig = (ThisBuild / version).value
if (orig.startsWith("0.0") && orig.endsWith("-SNAPSHOT")) {
if (orig.startsWith("9.") && orig.endsWith("-SNAPSHOT")) {
"9.0.0-SNAPSHOT"
} else orig
}
lazy val root = (project in file("."))
.enablePlugins(SbtPlugin)
.settings(
name := "flyway-sbt",
crossScalaVersions := Seq(scala212, scala3),
libraryDependencies ++= Seq(
"org.flywaydb" % "flyway-core" % flywayVersion
),
Expand All @@ -27,15 +30,19 @@ lazy val root = (project in file("."))
}
},
Compile / doc / scalacOptions ++= {
Seq(
"-sourcepath",
(LocalRootProject / baseDirectory).value.getAbsolutePath,
"-doc-source-url",
s"""https://github.com/sbt/flyway-sbt/tree/${sys.process
.Process("git rev-parse HEAD")
.lineStream_!
.head}€{FILE_PATH}.scala"""
)
scalaBinaryVersion.value match {
case "2.12" =>
Seq(
"-sourcepath",
(LocalRootProject / baseDirectory).value.getAbsolutePath,
"-doc-source-url",
s"""https://github.com/sbt/flyway-sbt/tree/${sys.process
.Process("git rev-parse HEAD")
.lineStream_!
.head}€{FILE_PATH}.scala"""
)
case _ => Nil
}
},
scriptedLaunchOpts := {
scriptedLaunchOpts.value ++
Expand Down Expand Up @@ -63,7 +70,7 @@ ThisBuild / scmInfo := Some(
)
ThisBuild / homepage := Some(url(s"https://github.com/$repoSlug"))
ThisBuild / publishTo := sonatypePublishTo.value
ThisBuild / githubWorkflowBuild := Seq(WorkflowStep.Sbt(List("test", "scripted")))
ThisBuild / githubWorkflowBuild := Seq(WorkflowStep.Sbt(List("+test", "+scripted")))
ThisBuild / githubWorkflowTargetTags ++= Seq("v*")
ThisBuild / githubWorkflowPublishTargetBranches :=
Seq(RefPredicate.StartsWith(Ref.Tag("v")))
Expand All @@ -79,12 +86,11 @@ ThisBuild / githubWorkflowPublish := Seq(
)
)
)
ThisBuild / githubWorkflowOSes := Seq("ubuntu-latest", "macos-latest", "windows-latest")
ThisBuild / githubWorkflowOSes := Seq("ubuntu-latest", "macos-latest")
ThisBuild / githubWorkflowJavaVersions := Seq(
JavaSpec.temurin("8"),
JavaSpec.temurin("17")
)
ThisBuild / githubWorkflowBuildMatrixExclusions ++= Seq(
MatrixExclude(Map("java" -> "temurin@8", "os" -> "macos-latest")),
MatrixExclude(Map("java" -> "temurin@17", "os" -> "windows-latest")),
)
14 changes: 14 additions & 0 deletions src/main/scala-2.12/PluginCompat.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package flywaysbt

import java.nio.file.{ Path => NioPath }
import java.io.File
import sbt.Attributed
import xsbti.FileConverter

private[flywaysbt] object PluginCompat {
type FileRef = java.io.File
type Out = java.io.File

def toNioPath(a: Attributed[File])(implicit conv: FileConverter): NioPath =
a.data.toPath()
}
13 changes: 13 additions & 0 deletions src/main/scala-3/PluginCompat.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package flywaysbt

import java.nio.file.{ Path => NioPath }
import sbt.*
import xsbti.{ FileConverter, HashedVirtualFileRef, VirtualFile }

private[flywaysbt] object PluginCompat:
type FileRef = HashedVirtualFileRef
type Out = VirtualFile

def toNioPath(a: Attributed[HashedVirtualFileRef])(using conv: FileConverter): NioPath =
conv.toPath(a.data)
end PluginCompat
29 changes: 16 additions & 13 deletions src/main/scala/flywaysbt/FlywayPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@
package flywaysbt

import java.util.Properties
import org.flywaydb.core.Flyway
import org.flywaydb.core.api.callback.Callback
import org.flywaydb.core.api.configuration.FluentConfiguration
import org.flywaydb.core.api.logging.{ Log, LogCreator, LogFactory }
import org.flywaydb.core.api.pattern.ValidatePattern
import org.flywaydb.core.Flyway
import org.flywaydb.core.internal.info.MigrationInfoDumper
import org.flywaydb.core.internal.util.ValidatePatternUtils
import sbt.{ given, * }
import sbt.Keys.*
import sbt.*

import scala.collection.JavaConverters.*
import org.flywaydb.core.api.configuration.FluentConfiguration
import org.flywaydb.core.api.pattern.ValidatePattern
import org.flywaydb.core.internal.util.ValidatePatternUtils
import xsbti.FileConverter

object FlywayPlugin extends AutoPlugin {

Expand Down Expand Up @@ -324,13 +324,13 @@ object FlywayPlugin extends AutoPlugin {
// fullClasspath triggers the compile task, so use a dynamic task to only run it if we need to.
// https://github.com/flyway/flyway-sbt/issues/10
if (flywayLocations.value.forall(_.startsWith("filesystem:"))) {
externalDependencyClasspath in conf
conf / externalDependencyClasspath
} else {
fullClasspath in conf
conf / fullClasspath
}
}).value,
// Tasks
flywayDefaults := withPrepared(flywayClasspath.value, streams.value)(Flyway.configure()),
flywayDefaults := withPrepared(flywayClasspath.value, fileConverter.value, streams.value)(Flyway.configure()),
flywayMigrate := flywayDefaults.value.configure(flywayConfig.value).migrate(),
flywayValidate := flywayDefaults.value.configure(flywayConfig.value).validate(),
flywayInfo := {
Expand All @@ -350,9 +350,9 @@ object FlywayPlugin extends AutoPlugin {
Flyway.configure()
}

private def withPrepared[T](cp: Types.Id[Keys.Classpath], streams: TaskStreams)(f: => T): T = {
private def withPrepared[T](cp: Types.Id[Keys.Classpath], conv: FileConverter, streams: TaskStreams)(f: => T): T = {
registerAsFlywayLogger(streams)
withContextClassLoader(cp)(f)
withContextClassLoader(cp, conv)(f)
}

/**
Expand All @@ -363,8 +363,11 @@ object FlywayPlugin extends AutoPlugin {
FlywaySbtLog.streams = Some(streams)
}

private def withContextClassLoader[T](cp: Types.Id[Keys.Classpath])(f: => T): T = {
val classloader = sbt.internal.inc.classpath.ClasspathUtilities.toLoader(cp.map(_.data), getClass.getClassLoader)
private def withContextClassLoader[T](cp: Types.Id[Keys.Classpath], conv0: FileConverter)(f: => T): T = {
implicit val conv: FileConverter = conv0

val classloader =
sbt.internal.inc.classpath.ClasspathUtil.toLoader(cp.map(PluginCompat.toNioPath), getClass.getClassLoader)
val thread = Thread.currentThread
val oldLoader = thread.getContextClassLoader
try {
Expand Down
4 changes: 2 additions & 2 deletions src/sbt-test/flyway-sbt/test1/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ libraryDependencies ++= Seq(
flywayUrl := "jdbc:hsqldb:file:target/flyway_sample;shutdown=true"
flywayUser := "SA"
flywayLocations += "db/sbt"
flywayUrl in Test := "jdbc:hsqldb:file:target/flyway_sample;shutdown=true"
flywayUser in Test := "SA"
Test / flywayUrl := "jdbc:hsqldb:file:target/flyway_sample;shutdown=true"
Test / flywayUser := "SA"
flywayCleanDisabled := false
Test / flywayCleanDisabled := false
6 changes: 3 additions & 3 deletions src/sbt-test/flyway-sbt/test1/test
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
> flywayMigrate
> flywayInfo
> 'eval System.setProperty("flyway.locations", "filesystem:src/main/resources/db/migration,filesystem:src/test/resources/db/migration")'
> test:flywayClean
> test:flywayMigrate
> test:flywayInfo
> Test/flywayClean
> Test/flywayMigrate
> Test/flywayInfo
4 changes: 2 additions & 2 deletions src/sbt-test/flyway-sbt/test2/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ libraryDependencies ++= Seq(
flywayUrl := "jdbc:hsqldb:file:target/flyway_sample;shutdown=true"
flywayUser := "SA"
flywayLocations += "db/migration"
flywayUrl in Test := "jdbc:hsqldb:file:target/flyway_sample;shutdown=true"
flywayUser in Test := "SA"
Test / flywayUrl := "jdbc:hsqldb:file:target/flyway_sample;shutdown=true"
Test / flywayUser := "SA"
flywayCleanDisabled := false
Test / flywayCleanDisabled := false
6 changes: 3 additions & 3 deletions src/sbt-test/flyway-sbt/test3/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ libraryDependencies ++= Seq(
flywayUrl := "jdbc:hsqldb:file:target/flyway_sample;shutdown=true"
flywayUser := "SA"
flywayLocations := Seq("filesystem:src/main/resources/db/migration")
flywayUrl in Test := "jdbc:hsqldb:file:target/flyway_sample;shutdown=true"
flywayUser in Test := "SA"
flywayLocations in Test := Seq("filesystem:src/main/resources/db/migration")
Test / flywayUrl := "jdbc:hsqldb:file:target/flyway_sample;shutdown=true"
Test / flywayUser := "SA"
Test / flywayLocations := Seq("filesystem:src/main/resources/db/migration")
flywayCleanDisabled := false
Test / flywayCleanDisabled := false
4 changes: 2 additions & 2 deletions src/sbt-test/flyway-sbt/test3/test
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
> flywayClean
> flywayMigrate
> test:flywayClean
> test:flywayMigrate
> Test/flywayClean
> Test/flywayMigrate

0 comments on commit 45e6b33

Please sign in to comment.