Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check up to 5 nested project folders #2995

Merged
merged 3 commits into from
Mar 10, 2023

Conversation

mkurz
Copy link
Contributor

@mkurz mkurz commented Feb 28, 2023

Some projects set up plugins in project/project/plugins.sbt and even in project/project/project/plugins.sbt (I worked on such a private project, so I can't share details, but such things do exists 😉)

For example, Play and the sbt-web-build-base project put sbt-buildinfo in their project/project/plugins.sbt files:

However, as you can see, even though scala-steward is enabled and visiting those repos, that plugin never gets updated (latest release is 0.11.0, also see maven central)

Making scala-steward check and update those dependencies is actually pretty easy and straight forward:
We just need to set up the special scala-steward-StewardPlugin_<version>.scala plugin in the corresponding project/project/project/project/ and project/project/project/ folders so they are available as plugins for the parent "build" and then just enter those sub "build" projects via reloadPlugins again and also run stewardDependencies which also logs the dependencies of those projects.
Nothing special, just a couple of more lines logged and parsed by scala steward.
I also think the test that I adjusted in this pull request explains everything.

To make sure everything works 100% I set up following test repo:

As you can see it has three levels of project folders including plugins.sbt:

So I added outdated plugins to each plugins.sbt and the build.sbt and ran scala steward with this pull request applied locally and voilà, scala steward opened all expected pull requests:

BTW:
If you want to test out what the output of the sbt command ran by sbt looks like, you can check out the steward-plugin-file branch of my test repo and ran the sbt command I show in the README. It is exactly what scala steward runs to figure out the versions. (For this to stewardDependencies command to work I manually added the StewardPlugin_1_3_11.scala files myself, see the README again).

@codecov
Copy link

codecov bot commented Feb 28, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.04 🎉

Comparison is base (5357f28) 90.98% compared to head (ed1fae1) 91.02%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2995      +/-   ##
==========================================
+ Coverage   90.98%   91.02%   +0.04%     
==========================================
  Files         160      160              
  Lines        3305     3322      +17     
  Branches      297      303       +6     
==========================================
+ Hits         3007     3024      +17     
  Misses        298      298              
Impacted Files Coverage Δ
...a/org/scalasteward/core/buildtool/sbt/SbtAlg.scala 98.55% <100.00%> (+0.24%) ⬆️

... and 2 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@mkurz
Copy link
Contributor Author

mkurz commented Mar 1, 2023

Would be nice if this PR makes it into v0.23.0 😉

@mkurz
Copy link
Contributor Author

mkurz commented Mar 6, 2023

Hey! I am pretty sure this pull request is good to go, reviews would be highly appreciated. Thanks!

@fthomas
Copy link
Member

fthomas commented Mar 7, 2023

Thanks for the PR, @mkurz! I'm fine with updating dependencies in meta-meta-builds and even meta-meta-meta-builds but I think it would be better to check how many nested project directories there are before calling reload plugins; stewardDependencies thrice. My concern is that calling reload plugins can take a few seconds and we're slowing down Scala Steward unnecessarily for the majority of sbt projects.

I would check how many (nested) project directories there are and then only adding the StewardPlugin_*.scala to them if they exist. We would then only need to call reload plugins; stewardDependencies as much as needed.

@mkurz
Copy link
Contributor Author

mkurz commented Mar 7, 2023

I get it. Will update when I find time, thanks!

@mkurz
Copy link
Contributor Author

mkurz commented Mar 8, 2023

@fthomas Updated. It works exactly like you asked for, depending on the levels of meta builds. I tested that again on a real project: https://github.com/mkurz/three-level-sbt-plugins-project/pulls (I deleted the repo and recreated it so it was fresh again). As you can see a pull request for each meta build was created. After one run I even created one more level with the scalafmt plugin and on the second run scala-steward also created the according pull request (you can see that the sbt-scalafmt pull request was opened 4 minutes later).

@mkurz mkurz changed the title Update up to 3 levels of plugins (project/project[/project/]plugins.sbt) Check all nested project folders Mar 8, 2023
.iterate(buildRootDir / project)(_ / project)
.takeWhile(p => p.exists && p.isDirectory)
.size,
1 // There is always at least one meta build, even if there is no project folder
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if we should drop this Math.max call. If there is no project folder, there aren't any *.sbt files either which could contain dependencies (plugins) that Scala Steward could update. And if there is nothing to update, why loading the meta-build and calling stewardDependencies? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory yes. However removing Math.max will break many many tests because of lines like

Cmd("write", s"$repoDir/project/project/scala-steward-StewardPlugin_1_3_11.scala"),

Cmd("rm", "-rf", s"$repoDir/project/project/scala-steward-StewardPlugin_1_3_11.scala"),

which assume scala-steward always checks/updates the project folder. And I would keep all those tests how they are currently.
Also in real life I never saw a sbt project without a project folder (sbt even creates the project folder when running in an empty folder).

I would just keep it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And I would keep all those tests how they are currently.

We can keep them if we use FileAlg#isDirectory for checking the project folders as I've done in 1a97fc5. Another benefit of using FileAlg is that the tests are now sensitive to the actual number of project folders.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! Thanks!

@fthomas
Copy link
Member

fthomas commented Mar 9, 2023

Updated.

Thanks @mkurz!

This allows to remove the `Math.max(..., 1)` call since our tests
actually count the `project` directories that are present in
`MockState`.
@mkurz
Copy link
Contributor Author

mkurz commented Mar 9, 2023

LGTM 👍

@mkurz mkurz changed the title Check all nested project folders Check up to 5 nested project folders Mar 9, 2023
@mkurz
Copy link
Contributor Author

mkurz commented Mar 9, 2023

Tested again with a real world repo, everything works great: https://github.com/mkurz/three-level-sbt-plugins-project/pulls

@fthomas
Copy link
Member

fthomas commented Mar 9, 2023

Awesome, thanks for testing again!

@fthomas fthomas added this to the 0.23.0 milestone Mar 10, 2023
@fthomas fthomas added the enhancement New feature or request label Mar 10, 2023
@fthomas fthomas merged commit c322669 into scala-steward-org:main Mar 10, 2023
@mkurz mkurz deleted the check_3-level-plugins branch March 10, 2023 06:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants