File tree Expand file tree Collapse file tree 3 files changed +62
-1
lines changed
Expand file tree Collapse file tree 3 files changed +62
-1
lines changed Original file line number Diff line number Diff line change 6969 - name : Commit new version support
7070 run : |
7171 gpg --list-keys
72- echo " ${{inputs.scala_version}}" >> scala-versions
72+ sbt "addVersion ${{inputs.scala_version}}"
7373 sbt "generateAll;++${{inputs.scala_version}} test"
7474 git add --all
7575 git commit -m "Add ${{inputs.scala_version}} support"
Original file line number Diff line number Diff line change @@ -99,3 +99,4 @@ val betterToString =
9999 .aggregate(plugin, tests)
100100 .enablePlugins(NoPublishPlugin )
101101 .enablePlugins(ReadmePlugin )
102+ .enablePlugins(AddVersionPlugin )
Original file line number Diff line number Diff line change 1+ import sbt .AutoPlugin
2+
3+ import sbt .Def
4+ import sbt ._
5+
6+ object AddVersionPlugin extends AutoPlugin {
7+
8+ val addVersion = inputKey[Unit ](" Write the given version to scala-versions" )
9+
10+ case class ParsedVersion (mainPart : String , rcPart : Option [String ]) {
11+
12+ def render : String =
13+ rcPart match {
14+ case Some (rc) => s " $mainPart- $rc"
15+ case None => mainPart
16+ }
17+
18+ }
19+
20+ object ParsedVersion {
21+
22+ // if mainPart is the same, RCs go first
23+ implicit val ordering : Ordering [ParsedVersion ] = Ordering .by { v =>
24+ (
25+ v.mainPart,
26+ v.rcPart match {
27+ case Some (rc) => s " 0 $rc" // prepend 0 to RCs to sort them before non-RCs
28+ case None => " 1" // non-RCs come after RCs
29+ }
30+ )
31+ }
32+
33+ def parse (version : String ): ParsedVersion = {
34+ val parts = version.split(" -" )
35+ val mainPart = parts.head
36+ val rcPart = if (parts.length > 1 ) Some (parts(1 )) else None
37+ ParsedVersion (mainPart, rcPart)
38+ }
39+
40+ }
41+
42+ override def projectSettings : Seq [Def .Setting [_]] = Seq (
43+ addVersion := {
44+ // Read the version from the input
45+ val version = Def .spaceDelimited(" <version>" ).parsed.mkString(" " )
46+
47+ val path = file(" scala-versions" )
48+ val currentVersions = IO
49+ .read(path)
50+ .split(" \n " )
51+ .map(_.trim)
52+ .filterNot(_.isEmpty)
53+ .toSet
54+
55+ val newVersions = (currentVersions + version).toSeq.map(ParsedVersion .parse).sorted.map(_.render)
56+ IO .write(path, newVersions.mkString(" \n " ) + " \n " )
57+ }
58+ )
59+
60+ }
You can’t perform that action at this time.
0 commit comments