@zio.dev/zio-sbt 0.4.0-alpha.6 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.md +155 -13
- package/package.json +1 -1
package/index.md
CHANGED
|
@@ -3,7 +3,7 @@ id: index
|
|
|
3
3
|
title: "ZIO SBT"
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
_ZIO SBT_
|
|
6
|
+
_ZIO SBT_ contains multiple sbt plugins that are useful for ZIO projects. It provides high-level SBT utilities that simplify the development of ZIO applications.
|
|
7
7
|
|
|
8
8
|
[](https://github.com/zio/zio/wiki/Project-Stages)  [](https://oss.sonatype.org/content/repositories/releases/dev/zio/zio-sbt-website_2.12/) [](https://oss.sonatype.org/content/repositories/snapshots/dev/zio/zio-sbt-website_2.12/) [](https://javadoc.io/doc/dev.zio/zio-sbt-docs_2.12) [](https://github.com/zio/zio-sbt)
|
|
9
9
|
|
|
@@ -12,15 +12,68 @@ _ZIO SBT_ is an sbt plugin for ZIO projects. It provides high-level SBT utilitie
|
|
|
12
12
|
Add the following lines to your `plugin.sbt` file:
|
|
13
13
|
|
|
14
14
|
```scala
|
|
15
|
-
addSbtPlugin("dev.zio" % "zio-sbt-
|
|
15
|
+
addSbtPlugin("dev.zio" % "zio-sbt-ecosystem" % "0.4.0")
|
|
16
|
+
addSbtPlugin("dev.zio" % "zio-sbt-ci" % "0.4.0")
|
|
17
|
+
addSbtPlugin("dev.zio" % "zio-sbt-website" % "0.4.0")
|
|
16
18
|
```
|
|
17
19
|
|
|
18
|
-
Then you can enable
|
|
20
|
+
Then you can enable them by using the following code in your `build.sbt` file:
|
|
19
21
|
|
|
20
22
|
```scala
|
|
21
|
-
enablePlugins(
|
|
23
|
+
enablePlugins(
|
|
24
|
+
ZioSbtWebsitePlugin,
|
|
25
|
+
ZioSbtEcosystemPlugin,
|
|
26
|
+
ZioSbtCiPlugin
|
|
27
|
+
)
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## ZIO SBT Ecosystem
|
|
31
|
+
|
|
32
|
+
ZIO SBT Ecosystem plugin is an sbt plugin that provides a set of sbt settings and tasks that are very common and useful for configuring and managing ZIO projects. It is designed help developers to quickly set up a new ZIO project with a minimal amount of effort.
|
|
33
|
+
|
|
34
|
+
This pluging provides the following settings with default values:
|
|
35
|
+
|
|
36
|
+
- scala212
|
|
37
|
+
- scala213
|
|
38
|
+
- scala3
|
|
39
|
+
|
|
40
|
+
The default values are the latest stable versions of Scala 2.12, 2.13, and Scala 3. All of these settings are of type `String` and can be overridden by the user.
|
|
41
|
+
|
|
42
|
+
By having these settings, then we can use them in other sbt settings. For example, we can use them to define the `crossScalaVersions` setting:
|
|
43
|
+
|
|
44
|
+
```scala
|
|
45
|
+
crossScalaVersions := Seq(scala212.value, scala213.value, scala3.value)
|
|
22
46
|
```
|
|
23
47
|
|
|
48
|
+
There are also some other settings that are useful for configuring the projects:
|
|
49
|
+
|
|
50
|
+
- `stdSettings`— a set of standard settings which are common for every ZIO project, which includes configuring:
|
|
51
|
+
- silencer plugin
|
|
52
|
+
- kind projector plugin
|
|
53
|
+
- cross project plugin
|
|
54
|
+
- scalafix plugin
|
|
55
|
+
- java target platform
|
|
56
|
+
- `enableZIO`- a set of ZIO related settings such as enabling zio streams and ZIO test framework.
|
|
57
|
+
- `jsSettings`, `nativeSettings`- common platform specific settings for Scala.js and Scala Native.
|
|
58
|
+
|
|
59
|
+
It also provides some helper methods that are useful for configuring a compiler option for a specific Scala version:
|
|
60
|
+
|
|
61
|
+
- `optionsOn`
|
|
62
|
+
- `optionsOnExcept`
|
|
63
|
+
- `optionsOnOrElse`
|
|
64
|
+
- `addOptionsOn`
|
|
65
|
+
- `addOptionsOnOrElse`
|
|
66
|
+
- `addOptionsOnExcept`
|
|
67
|
+
|
|
68
|
+
And the same for adding a dependency for a specific Scala version:
|
|
69
|
+
|
|
70
|
+
- `dependenciesOn`
|
|
71
|
+
- `dependenciesOnExcept`
|
|
72
|
+
- `dependenciesOnOrElse`
|
|
73
|
+
- `addDependenciesOn`
|
|
74
|
+
- `addDependenciesOnExcept`
|
|
75
|
+
- `addDependenciesOnOrElse`
|
|
76
|
+
|
|
24
77
|
## ZIO SBT Website
|
|
25
78
|
|
|
26
79
|
ZIO SBT Website is an SBT plugin that has the following tasks:
|
|
@@ -29,7 +82,6 @@ ZIO SBT Website is an SBT plugin that has the following tasks:
|
|
|
29
82
|
- `sbt installWebsite`— creates a website for the project inside the `website` directory.
|
|
30
83
|
- `sbt previewWebsite`— runs a local webserver that serves documentation locally on http://localhost:3000. By changing the documentation inside the `docs` directory, the website will be reloaded with new content.
|
|
31
84
|
- `sbt publishToNpm`— publishes documentation inside the `docs` directory to the npm registry.
|
|
32
|
-
- `sbt generateGithubWorkflow`— generates GitHub workflow which publishes documentation for each library release.
|
|
33
85
|
- `sbt generateReadme`— generate README.md file from `docs/index.md` and sbt setting keys.
|
|
34
86
|
|
|
35
87
|
## ZIO SBT CI Plugin
|
|
@@ -45,7 +97,7 @@ ZIO SBT CI plugin generates a default GitHub workflow that includes common CI ta
|
|
|
45
97
|
To use ZIO SBT CI plugin, add the following lines to your `plugins.sbt` file:
|
|
46
98
|
|
|
47
99
|
```scala
|
|
48
|
-
addSbtPlugin("dev.zio" % "zio-sbt-ci" % "0.4.0
|
|
100
|
+
addSbtPlugin("dev.zio" % "zio-sbt-ci" % "0.4.0")
|
|
49
101
|
|
|
50
102
|
resolvers ++= Resolver.sonatypeOssRepos("public")
|
|
51
103
|
```
|
|
@@ -62,21 +114,70 @@ Now you can generate a Github workflow by running the following command:
|
|
|
62
114
|
sbt ciGenerateGithubWorkflow
|
|
63
115
|
```
|
|
64
116
|
|
|
65
|
-
|
|
117
|
+
This will generate a GitHub workflow file inside the `.github/workflows` directory, named `ci.yml`. The workflow file contains following default Jobs:
|
|
118
|
+
|
|
119
|
+
- Build
|
|
120
|
+
- Lint
|
|
121
|
+
- Test
|
|
122
|
+
- Update Readme
|
|
123
|
+
|
|
124
|
+
> **Note:**
|
|
125
|
+
>
|
|
126
|
+
> To use this plugin, we also need to install [ZIO Assistant](https://github.com/apps/zio-assistant) bot.
|
|
127
|
+
|
|
128
|
+
## Testing Strategies
|
|
129
|
+
|
|
130
|
+
### Default Testing Strategy
|
|
131
|
+
|
|
132
|
+
The default testing strategy for ZIO SBT CI plugin is to run `sbt +test` on Corretto Java 11, 17 and 21. So this will generate the following job:
|
|
133
|
+
|
|
134
|
+
```yaml
|
|
135
|
+
test:
|
|
136
|
+
name: Test
|
|
137
|
+
runs-on: ubuntu-latest
|
|
138
|
+
continue-on-error: false
|
|
139
|
+
strategy:
|
|
140
|
+
fail-fast: false
|
|
141
|
+
matrix:
|
|
142
|
+
java: ['11', '17', '21']
|
|
143
|
+
steps:
|
|
144
|
+
- name: Install libuv
|
|
145
|
+
run: sudo apt-get update && sudo apt-get install -y libuv1-dev
|
|
146
|
+
- name: Setup Scala
|
|
147
|
+
uses: actions/setup-java@v3.13.0
|
|
148
|
+
with:
|
|
149
|
+
distribution: corretto
|
|
150
|
+
java-version: ${{ matrix.java }}
|
|
151
|
+
check-latest: true
|
|
152
|
+
- name: Cache Dependencies
|
|
153
|
+
uses: coursier/cache-action@v6
|
|
154
|
+
- name: Git Checkout
|
|
155
|
+
uses: actions/checkout@v4.1.1
|
|
156
|
+
with:
|
|
157
|
+
fetch-depth: '0'
|
|
158
|
+
- name: Test
|
|
159
|
+
run: sbt +test
|
|
160
|
+
```
|
|
66
161
|
|
|
67
|
-
|
|
162
|
+
The `sbt +test` command will run the `test` task for all submodules in the project against all Scala versions defined in the `crossScalaVersions` setting.
|
|
163
|
+
|
|
164
|
+
### Concurrent Testing Strategy
|
|
68
165
|
|
|
69
|
-
|
|
166
|
+
In some cases, we may have multiple submodules in our project and we want to test them concurrently using GitHub Actions matrix strategy.
|
|
70
167
|
|
|
71
|
-
|
|
168
|
+
The `ciTargetScalaVersions` setting key is used to define a mapping of project names to the Scala versions that should be used for testing phase of continuous integration (CI).
|
|
169
|
+
|
|
170
|
+
For example, suppose we have a project with the name "submoduleA" and we want to test it against Scala `2.12.20`, and for the "submoduleB" we want to test it against Scala `2.12.20` and `2.13.17` and `3.3.7`, We can define the `ciTargetScalaVersions` setting as follows:
|
|
72
171
|
|
|
73
172
|
```scala
|
|
74
173
|
ThisBuild / ciTargetScalaVersions := Map(
|
|
75
|
-
"submoduleA" -> Seq("2.
|
|
76
|
-
"submoduleB" -> Seq("2.12.
|
|
174
|
+
"submoduleA" -> Seq("2.12.20"),
|
|
175
|
+
"submoduleB" -> Seq("2.12.20", "2.13.17", "3.3.7")
|
|
77
176
|
)
|
|
78
177
|
```
|
|
79
178
|
|
|
179
|
+
In the example provided, `ciTargetScalaVersions` is defined at the `ThisBuild` level, meaning that the setting will apply to all projects within the build. The setting defines a Map where the key is the name of the current project, obtained by calling the `id` method on the `thisProject` setting, and the value is a sequence of Scala versions obtained from the `crossScalaVersions` of each submodule setting.
|
|
180
|
+
|
|
80
181
|
To simplify this process, we can populate the versions using each submodule's crossScalaVersions setting as follows:
|
|
81
182
|
|
|
82
183
|
```scala
|
|
@@ -84,4 +185,45 @@ ThisBuild / ciTargetScalaVersions := Map(
|
|
|
84
185
|
(submoduleA / thisProject).value.id -> (submoduleA / crossScalaVersions).value,
|
|
85
186
|
(submoduleB / thisProject).value.id -> (submoduleB / crossScalaVersions).value
|
|
86
187
|
)
|
|
87
|
-
```
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
The above code can be simplified further by using `targetScalaVersionsFor` helper method, it takes a list of submodules and returns a Map of project names to their `crossScalaVersions`:
|
|
191
|
+
|
|
192
|
+
```scala
|
|
193
|
+
ThisBuild / ciTargetScalaVersions := targetScalaVersionsFor(submoduleA, submoduleB).value
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
This will generate the following job:
|
|
197
|
+
|
|
198
|
+
```yaml
|
|
199
|
+
test:
|
|
200
|
+
name: Test
|
|
201
|
+
runs-on: ubuntu-latest
|
|
202
|
+
continue-on-error: false
|
|
203
|
+
strategy:
|
|
204
|
+
fail-fast: false
|
|
205
|
+
matrix:
|
|
206
|
+
java: ['11', '17', '21']
|
|
207
|
+
scala-project:
|
|
208
|
+
- ++2.12.20 submoduleA
|
|
209
|
+
- ++2.12.20 submoduleB
|
|
210
|
+
- ++2.13.17 submoduleB
|
|
211
|
+
- ++3.3.7 submoduleB
|
|
212
|
+
steps:
|
|
213
|
+
- name: Install libuv
|
|
214
|
+
run: sudo apt-get update && sudo apt-get install -y libuv1-dev
|
|
215
|
+
- name: Setup Scala
|
|
216
|
+
uses: actions/setup-java@v3.10.0
|
|
217
|
+
with:
|
|
218
|
+
distribution: corretto
|
|
219
|
+
java-version: ${{ matrix.java }}
|
|
220
|
+
check-latest: true
|
|
221
|
+
- name: Cache Dependencies
|
|
222
|
+
uses: coursier/cache-action@v6
|
|
223
|
+
- name: Git Checkout
|
|
224
|
+
uses: actions/checkout@v4.1.1
|
|
225
|
+
with:
|
|
226
|
+
fetch-depth: '0'
|
|
227
|
+
- name: Test
|
|
228
|
+
run: sbt ${{ matrix.scala-project }}/test
|
|
229
|
+
```
|
package/package.json
CHANGED