Skip to content

Commit

Permalink
Merge branch 'main' into wip/bsp
Browse files Browse the repository at this point in the history
  • Loading branch information
fthomas committed Dec 11, 2023
2 parents 1aaf1c3 + ff6dce9 commit 7e30a9b
Show file tree
Hide file tree
Showing 16 changed files with 215 additions and 52 deletions.
2 changes: 0 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,6 @@ lazy val commonSettings = Def.settings(

lazy val compileSettings = Def.settings(
scalaVersion := Scala213,
// Uncomment for local development:
// scalacOptions -= "-Xfatal-warnings",
doctestTestFramework := DoctestTestFramework.Munit
)

Expand Down
13 changes: 11 additions & 2 deletions docs/artifact-migrations.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,22 @@

Scala Steward can not only bump versions but also change groupId and/or artifactIds if they have been renamed.

An example pull request that demonstrates this feature is https://github.com/scala-steward-org/scala-steward/pull/2264/files which not only bumped the version but also changed the groupId.
Here is a pull request that demonstrate this feature:

* https://github.com/scala-steward-org/scala-steward/pull/2264/files

More pull requests where Scala Steward applied artifact migrations can be found here:

* [Created pull requests](https://github.com/search?q=author%3Ascala-steward+is%3Apr+artifact-migrations&type=pullrequests)
([compact]( https://github.com/pulls?q=author%3Ascala-steward+is%3Apr+artifact-migrations))
* [Merged pull requests]( https://github.com/search?q=author%3Ascala-steward+is%3Amerged+sort%3Aupdated-desc+artifact-migrations&type=pullrequests)
([compact]( https://github.com/pulls?q=author%3Ascala-steward+is%3Amerged+sort%3Aupdated-desc+artifact-migrations))

## How does this work?

Scala Steward contains a list of [artifact migrations][migrations] that maps old groupIds and/or artifactIds to their new values.
When an artifact migration for a dependency exists, Scala Steward will look for new versions with the old **and** new groupIds and artifactIds.
If it finds a suitable newer version with the new groupId/artifactId, it will consider it an update of that dependency and change the artifactId/groupId accordingly.
If it finds a suitable newer version with the new groupId/artifactId, it will consider it an update of that dependency and change the groupId/artifactId accordingly.

## Adding artifact migrations to Scala Steward

Expand Down
10 changes: 5 additions & 5 deletions docs/help.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ All command line arguments for the `scala-steward` application.
```
Usage:
scala-steward validate-repo-config
scala-steward --workspace <file> --repos-file <file> [--git-author-name <string>] --git-author-email <string> [--git-author-signing-key <string>] --git-ask-pass <file> [--sign-commits] [--forge-type <forge-type>] [--forge-api-host <uri>] --forge-login <string> [--do-not-fork] [--add-labels] [--ignore-opts-files] [--env-var <name=value>]... [--process-timeout <duration>] [--whitelist <string>]... [--read-only <string>]... [--enable-sandbox | --disable-sandbox] [--max-buffer-size <integer>] [--repo-config <uri>]... [--disable-default-repo-config] [--scalafix-migrations <uri>]... [--disable-default-scalafix-migrations] [--artifact-migrations <uri>]... [--disable-default-artifact-migrations] [--cache-ttl <duration>] [--bitbucket-use-default-reviewers] [--bitbucket-server-use-default-reviewers] [--gitlab-merge-when-pipeline-succeeds] [--gitlab-required-reviewers <integer>] [--gitlab-remove-source-branch] [--azure-repos-organization <string>] [--github-app-id <integer> --github-app-key-file <file>] [--url-checker-test-url <uri>]... [--default-maven-repo <string>] [--refresh-backoff-period <duration>]
scala-steward --workspace <file> --repos-file <uri> [--repos-file <uri>]... [--git-author-name <string>] --git-author-email <string> [--git-author-signing-key <string>] --git-ask-pass <file> [--sign-commits] [--forge-type <forge-type>] [--forge-api-host <uri>] --forge-login <string> [--do-not-fork] [--add-labels] [--ignore-opts-files] [--env-var <name=value>]... [--process-timeout <duration>] [--whitelist <string>]... [--read-only <string>]... [--enable-sandbox | --disable-sandbox] [--max-buffer-size <integer>] [--repo-config <uri>]... [--disable-default-repo-config] [--scalafix-migrations <uri>]... [--disable-default-scalafix-migrations] [--artifact-migrations <uri>]... [--disable-default-artifact-migrations] [--cache-ttl <duration>] [--bitbucket-use-default-reviewers] [--bitbucket-server-use-default-reviewers] [--gitlab-merge-when-pipeline-succeeds] [--gitlab-required-reviewers <integer>] [--gitlab-remove-source-branch] [--azure-repos-organization <string>] [--github-app-id <integer> --github-app-key-file <file>] [--url-checker-test-url <uri>]... [--default-maven-repo <string>] [--refresh-backoff-period <duration>]
Expand All @@ -14,8 +14,8 @@ Options and flags:
Display this help text.
--workspace <file>
Location for cache and temporary files
--repos-file <file>
A markdown formatted file with a repository list
--repos-file <uri>
A markdown formatted file with a repository list (can be used multiple times)
--git-author-name <string>
Git "user.name"; default: Scala Steward
--git-author-email <string>
Expand Down Expand Up @@ -63,9 +63,9 @@ Options and flags:
--disable-default-repo-config
Whether to disable the default repo config file
--scalafix-migrations <uri>
Additional scalafix migrations configuration file (can be used multiple times)
Additional Scalafix migrations configuration file (can be used multiple times)
--disable-default-scalafix-migrations
Whether to disable the default scalafix migration file; default: false
Whether to disable the default Scalafix migration file; default: false
--artifact-migrations <uri>
Additional artifact migration configuration file (can be used multiple times)
--disable-default-artifact-migrations
Expand Down
9 changes: 4 additions & 5 deletions docs/scalafix-migrations.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ would not compile with the new version of the dependency.

Here are two pull requests that demonstrate this feature:

* https://github.com/coursier/versions/pull/25
* https://github.com/barambani/http4s-extend/pull/67/files
* https://github.com/fthomas/scalafix-test/pull/6/files

And here are all pull requests where Scala Steward applied Scalafix
migrations:
More pull requests where Scala Steward applied Scalafix migrations can be found here:

* [Created pull requests](https://github.com/search?q=author%3Ascala-steward+is%3Apr+scalafix-migrations)
* [Created pull requests](https://github.com/search?q=author%3Ascala-steward+is%3Apr+scalafix-migrations&type=pullrequests)
([compact]( https://github.com/pulls?q=author%3Ascala-steward+is%3Apr+scalafix-migrations))
* [Merged pull requests]( https://github.com/search?q=author%3Ascala-steward+is%3Amerged+sort%3Aupdated-desc+scalafix-migrations)
* [Merged pull requests]( https://github.com/search?q=author%3Ascala-steward+is%3Amerged+sort%3Aupdated-desc+scalafix-migrations&type=pullrequests)
([compact]( https://github.com/pulls?q=author%3Ascala-steward+is%3Amerged+sort%3Aupdated-desc+scalafix-migrations))

## How does this work?
Expand Down
75 changes: 75 additions & 0 deletions modules/core/src/main/resources/artifact-migrations.v2.conf
Original file line number Diff line number Diff line change
Expand Up @@ -999,4 +999,79 @@ changes = [
groupIdAfter = io.github.play-swagger
artifactIdAfter = sbt-play-swagger
},
{
groupIdBefore = com.mohiva
groupIdAfter = org.playframework.silhouette
artifactIdAfter = play-silhouette-cas
},
{
groupIdBefore = com.mohiva
groupIdAfter = org.playframework.silhouette
artifactIdAfter =play-silhouette-crypto-jca
},
{
groupIdBefore = com.mohiva
groupIdAfter = org.playframework.silhouette
artifactIdAfter = play-silhouette-password-bcrypt
},
{
groupIdBefore = com.mohiva
groupIdAfter = org.playframework.silhouette
artifactIdAfter = play-silhouette-persistence
},
{
groupIdBefore = com.mohiva
groupIdAfter = org.playframework.silhouette
artifactIdAfter = play-silhouette-testkit
},
{
groupIdBefore = com.mohiva
groupIdAfter = org.playframework.silhouette
artifactIdAfter = play-silhouette-totp
},
{
groupIdBefore = com.mohiva
groupIdAfter = org.playframework.silhouette
artifactIdAfter = play-silhouette
},
{
groupIdBefore = io.github.honeycomb-cheesecake
groupIdAfter = org.playframework.silhouette
artifactIdAfter = play-silhouette-cas
},
{
groupIdBefore = io.github.honeycomb-cheesecake
groupIdAfter = org.playframework.silhouette
artifactIdAfter =play-silhouette-crypto-jca
},
{
groupIdBefore = io.github.honeycomb-cheesecake
groupIdAfter = org.playframework.silhouette
artifactIdAfter = play-silhouette-password-argon2
},
{
groupIdBefore = io.github.honeycomb-cheesecake
groupIdAfter = org.playframework.silhouette
artifactIdAfter = play-silhouette-password-bcrypt
},
{
groupIdBefore = io.github.honeycomb-cheesecake
groupIdAfter = org.playframework.silhouette
artifactIdAfter = play-silhouette-persistence
},
{
groupIdBefore = io.github.honeycomb-cheesecake
groupIdAfter = org.playframework.silhouette
artifactIdAfter = play-silhouette-testkit
},
{
groupIdBefore = io.github.honeycomb-cheesecake
groupIdAfter = org.playframework.silhouette
artifactIdAfter = play-silhouette-totp
},
{
groupIdBefore = io.github.honeycomb-cheesecake
groupIdAfter = org.playframework.silhouette
artifactIdAfter = play-silhouette
},
]
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ object Cli {
private val workspace: Opts[File] =
option[File]("workspace", "Location for cache and temporary files")

private val reposFile: Opts[File] =
option[File]("repos-file", "A markdown formatted file with a repository list")
private val reposFiles: Opts[Nel[Uri]] =
options[Uri]("repos-file", s"A markdown formatted file with a repository list $multiple")

private val gitAuthorName: Opts[String] = {
val default = "Scala Steward"
Expand Down Expand Up @@ -217,13 +217,13 @@ object Cli {
private val scalafixMigrations: Opts[List[Uri]] =
options[Uri](
"scalafix-migrations",
s"Additional scalafix migrations configuration file $multiple"
s"Additional Scalafix migrations configuration file $multiple"
).orEmpty

private val disableDefaultScalafixMigrations: Opts[Boolean] =
flag(
"disable-default-scalafix-migrations",
"Whether to disable the default scalafix migration file; default: false"
"Whether to disable the default Scalafix migration file; default: false"
).orFalse

private val scalafixCfg: Opts[ScalafixCfg] =
Expand Down Expand Up @@ -348,7 +348,7 @@ object Cli {

private val configOpts: Opts[Config] = (
workspace,
reposFile,
reposFiles,
gitCfg,
forgeCfg,
ignoreOptsFiles,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import scala.concurrent.duration.FiniteDuration
*/
final case class Config(
workspace: File,
reposFile: File,
reposFiles: Nel[Uri],
gitCfg: GitCfg,
forgeCfg: ForgeCfg,
ignoreOptsFiles: Boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ final class Context[F[_]](implicit
val refreshErrorAlg: RefreshErrorAlg[F],
val repoCacheAlg: RepoCacheAlg[F],
val repoConfigAlg: RepoConfigAlg[F],
val reposFilesLoader: ReposFilesLoader[F],
val sbtAlg: SbtAlg[F],
val scalaCliAlg: ScalaCliAlg[F],
val scalafixMigrationsFinder: ScalafixMigrationsFinder,
Expand Down Expand Up @@ -240,6 +241,7 @@ object Context {
implicit val editAlg: EditAlg[F] = new EditAlg[F]
implicit val nurtureAlg: NurtureAlg[F] = new NurtureAlg[F](config.forgeCfg)
implicit val pruningAlg: PruningAlg[F] = new PruningAlg[F]
implicit val reposFilesLoader: ReposFilesLoader[F] = new ReposFilesLoader[F]()
implicit val gitHubAppApiAlg: GitHubAppApiAlg[F] =
new GitHubAppApiAlg[F](config.forgeCfg.apiHost)
implicit val stewardAlg: StewardAlg[F] = new StewardAlg[F](config)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright 2018-2023 Scala Steward contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.scalasteward.core.application

import cats.effect.Sync
import cats.syntax.all._
import fs2.Stream
import org.http4s.Uri
import org.scalasteward.core.data.Repo
import org.scalasteward.core.io.FileAlg
import org.scalasteward.core.util.Nel
import org.typelevel.log4cats.Logger

final class ReposFilesLoader[F[_]](implicit
fileAlg: FileAlg[F],
logger: Logger[F],
F: Sync[F]
) {
def loadAll(reposFiles: Nel[Uri]): Stream[F, Repo] =
Stream.emits(reposFiles.toList).evalMap(loadRepos).flatMap(Stream.emits)

private def loadRepos(reposFile: Uri): F[List[Repo]] =
for {
_ <- logger.debug(s"Loading repos from $reposFile")
content <- fileAlg.readUri(reposFile)
repos <- Stream.fromIterator(content.linesIterator, 4096).mapFilter(Repo.parse).compile.toList
_ <-
if (repos.nonEmpty) F.unit
else {
val msg = s"No repos found in ${reposFile.renderString}. " +
s"Check the formatting of that file. " +
s"""The format is "- $$owner/$$repo" or "- $$owner/$$repo:$$branch"."""
logger.warn(msg)
}
} yield repos
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package org.scalasteward.core.application

import better.files.File
import cats.effect.{ExitCode, Sync}
import cats.syntax.all._
import fs2.Stream
Expand All @@ -43,16 +42,11 @@ final class StewardAlg[F[_]](config: Config)(implicit
nurtureAlg: NurtureAlg[F],
pruningAlg: PruningAlg[F],
repoCacheAlg: RepoCacheAlg[F],
reposFilesLoader: ReposFilesLoader[F],
selfCheckAlg: SelfCheckAlg[F],
workspaceAlg: WorkspaceAlg[F],
F: Sync[F]
) {
private def readRepos(reposFile: File): Stream[F, Repo] =
Stream
.eval(fileAlg.readFile(reposFile).map(_.getOrElse("")))
.flatMap(content => Stream.fromIterator(content.linesIterator, 1024))
.mapFilter(Repo.parse)

private def getGitHubAppRepos(githubApp: GitHubApp): Stream[F, Repo] =
Stream.evals[F, List, Repo] {
for {
Expand Down Expand Up @@ -95,22 +89,16 @@ final class StewardAlg[F[_]](config: Config)(implicit
_ <- workspaceAlg.removeAnyRunSpecificFiles
exitCode <-
(config.githubApp.map(getGitHubAppRepos).getOrElse(Stream.empty) ++
readRepos(config.reposFile))
reposFilesLoader.loadAll(config.reposFiles))
.evalMap(repo => steward(repo).map(_.bimap(repo -> _, _ => repo)))
.compile
.toList
.flatMap {
case Nil =>
val msg = "No repos specified. " +
s"Check the formatting of ${config.reposFile.pathAsString}. " +
s"""The format is "- $$owner/$$repo" or "- $$owner/$$repo:$$branch"."""
logger.warn(msg).as(ExitCode.Success)
case results =>
val runResults = RunResults(results)
for {
summaryFile <- workspaceAlg.runSummaryFile
_ <- fileAlg.writeFile(summaryFile, runResults.markdownSummary)
} yield runResults.exitCode
.flatMap { results =>
val runResults = RunResults(results)
for {
summaryFile <- workspaceAlg.runSummaryFile
_ <- fileAlg.writeFile(summaryFile, runResults.markdownSummary)
} yield runResults.exitCode
}
} yield exitCode
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import org.scalasteward.core.application.Cli.ParseResult._
import org.scalasteward.core.application.Config.StewardUsage
import org.scalasteward.core.forge.ForgeType
import org.scalasteward.core.forge.github.GitHubApp
import org.scalasteward.core.util.Nel
import scala.concurrent.duration._

class CliTest extends FunSuite {
Expand Down Expand Up @@ -38,7 +39,7 @@ class CliTest extends FunSuite {
)

assertEquals(obtained.workspace, File("a"))
assertEquals(obtained.reposFile, File("b"))
assertEquals(obtained.reposFiles, Nel.one(uri"b"))
assertEquals(obtained.gitCfg.gitAuthor.email, "d")
assertEquals(obtained.gitCfg.gitAskPass, File("f"))
assertEquals(obtained.forgeCfg.tpe, ForgeType.GitLab)
Expand Down Expand Up @@ -84,7 +85,7 @@ class CliTest extends FunSuite {

assert(!obtained.processCfg.sandboxCfg.enableSandbox)
assertEquals(obtained.workspace, File("a"))
assertEquals(obtained.reposFile, File("b"))
assertEquals(obtained.reposFiles, Nel.one(uri"b"))
assertEquals(obtained.gitCfg.gitAuthor.email, "d")
assertEquals(obtained.gitCfg.gitAskPass, File("f"))
assertEquals(obtained.forgeCfg.login, "e")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.scalasteward.core.application

import munit.CatsEffectSuite
import org.scalasteward.core.data.Repo
import org.scalasteward.core.git.Branch
import org.scalasteward.core.mock.MockContext.context.reposFilesLoader
import org.scalasteward.core.mock.{MockConfig, MockState}
import org.scalasteward.core.util.Nel

class ReposFilesLoaderTest extends CatsEffectSuite {
test("non-empty repos file") {
val initialState = MockState.empty.addUris(MockConfig.reposFile -> "- a/b\n- c/d:e")
val obtained =
reposFilesLoader.loadAll(Nel.one(MockConfig.reposFile)).compile.toList.runA(initialState)
assertIO(obtained, List(Repo("a", "b"), Repo("c", "d", Some(Branch("e")))))
}

test("malformed repos file") {
val initialState = MockState.empty.addUris(MockConfig.reposFile -> " - a/b")
val obtained =
reposFilesLoader.loadAll(Nel.one(MockConfig.reposFile)).compile.toList.runA(initialState)
assertIO(obtained, List.empty)
}

test("non-existing repos file") {
val initialState = MockState.empty
val obtained =
reposFilesLoader.loadAll(Nel.one(MockConfig.reposFile)).compile.toList.runA(initialState)
assertIO(obtained.attempt.map(_.isLeft), true)
}
}
Loading

0 comments on commit 7e30a9b

Please sign in to comment.