scala-steward icon indicating copy to clipboard operation
scala-steward copied to clipboard

A CLI command to validate repo configs

Open nikololiahim opened this issue 3 years ago • 11 comments

Attempt to solve #2638. Can be invoked like this (as a subcommand):

java -jar scala-steward-assembly-VERSION.jar validate-repo-config .scala-steward.conf

Sample input (with error): .scala-steward.conf:

updatePullRequests = 123

Output:

2022-07-12 11:17:08,589 ERROR Configuration file at /home/nikololiahim/scala/scala-steward/.scala-steward.conf contains errors:
  Decoding failed with:
    Got value '123' with wrong type, expecting string:
      updatePullRequests

nikololiahim avatar Jul 09 '22 14:07 nikololiahim

Now that I think of it, this doesn't solve the "actually valid config" problem described here. It still just runs the file through a circe parser, and doesn't perform any additional checks.

It also feels weird to make --validate-repo-config an option, it should rather be a subcommand (IMO).

nikololiahim avatar Jul 09 '22 17:07 nikololiahim

Codecov Report

Merging #2662 (5568b6f) into main (c17d367) will decrease coverage by 0.44%. The diff coverage is 70.00%.

@@            Coverage Diff             @@
##             main    #2662      +/-   ##
==========================================
- Coverage   81.32%   80.88%   -0.45%     
==========================================
  Files         146      147       +1     
  Lines        2592     2673      +81     
  Branches       43       49       +6     
==========================================
+ Hits         2108     2162      +54     
- Misses        484      511      +27     
Impacted Files Coverage Δ
...re/src/main/scala/org/scalasteward/core/Main.scala 0.00% <0.00%> (ø)
...ala/org/scalasteward/core/application/Config.scala 100.00% <ø> (ø)
...la/org/scalasteward/core/application/Context.scala 68.91% <21.42%> (-1.67%) :arrow_down:
.../scala/org/scalasteward/core/application/Cli.scala 100.00% <100.00%> (ø)
...teward/core/repoconfig/ValidateRepoConfigAlg.scala 100.00% <100.00%> (ø)
...a/org/scalasteward/core/coursier/CoursierAlg.scala 71.11% <0.00%> (-14.19%) :arrow_down:
.../org/scalasteward/core/buildtool/mill/parser.scala 66.66% <0.00%> (-1.52%) :arrow_down:
...ain/scala/org/scalasteward/core/data/Version.scala 100.00% <0.00%> (ø)
...in/scala/org/scalasteward/core/data/Resolver.scala 100.00% <0.00%> (ø)
...ala/org/scalasteward/core/nurture/NurtureAlg.scala 0.00% <0.00%> (ø)
... and 6 more

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

codecov[bot] avatar Jul 09 '22 18:07 codecov[bot]

In case you haven't seen it, a scala-cli version of this idea was proposed in https://github.com/typelevel/steward/pull/7#discussion_r903318794. Not sure if that's basically what you were doing here already.

armanbilge avatar Jul 09 '22 19:07 armanbilge

In case you haven't seen it, a scala-cli version of this idea was proposed in typelevel/steward#7 (comment). Not sure if that's basically what you were doing here already.

Yes, I have seen this comment, and this is basically what I am doing here. I'm just wondering if this solution is good enough (or even necessary at all).

nikololiahim avatar Jul 09 '22 19:07 nikololiahim

I'm just wondering if this solution is good enough (or even necessary at all).

Not entirely sure what you mean, but it's definitely necessary :) basically it helps validate two things:

  1. the config file is valid HOCON format (extraneous commas have messed us up multiple times)
  2. furthermore, it's consistent with the Steward config "schema"

Of course, this won't guarantee that it "works", but it's a huge improvement over the status quo.

See also: https://github.com/scala-steward-org/scala-steward/pull/2446.

armanbilge avatar Jul 09 '22 20:07 armanbilge

So I tried to use the --validate-repo-config as it was prior to https://github.com/scala-steward-org/scala-steward/pull/2662/commits/7be5f91fa90f2879ee1a023ee1f1e8e127b030df and it turns out there are several required flags which are not relevant to the config validation part. So, I decided that it would be better to make a separate validate-repo-config subcommand. It can now be invoked like this:

java -jar scala-steward-assembly-VERSION.jar validate-repo-config .scala-steward.conf

That being said, I had to touch a lot of things, which doesn't feel right. So if somethings seems in need of refactoring, don't hesitate to ping!

nikololiahim avatar Jul 10 '22 14:07 nikololiahim

I was editing a .scala-steward.conf a little earlier and missed this :) I hope a maintainer may be able to take a look soon, thanks!

armanbilge avatar Jul 31 '22 07:07 armanbilge

@armanbilge yeah, it's basically ready (at least functionality-wise), just needs a review

nikololiahim avatar Jul 31 '22 07:07 nikololiahim

@nikololiahim Thanks for your contribution. I've added change requests regarding the naming convention. Other parts look great to me.

exoego avatar Aug 11 '22 11:08 exoego

@exoego Thank you! Will fix the comments shortly.

nikololiahim avatar Aug 11 '22 11:08 nikololiahim

@exoego https://github.com/scala-steward-org/scala-steward/pull/2662/commits/5568b6f21d7be97a07eaac6c0e80f795372e034e addresses all the naming comments.

nikololiahim avatar Aug 12 '22 05:08 nikololiahim

Sorry for late review

exoego avatar Oct 20 '22 04:10 exoego

I am fine with a little coverage down and minor Codacy issues. https://app.codacy.com/gh/scala-steward-org/scala-steward/pullRequest?prid=9766981

exoego avatar Oct 20 '22 04:10 exoego