diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5376e7a8..91176a13 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -2,6 +2,10 @@ name: ci on: push: + branches: + - master + tags: + - '*' pull_request: branches: - main @@ -49,7 +53,7 @@ jobs: distribution: 'temurin' java-version: 17 - - run: ./mill -i "__.test" + generateTutorial + generateReference && git diff --exit-code + - run: ./mill -i "__.test" && ./mill -i generateTutorial + generateReference && git diff --exit-code check-scalafix: runs-on: ubuntu-latest diff --git a/.mill-version b/.mill-version new file mode 100644 index 00000000..ac454c6a --- /dev/null +++ b/.mill-version @@ -0,0 +1 @@ +0.12.0 diff --git a/build.sc b/build.sc index ce5623bd..94cb573e 100644 --- a/build.sc +++ b/build.sc @@ -1,7 +1,7 @@ import $file.docs.generateDocs import $ivy.`de.tototec::de.tobiasroeser.mill.vcs.version::0.4.0` import $ivy.`com.github.lolgab::mill-mima::0.1.0` -import $ivy.`com.goyeau::mill-scalafix::0.4.0` +import $ivy.`com.goyeau::mill-scalafix::0.4.2` import de.tobiasroeser.mill.vcs.version.VcsVersion import com.goyeau.mill.scalafix.ScalafixModule import mill._, scalalib._, publish._ @@ -67,6 +67,7 @@ trait ScalaSql extends Common{ common => def testFramework = "scalasql.UtestFramework" def forkArgs = Seq("-Duser.timezone=Asia/Singapore") + def forkEnv = Map("MILL_WORKSPACE_ROOT" -> T.workspace.toString()) } private def indent(code: Iterable[String]): String = @@ -212,13 +213,13 @@ trait ScalaSql extends Common{ common => val generatedCodeHeader = "[//]: # (GENERATED SOURCES, DO NOT EDIT DIRECTLY)" def generateTutorial() = T.command { generateDocs.generateTutorial( - os.pwd / "scalasql" / "test" / "src" / "WorldSqlTests.scala", - os.pwd / "docs" / "tutorial.md" + T.workspace / "scalasql" / "test" / "src" / "WorldSqlTests.scala", + T.workspace / "docs" / "tutorial.md" ) } def generateReference() = T.command { generateDocs.generateReference( - os.pwd / "docs" / "reference.md", + T.workspace / "docs" / "reference.md", (sources, config) => mill.scalalib.scalafmt.ScalafmtWorkerModule .worker() diff --git a/docs/generateDocs.sc b/docs/generateDocs.sc index d32b96a1..5a1e6ef5 100644 --- a/docs/generateDocs.sc +++ b/docs/generateDocs.sc @@ -25,7 +25,7 @@ def generateTutorial(sourcePath: os.Path, destPath: os.Path) = { case ("", _) => outputLines.append("") case (s"// +INCLUDE $rest", _) => - os.read.lines(os.pwd / os.SubPath(rest)).foreach(outputLines.append) + os.read.lines(mill.api.WorkspaceRoot.workspaceRoot / os.SubPath(rest)).foreach(outputLines.append) case (s"//$rest", false) => outputLines.append(rest.stripPrefix(" ")) @@ -49,14 +49,14 @@ def generateTutorial(sourcePath: os.Path, destPath: os.Path) = { } def generateReference(dest: os.Path, scalafmtCallback: (Seq[os.Path], os.Path) => Unit) = { def dropExprPrefix(s: String) = s.split('.').drop(2).mkString(".") - val records = upickle.default.read[Seq[Record]](os.read.stream(os.pwd / "out" / "recordedTests.json")) - val suiteDescriptions = upickle.default.read[Map[String, String]](os.read.stream(os.pwd / "out" / "recordedSuiteDescriptions.json")) + val records = upickle.default.read[Seq[Record]](os.read.stream(mill.api.WorkspaceRoot.workspaceRoot / "out" / "recordedTests.json")) + val suiteDescriptions = upickle.default.read[Map[String, String]](os.read.stream(mill.api.WorkspaceRoot.workspaceRoot / "out" / "recordedSuiteDescriptions.json")) .map{case (k, v) => (dropExprPrefix(k), v)} val rawScalaStrs = records.flatMap(r => Seq(r.queryCodeString) ++ r.resultCodeString) val formattedScalaStrs = { val tmps = rawScalaStrs.map(os.temp(_, suffix = ".scala")) - scalafmtCallback(tmps, os.pwd / ".scalafmt.conf") + scalafmtCallback(tmps, mill.api.WorkspaceRoot.workspaceRoot / ".scalafmt.conf") tmps.map(os.read(_).trim) } diff --git a/docs/tutorial.md b/docs/tutorial.md index 34cd47f1..ba10f6a7 100644 --- a/docs/tutorial.md +++ b/docs/tutorial.md @@ -134,8 +134,8 @@ val dbClient = new DbClient.Connection( ) val db = dbClient.getAutoCommitClientConnection -db.updateRaw(os.read(os.pwd / "scalasql" / "test" / "resources" / "world-schema.sql")) -db.updateRaw(os.read(os.pwd / "scalasql" / "test" / "resources" / "world-data.sql")) +db.updateRaw(os.read(os.Path(sys.env("MILL_TEST_RESOURCE_DIR")) / "world-schema.sql")) +db.updateRaw(os.read(os.Path(sys.env("MILL_TEST_RESOURCE_DIR")) / "world-data.sql")) ``` We use `dbClient.getAutoCommitClientConnection` in order to create a client that diff --git a/mill b/mill index 41278e89..d03a045c 100755 --- a/mill +++ b/mill @@ -7,7 +7,7 @@ set -e if [ -z "${DEFAULT_MILL_VERSION}" ] ; then - DEFAULT_MILL_VERSION=0.11.11 + DEFAULT_MILL_VERSION=0.11.12 fi if [ -z "$MILL_VERSION" ] ; then @@ -53,7 +53,9 @@ if [ -z "$MILL_MAIN_CLI" ] ; then fi MILL_FIRST_ARG="" -if [ "$1" = "--bsp" ] || [ "$1" = "-i" ] || [ "$1" = "--interactive" ] || [ "$1" = "--no-server" ] || [ "$1" = "--repl" ] || [ "$1" = "--help" ] ; then + + # first arg is a long flag for "--interactive" or starts with "-i" +if [ "$1" = "--bsp" ] || [ "${1#"-i"}" != "$1" ] || [ "$1" = "--interactive" ] || [ "$1" = "--no-server" ] || [ "$1" = "--repl" ] || [ "$1" = "--help" ] ; then # Need to preserve the first position of those listed options MILL_FIRST_ARG=$1 shift diff --git a/scalasql/test/src/UtestFramework.scala b/scalasql/test/src/UtestFramework.scala index e443d044..de1d809c 100644 --- a/scalasql/test/src/UtestFramework.scala +++ b/scalasql/test/src/UtestFramework.scala @@ -26,12 +26,13 @@ class UtestFramework extends utest.runner.Framework { } override def teardown() = { println("Tearing down CustomFramework " + recordedTests.size) + val workspaceRoot = os.Path(sys.env("MILL_WORKSPACE_ROOT")) os.write.over( - os.pwd / "out" / "recordedTests.json", + workspaceRoot / "out" / "recordedTests.json", upickle.default.write(UtestFramework.recordedTests, indent = 4) ) os.write.over( - os.pwd / "out" / "recordedSuiteDescriptions.json", + workspaceRoot / "out" / "recordedSuiteDescriptions.json", upickle.default.write(UtestFramework.recordedSuiteDescriptions, indent = 4) ) recordedTests.clear() diff --git a/scalasql/test/src/WorldSqlTests.scala b/scalasql/test/src/WorldSqlTests.scala index 0bc472db..5433f709 100644 --- a/scalasql/test/src/WorldSqlTests.scala +++ b/scalasql/test/src/WorldSqlTests.scala @@ -127,8 +127,8 @@ object WorldSqlTests extends TestSuite { ) val db = dbClient.getAutoCommitClientConnection - db.updateRaw(os.read(os.pwd / "scalasql" / "test" / "resources" / "world-schema.sql")) - db.updateRaw(os.read(os.pwd / "scalasql" / "test" / "resources" / "world-data.sql")) + db.updateRaw(os.read(os.Path(sys.env("MILL_TEST_RESOURCE_DIR")) / "world-schema.sql")) + db.updateRaw(os.read(os.Path(sys.env("MILL_TEST_RESOURCE_DIR")) / "world-data.sql")) // We use `dbClient.getAutoCommitClientConnection` in order to create a client that // will automatically run every SQL command in a new transaction and commit it. For // the majority of examples in this page, the exact transaction configuration doesn't diff --git a/scalasql/test/src/utils/TestChecker.scala b/scalasql/test/src/utils/TestChecker.scala index bc1b8468..86f31ec8 100644 --- a/scalasql/test/src/utils/TestChecker.scala +++ b/scalasql/test/src/utils/TestChecker.scala @@ -19,10 +19,10 @@ class TestChecker( val autoCommitConnection = dbClient.getAutoCommitClientConnection def reset() = { autoCommitConnection.updateRaw( - os.read(os.pwd / "scalasql" / "test" / "resources" / testSchemaFileName) + os.read(os.Path(sys.env("MILL_TEST_RESOURCE_DIR")) / testSchemaFileName) ) autoCommitConnection.updateRaw( - os.read(os.pwd / "scalasql" / "test" / "resources" / testDataFileName) + os.read(os.Path(sys.env("MILL_TEST_RESOURCE_DIR")) / testDataFileName) ) }