Skip to content

Commit c8f2383

Browse files
authored
Use actual default values in .scala-steward.conf doc (#3103)
This generates `docs/repo-specific-configuration.md` from a mdoc source file such that the default values referenced in that documentation are always in sync with the actual default values in the source code.
1 parent a3c0851 commit c8f2383

File tree

5 files changed

+258
-9
lines changed

5 files changed

+258
-9
lines changed

build.sbt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,12 @@ lazy val docs = myCrossProject("docs")
248248
try git.runner.value.apply("diff", "--quiet", outDir)(rootDir, streams.value.log)
249249
catch {
250250
case t: Throwable =>
251-
val msg = s"Docs in $inDir and $outDir are out of sync." +
252-
" Run 'sbt docs/mdoc' and commit the changes to fix this."
251+
val diff = git.runner.value.apply("diff", outDir)(rootDir, streams.value.log)
252+
val msg = s"""|Docs in $inDir and $outDir are out of sync.
253+
|Run 'sbt docs/mdoc' and commit the changes to fix this.
254+
|The diff is:
255+
|$diff
256+
|""".stripMargin
253257
throw new Throwable(msg, t)
254258
}
255259
()

docs/repo-specific-configuration.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ If a configuration file exists in more than one location, only the first found f
2929
# while the time parts are only used to abide to the frequency of
3030
# the given expression.
3131
#
32-
# Default: @asap
32+
# Default: "@asap"
3333
#
3434
#pullRequests.frequency = "0 0 ? * 3" # every thursday on midnight
3535
pullRequests.frequency = "7 days"
@@ -63,7 +63,7 @@ pullRequests.frequency = "7 days"
6363
# For grouping every update together a filter like {group = "*"} can be # provided.
6464
#
6565
# To create a new PR for each unique combination of artifact-versions, include ${hash} in the name.
66-
#
66+
#
6767
# Default: []
6868
pullRequests.grouping = [
6969
{ name = "patches", "title" = "Patch updates", "filter" = [{"version" = "patch"}] },
@@ -113,11 +113,11 @@ updates.allowPreReleases = [ { groupId = "com.example", artifactId="foo" } ]
113113

114114
# If set, Scala Steward will only create or update `n` PRs each time it runs (see `pullRequests.frequency` above).
115115
# Useful if running frequently and/or CI build are costly
116-
# Default: None
116+
# Default: null
117117
updates.limit = 5
118118

119119
# The extensions of files that should be updated.
120-
# Default: [".scala", ".sbt", ".sbt.shared", ".sc", ".yml", "pom.xml"]
120+
# Default: [".mill-version",".sbt",".sbt.shared",".sc",".scala",".scalafmt.conf",".yml","build.properties","mill-version","pom.xml"]
121121
updates.fileExtensions = [".scala", ".sbt", ".sbt.shared", ".sc", ".yml", ".md", ".markdown", ".txt"]
122122

123123
# If "on-conflicts", Scala Steward will update the PR it created to resolve conflicts as

modules/core/src/main/scala/org/scalasteward/core/repoconfig/RepoConfig.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import io.circe.syntax._
2525
import org.scalasteward.core.buildtool.BuildRoot
2626
import org.scalasteward.core.data.Repo
2727
import org.scalasteward.core.edit.hooks.PostUpdateHook
28+
import org.scalasteward.core.repoconfig.RepoConfig.defaultBuildRoots
2829

2930
final case class RepoConfig(
3031
commits: CommitsConfig = CommitsConfig(),
@@ -41,7 +42,7 @@ final case class RepoConfig(
4142
def buildRootsOrDefault(repo: Repo): List[BuildRoot] =
4243
buildRoots
4344
.map(_.filterNot(_.relativePath.contains("..")))
44-
.getOrElse(List(BuildRootConfig.repoRoot))
45+
.getOrElse(defaultBuildRoots)
4546
.map(cfg => BuildRoot(repo, cfg.relativePath))
4647

4748
def postUpdateHooksOrDefault: List[PostUpdateHook] =
@@ -57,6 +58,9 @@ final case class RepoConfig(
5758
object RepoConfig {
5859
val empty: RepoConfig = RepoConfig()
5960

61+
val defaultBuildRoots: List[BuildRootConfig] =
62+
List(BuildRootConfig.repoRoot)
63+
6064
implicit val repoConfigEq: Eq[RepoConfig] =
6165
Eq.fromUniversalEquals
6266

modules/core/src/main/scala/org/scalasteward/core/repoconfig/UpdatesConfig.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import org.scalasteward.core.buildtool.maven.pomXmlName
2727
import org.scalasteward.core.buildtool.mill.MillAlg
2828
import org.scalasteward.core.buildtool.sbt.buildPropertiesName
2929
import org.scalasteward.core.data.{GroupId, Update}
30+
import org.scalasteward.core.repoconfig.UpdatesConfig.defaultLimit
3031
import org.scalasteward.core.scalafmt.scalafmtConfName
3132
import org.scalasteward.core.update.FilterAlg.{
3233
FilterResult,
@@ -41,7 +42,7 @@ final case class UpdatesConfig(
4142
allow: List[UpdatePattern] = List.empty,
4243
allowPreReleases: List[UpdatePattern] = List.empty,
4344
ignore: List[UpdatePattern] = List.empty,
44-
limit: Option[NonNegInt] = None,
45+
limit: Option[NonNegInt] = defaultLimit,
4546
fileExtensions: Option[List[String]] = None
4647
) {
4748
def fileExtensionsOrDefault: Set[String] =
@@ -88,7 +89,7 @@ final case class UpdatesConfig(
8889
}
8990

9091
object UpdatesConfig {
91-
private val defaultFileExtensions: Set[String] =
92+
val defaultFileExtensions: Set[String] =
9293
Set(
9394
MillAlg.millVersionName,
9495
MillAlg.millVersionNameInConfig,
@@ -102,6 +103,8 @@ object UpdatesConfig {
102103
pomXmlName
103104
)
104105

106+
val defaultLimit: Option[NonNegInt] = None
107+
105108
implicit val updatesConfigEq: Eq[UpdatesConfig] =
106109
Eq.fromUniversalEquals
107110

Lines changed: 238 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
1+
# Repository-specific configuration
2+
3+
You can add a configuration file `.scala-steward.conf` to configure how Scala Steward updates your repository.
4+
The `.scala-steward.conf` configuration file can be located in the root of your repository, in `.github` directory or in `.config` directory (searched in this order).
5+
If a configuration file exists in more than one location, only the first found file is taken into account.
6+
7+
```scala mdoc:passthrough
8+
import io.circe.refined._
9+
import io.circe.syntax._
10+
import org.scalasteward.core.repoconfig._
11+
12+
print("```properties")
13+
print(s"""
14+
# pullRequests.frequency allows to control how often or when Scala Steward
15+
# is allowed to create pull requests.
16+
#
17+
# Possible values:
18+
# @asap
19+
# PRs are created without delay.
20+
#
21+
# <timespan>
22+
# PRs are created only again after the given timespan since the last PR
23+
# has passed. Example values are "36 hours", "1 day", or "14 days".
24+
25+
# <CRON expression>
26+
# PRs are created roughly according to the given CRON expression.
27+
#
28+
# CRON expressions consist of five fields:
29+
# minutes, hour of day, day of month, month, and day of week.
30+
#
31+
# See https://www.alonsodomin.me/cron4s/userguide/index.html#parsing for
32+
# more information about the CRON expressions that are supported.
33+
#
34+
# Note that the date parts of the CRON expression are matched exactly
35+
# while the time parts are only used to abide to the frequency of
36+
# the given expression.
37+
#
38+
# Default: ${PullRequestsConfig.defaultFrequency.asJson.noSpaces}
39+
#
40+
#pullRequests.frequency = "0 0 ? * 3" # every thursday on midnight
41+
pullRequests.frequency = "7 days"
42+
43+
# pullRequests.grouping allows you to specify how Scala Steward should group
44+
# your updates in order to reduce the number of pull-requests.
45+
#
46+
# Updates will be placed in the first group with which they match, starting
47+
# from the first in the array. Those that do not match any group will follow
48+
# the default procedure (one PR per update).
49+
#
50+
# Each element in the array will have the following schema:
51+
#
52+
# - name (mandatory): the name of the group, will be used for things like naming the branch
53+
# - title (optional): if provided it will be used as the title for the PR
54+
# - filter (mandatory): a non-empty list containing the filters to use to know
55+
# if an update falls into this group.
56+
#
57+
# `filter` properties would have this format:
58+
#
59+
# {
60+
# version = "major" | "minor" | "patch" | "pre-release" | "build-metadata",
61+
# group = "{group}",
62+
# artifact = "{artifact}"
63+
# }
64+
#
65+
# For more information on the values for the `version` filter visit https://semver.org/
66+
#
67+
# Every field in a `filter` is optional but at least one must be provided.
68+
#
69+
# For grouping every update together a filter like {group = "*"} can be # provided.
70+
#
71+
# To create a new PR for each unique combination of artifact-versions, include $${hash} in the name.
72+
#
73+
# Default: []
74+
pullRequests.grouping = [
75+
{ name = "patches", "title" = "Patch updates", "filter" = [{"version" = "patch"}] },
76+
{ name = "minor_major", "title" = "Minor/major updates", "filter" = [{"version" = "minor"}, {"version" = "major"}] },
77+
{ name = "typelevel", "title" = "Typelevel updates", "filter" = [{"group" = "org.typelevel"}, {"group" = "org.http4s"}] },
78+
{ name = "my_libraries_$${hash}", "filter" = [{"artifact" = "my-library"}, {"artifact" = "my-other-library", "group" = "my-org"}] },
79+
{ name = "all", "title" = "Dependency updates", "filter" = [{"group" = "*"}] }
80+
]
81+
82+
# pullRequests.includeMatchedLabels allows to control which autogenerated labels are added to PRs
83+
# This setting has no effect on custom labels (see below).
84+
# via a regex check each label is checked against.
85+
# Defaults to no regex (all labels are added) which is equivalent to ".*".
86+
pullRequests.includeMatchedLabels = "(.*semver.*)|(commit-count:n:.*)"
87+
88+
# pullRequests.customLabels allows to add custom labels to PRs.
89+
# This is useful if you want to use the labels for automation (project board for example).
90+
# Defaults to no labels (no labels are added).
91+
pullRequests.customLabels = [ "dependencies", "scala" ]
92+
93+
# Only these dependencies which match the given patterns are updated.
94+
#
95+
# Each pattern must have `groupId`, and may have `artifactId` and `version`.
96+
# Defaults to empty `[]` which mean Scala Steward will update all dependencies.
97+
updates.allow = [ { groupId = "com.example" } ]
98+
99+
# The dependencies which match the given version pattern are updated.
100+
# Dependencies that are not listed will be updated.
101+
#
102+
# Each pattern must have `groupId`, `version` and optional `artifactId`.
103+
# Defaults to empty `[]` which mean Scala Steward will update all dependencies.
104+
# the following example will allow to update foo when version is 1.1.x
105+
updates.pin = [ { groupId = "com.example", artifactId="foo", version = "1.1." } ]
106+
107+
# The dependencies which match the given pattern are NOT updated.
108+
#
109+
# Each pattern must have `groupId`, and may have `artifactId` and `version`.
110+
# Defaults to empty `[]` which mean Scala Steward will not ignore dependencies.
111+
updates.ignore = [ { groupId = "org.acme", artifactId="foo", version = "1.0" } ]
112+
113+
# The dependencies which match the given patterns are allowed to be updated to pre-release from stable.
114+
# This also implies, that it will be allowed for snapshot versions to be updated to snapshots of different series.
115+
#
116+
# Each pattern must have `groupId`, and may have `artifactId` and `version`.
117+
# Defaults to empty `[]` which mean Scala Steward will ignore all stable to pre-release update options.
118+
updates.allowPreReleases = [ { groupId = "com.example", artifactId="foo" } ]
119+
120+
# If set, Scala Steward will only create or update `n` PRs each time it runs (see `pullRequests.frequency` above).
121+
# Useful if running frequently and/or CI build are costly
122+
# Default: ${UpdatesConfig.defaultLimit.asJson.noSpaces}
123+
updates.limit = 5
124+
125+
# The extensions of files that should be updated.
126+
# Default: ${UpdatesConfig.defaultFileExtensions.toList.sorted.asJson.noSpaces}
127+
updates.fileExtensions = [".scala", ".sbt", ".sbt.shared", ".sc", ".yml", ".md", ".markdown", ".txt"]
128+
129+
# If "on-conflicts", Scala Steward will update the PR it created to resolve conflicts as
130+
# long as you don't change it yourself.
131+
# If "always", Scala Steward will always update the PR it created as long as
132+
# you don't change it yourself.
133+
# If "never", Scala Steward will never update the PR
134+
# Default: ${PullRequestUpdateStrategy.default.asJson.noSpaces}
135+
updatePullRequests = "always" | "on-conflicts" | "never"
136+
137+
# If set, Scala Steward will use this message template for the commit messages and PR titles.
138+
# Supported variables: $${artifactName}, $${currentVersion}, $${nextVersion} and $${default}
139+
# Default: ${CommitsConfig.defaultMessage.asJson.noSpaces} which is equivalent to "Update $${artifactName} to $${nextVersion}"
140+
commits.message = "Update $${artifactName} from $${currentVersion} to $${nextVersion}"
141+
142+
# If true and when upgrading version in .scalafmt.conf, Scala Steward will perform scalafmt
143+
# and add a separate commit when format changed. So you don't need reformat manually and can merge PR.
144+
# If false, Scala Steward will not perform scalafmt, so your CI may abort when reformat needed.
145+
# Default: ${ScalafmtConfig.defaultRunAfterUpgrading.asJson.noSpaces}
146+
scalafmt.runAfterUpgrading = false
147+
148+
# It is possible to have multiple scala projects in a single repository. In that case the folders containing the projects (build.sbt folders)
149+
# are specified using the buildRoots property. Note that the paths used there are relative and if the repo directory itself also contains a build.sbt the dot can be used to specify it.
150+
# Default: ${RepoConfig.defaultBuildRoots.asJson.noSpaces}
151+
buildRoots = [ ".", "subfolder/projectA" ]
152+
153+
# Define commands that are executed after an update via a hook.
154+
# A groupId and/or artifactId can be defined to only execute after certain dependencies are updated. If neither is defined, the hook runs for every update.
155+
postUpdateHooks = [{
156+
command = ["sbt", "protobufGenerate"],
157+
commitMessage = "Regenerated protobuf files",
158+
groupId = "com.github.sbt",
159+
artifactId = "sbt-protobuf"
160+
}]
161+
162+
# You can override some config options for dependencies that matches the given pattern.
163+
# Currently, "pullRequests" can be overridden.
164+
# Each pattern must have `groupId`, and may have `artifactId` and `version`.
165+
# First-matched entry is used.
166+
# More-specific entry should be placed before less-specific entry.
167+
#
168+
# Default: empty `[]`
169+
dependencyOverrides = [
170+
{
171+
dependency = { groupId = "com.example", artifactId = "foo", version = "2." },
172+
pullRequests = { frequency = "1 day" },
173+
},
174+
{
175+
dependency = { groupId = "com.example", artifactId = "foo" },
176+
pullRequests = { frequency = "30 day" },
177+
},
178+
{
179+
dependency = { groupId = "com.example" },
180+
pullRequests = { frequency = "14 day" },
181+
}
182+
]
183+
184+
# Assign people from the list to the pull request or request a review.
185+
# Currently supported only for GitLab and GitHub.
186+
# GitLab users - free version of GitLab only supports one assignee and one reviewer, others will be ignored.
187+
# GitHub users - to request review from a team inside your organisation it should be specified
188+
# like "yourOrg/yourTeam" in `reviewers` config below.
189+
# Please note that only accounts with write access to the repository (Developer role for GitLab) are able
190+
# to add assignees or request reviews. Consequently, it won't work for public @scala-steward instance on GitHub.
191+
assignees = [ "username1", "username2" ]
192+
reviewers = [ "username1", "username2" ]
193+
""")
194+
println("```")
195+
```
196+
197+
The version information given in the patterns above can be in two formats:
198+
1. just a `version` field that is treated as a prefix of the version
199+
2. a structure consisting of any of the following fields:
200+
* `prefix`: is matched against the beginning of the version
201+
* `suffix`: is matched against the end of the version
202+
* `exact`: is matched against the whole version
203+
* `contains`: is matched against substrings in the version
204+
205+
```properties
206+
version = "1.1."
207+
version = { prefix = "1.1." }
208+
version = { suffix = "jre8" }
209+
version = { prefix = "1.1.", suffix = "jre8" }
210+
version = { exact = "1.1.2.jre8" }
211+
version = { contains = "feature" }
212+
```
213+
214+
## Ignore lines
215+
216+
Though `updates.ignores` offers granular configuration to exclude dependencies from update, Scala Steward also recognizes markers in file to ignore lines.
217+
218+
Dependencies in lines between `// scala-steward:off` and `// scala-steward:on` are not updated.
219+
220+
```scala
221+
libraryDependencies ++= Seq(
222+
// scala-steward:off
223+
"com.github.pathikrit" %% "better-files" % "3.8.0",
224+
"com.olegpy" %% "better-monadic-for" % "0.3.1",
225+
// scala-steward:on
226+
"org.typelevel" %% "cats-effect" % "1.3.1", // This and subsequent will get updated
227+
"org.typelevel" %% "cats-kernel-laws" % "1.6.1"
228+
)
229+
```
230+
231+
Also, the line ends with `// scala-steward:off` is not updated solely.
232+
233+
```scala
234+
libraryDependencies ++= Seq(
235+
"com.typesafe.akka" %% "akka-actor" % "2.4.0", // scala-steward:off
236+
"com.typesafe.akka" %% "akka-testkit" % "2.5.0", // This and subsequent will get updated
237+
)
238+
```

0 commit comments

Comments
 (0)