Skip to content

Commit c650c79

Browse files
authored
Create .mill-version (#30)
1 parent e97a68b commit c650c79

File tree

9 files changed

+28
-19
lines changed

9 files changed

+28
-19
lines changed

.github/workflows/build.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ name: ci
22

33
on:
44
push:
5+
branches:
6+
- master
7+
tags:
8+
- '*'
59
pull_request:
610
branches:
711
- main
@@ -49,7 +53,7 @@ jobs:
4953
distribution: 'temurin'
5054
java-version: 17
5155

52-
- run: ./mill -i "__.test" + generateTutorial + generateReference && git diff --exit-code
56+
- run: ./mill -i "__.test" && ./mill -i generateTutorial + generateReference && git diff --exit-code
5357

5458
check-scalafix:
5559
runs-on: ubuntu-latest

.mill-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.12.0

build.sc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import $file.docs.generateDocs
22
import $ivy.`de.tototec::de.tobiasroeser.mill.vcs.version::0.4.0`
33
import $ivy.`com.github.lolgab::mill-mima::0.1.0`
4-
import $ivy.`com.goyeau::mill-scalafix::0.4.0`
4+
import $ivy.`com.goyeau::mill-scalafix::0.4.2`
55
import de.tobiasroeser.mill.vcs.version.VcsVersion
66
import com.goyeau.mill.scalafix.ScalafixModule
77
import mill._, scalalib._, publish._
@@ -67,6 +67,7 @@ trait ScalaSql extends Common{ common =>
6767
def testFramework = "scalasql.UtestFramework"
6868

6969
def forkArgs = Seq("-Duser.timezone=Asia/Singapore")
70+
def forkEnv = Map("MILL_WORKSPACE_ROOT" -> T.workspace.toString())
7071
}
7172

7273
private def indent(code: Iterable[String]): String =
@@ -212,13 +213,13 @@ trait ScalaSql extends Common{ common =>
212213
val generatedCodeHeader = "[//]: # (GENERATED SOURCES, DO NOT EDIT DIRECTLY)"
213214
def generateTutorial() = T.command {
214215
generateDocs.generateTutorial(
215-
os.pwd / "scalasql" / "test" / "src" / "WorldSqlTests.scala",
216-
os.pwd / "docs" / "tutorial.md"
216+
T.workspace / "scalasql" / "test" / "src" / "WorldSqlTests.scala",
217+
T.workspace / "docs" / "tutorial.md"
217218
)
218219
}
219220
def generateReference() = T.command {
220221
generateDocs.generateReference(
221-
os.pwd / "docs" / "reference.md",
222+
T.workspace / "docs" / "reference.md",
222223
(sources, config) =>
223224
mill.scalalib.scalafmt.ScalafmtWorkerModule
224225
.worker()

docs/generateDocs.sc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def generateTutorial(sourcePath: os.Path, destPath: os.Path) = {
2525
case ("", _) => outputLines.append("")
2626

2727
case (s"// +INCLUDE $rest", _) =>
28-
os.read.lines(os.pwd / os.SubPath(rest)).foreach(outputLines.append)
28+
os.read.lines(mill.api.WorkspaceRoot.workspaceRoot / os.SubPath(rest)).foreach(outputLines.append)
2929

3030
case (s"//$rest", false) => outputLines.append(rest.stripPrefix(" "))
3131

@@ -49,14 +49,14 @@ def generateTutorial(sourcePath: os.Path, destPath: os.Path) = {
4949
}
5050
def generateReference(dest: os.Path, scalafmtCallback: (Seq[os.Path], os.Path) => Unit) = {
5151
def dropExprPrefix(s: String) = s.split('.').drop(2).mkString(".")
52-
val records = upickle.default.read[Seq[Record]](os.read.stream(os.pwd / "out" / "recordedTests.json"))
53-
val suiteDescriptions = upickle.default.read[Map[String, String]](os.read.stream(os.pwd / "out" / "recordedSuiteDescriptions.json"))
52+
val records = upickle.default.read[Seq[Record]](os.read.stream(mill.api.WorkspaceRoot.workspaceRoot / "out" / "recordedTests.json"))
53+
val suiteDescriptions = upickle.default.read[Map[String, String]](os.read.stream(mill.api.WorkspaceRoot.workspaceRoot / "out" / "recordedSuiteDescriptions.json"))
5454
.map{case (k, v) => (dropExprPrefix(k), v)}
5555

5656
val rawScalaStrs = records.flatMap(r => Seq(r.queryCodeString) ++ r.resultCodeString)
5757
val formattedScalaStrs = {
5858
val tmps = rawScalaStrs.map(os.temp(_, suffix = ".scala"))
59-
scalafmtCallback(tmps, os.pwd / ".scalafmt.conf")
59+
scalafmtCallback(tmps, mill.api.WorkspaceRoot.workspaceRoot / ".scalafmt.conf")
6060

6161
tmps.map(os.read(_).trim)
6262
}

docs/tutorial.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ val dbClient = new DbClient.Connection(
134134
)
135135

136136
val db = dbClient.getAutoCommitClientConnection
137-
db.updateRaw(os.read(os.pwd / "scalasql" / "test" / "resources" / "world-schema.sql"))
138-
db.updateRaw(os.read(os.pwd / "scalasql" / "test" / "resources" / "world-data.sql"))
137+
db.updateRaw(os.read(os.Path(sys.env("MILL_TEST_RESOURCE_DIR")) / "world-schema.sql"))
138+
db.updateRaw(os.read(os.Path(sys.env("MILL_TEST_RESOURCE_DIR")) / "world-data.sql"))
139139

140140
```
141141
We use `dbClient.getAutoCommitClientConnection` in order to create a client that

mill

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
set -e
88

99
if [ -z "${DEFAULT_MILL_VERSION}" ] ; then
10-
DEFAULT_MILL_VERSION=0.11.11
10+
DEFAULT_MILL_VERSION=0.11.12
1111
fi
1212

1313
if [ -z "$MILL_VERSION" ] ; then
@@ -53,7 +53,9 @@ if [ -z "$MILL_MAIN_CLI" ] ; then
5353
fi
5454

5555
MILL_FIRST_ARG=""
56-
if [ "$1" = "--bsp" ] || [ "$1" = "-i" ] || [ "$1" = "--interactive" ] || [ "$1" = "--no-server" ] || [ "$1" = "--repl" ] || [ "$1" = "--help" ] ; then
56+
57+
# first arg is a long flag for "--interactive" or starts with "-i"
58+
if [ "$1" = "--bsp" ] || [ "${1#"-i"}" != "$1" ] || [ "$1" = "--interactive" ] || [ "$1" = "--no-server" ] || [ "$1" = "--repl" ] || [ "$1" = "--help" ] ; then
5759
# Need to preserve the first position of those listed options
5860
MILL_FIRST_ARG=$1
5961
shift

scalasql/test/src/UtestFramework.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@ class UtestFramework extends utest.runner.Framework {
2626
}
2727
override def teardown() = {
2828
println("Tearing down CustomFramework " + recordedTests.size)
29+
val workspaceRoot = os.Path(sys.env("MILL_WORKSPACE_ROOT"))
2930
os.write.over(
30-
os.pwd / "out" / "recordedTests.json",
31+
workspaceRoot / "out" / "recordedTests.json",
3132
upickle.default.write(UtestFramework.recordedTests, indent = 4)
3233
)
3334
os.write.over(
34-
os.pwd / "out" / "recordedSuiteDescriptions.json",
35+
workspaceRoot / "out" / "recordedSuiteDescriptions.json",
3536
upickle.default.write(UtestFramework.recordedSuiteDescriptions, indent = 4)
3637
)
3738
recordedTests.clear()

scalasql/test/src/WorldSqlTests.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ object WorldSqlTests extends TestSuite {
127127
)
128128

129129
val db = dbClient.getAutoCommitClientConnection
130-
db.updateRaw(os.read(os.pwd / "scalasql" / "test" / "resources" / "world-schema.sql"))
131-
db.updateRaw(os.read(os.pwd / "scalasql" / "test" / "resources" / "world-data.sql"))
130+
db.updateRaw(os.read(os.Path(sys.env("MILL_TEST_RESOURCE_DIR")) / "world-schema.sql"))
131+
db.updateRaw(os.read(os.Path(sys.env("MILL_TEST_RESOURCE_DIR")) / "world-data.sql"))
132132
// We use `dbClient.getAutoCommitClientConnection` in order to create a client that
133133
// will automatically run every SQL command in a new transaction and commit it. For
134134
// the majority of examples in this page, the exact transaction configuration doesn't

scalasql/test/src/utils/TestChecker.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ class TestChecker(
1919
val autoCommitConnection = dbClient.getAutoCommitClientConnection
2020
def reset() = {
2121
autoCommitConnection.updateRaw(
22-
os.read(os.pwd / "scalasql" / "test" / "resources" / testSchemaFileName)
22+
os.read(os.Path(sys.env("MILL_TEST_RESOURCE_DIR")) / testSchemaFileName)
2323
)
2424
autoCommitConnection.updateRaw(
25-
os.read(os.pwd / "scalasql" / "test" / "resources" / testDataFileName)
25+
os.read(os.Path(sys.env("MILL_TEST_RESOURCE_DIR")) / testDataFileName)
2626
)
2727
}
2828

0 commit comments

Comments
 (0)