Skip to content

Commit

Permalink
modernize build and code
Browse files Browse the repository at this point in the history
  • Loading branch information
SethTisue committed Feb 7, 2022
1 parent 4b4a354 commit c42175d
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 26 deletions.
1 change: 1 addition & 0 deletions .jvmopts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-Dfile.encoding=UTF-8
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ but perhaps shows off a few standard library APIs.
## Building

1. Update the highlights notes in `hand-written.md`.
2. run `sbt -Dfile.encoding=UTF-8`, and then:
2. run `sbt`, and then:
```
> runMain MakeReleaseNotes $PrevVersion $CurrentVersion $ReleaseYear/$ReleaseMonth/$ReleaseDay "$pathToScalaScalaCheckout"
```

## Contributing

Feel free to improve. Make sure to sign the Scala CLA.
Feel free to improve. Make sure to sign the Scala CLA.
19 changes: 8 additions & 11 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
name := "make-release-notes"

scalaVersion := "2.13.8"

scalacOptions ++= Seq("-feature", "-deprecation", "-Xfatal-warnings")

libraryDependencies += "org.pegdown" % "pegdown" % "1.6.0"
libraryDependencies += "org.apache.commons" % "commons-text" % "1.9"
libraryDependencies += "org.scala-lang.modules" %% "scala-xml" % "2.0.1"

{
require(sys.props("file.encoding") == "UTF-8", "Please rerun with -Dfile.encoding=UTF-8")
Nil
}
scalacOptions ++= Seq("-feature", "-deprecation", "-Werror")

libraryDependencies ++= Seq(
"org.pegdown" % "pegdown" % "1.6.0",
"org.apache.commons" % "commons-text" % "1.9",
"org.scala-lang.modules" %% "scala-xml" % "2.0.1",
"org.scala-lang.modules" %% "scala-parallel-collections" % "1.0.3",
)
7 changes: 7 additions & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
locally {
require(sys.props("file.encoding") == "UTF-8",
"Please rerun with -Dfile.encoding=UTF-8")
Nil
}

scalacOptions ++= Seq("-feature", "-deprecation", "-Xfatal-warnings")
15 changes: 9 additions & 6 deletions src/main/scala/GitInfo.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import scala.collection.parallel.CollectionConverters._ // for .par

case class Commit(sha: String, author: String, header: String, body: String) {
def trimmedHeader = header.take(80)
Expand All @@ -9,11 +10,11 @@ object GitHelper {
def processGitCommits(gitDir: java.io.File, previousTag: String, currentTag: String): IndexedSeq[Commit] = {
import sys.process._
val gitFormat = "%h %s" // sha and subject
val log = Process(Seq("git", "--no-pager", "log", s"${previousTag}..${currentTag}", "--format=format:" + gitFormat, "--no-merges", "--topo-order"), gitDir).lineStream
val log = Process(Seq("git", "--no-pager", "log", s"${previousTag}..${currentTag}", "--format=format:" + gitFormat, "--no-merges", "--topo-order"), gitDir).lazyLines

log.par.map(_.split(" ", 2)).collect {
case Array(sha, title) =>
val (author :: body) = Process(Seq("git", "--no-pager", "show", sha, "--format=format:%aN%n%b", "--quiet"), gitDir).lineStream.toList
val (author :: body) = Process(Seq("git", "--no-pager", "show", sha, "--format=format:%aN%n%b", "--quiet"), gitDir).lazyLines.toList
Commit(sha, author, title, body.mkString("\n"))
}.toVector
}
Expand Down Expand Up @@ -41,10 +42,12 @@ class GitInfo(gitDir: java.io.File, val previousTag: String, val currentTag: Str
import GitHelper._
val commits = processGitCommits(gitDir, previousTag, currentTag)

val authors: Seq[(String, Int)] = {
val grouped: Vector[(String, Int)] = (commits groupBy (_.author)).map { case (a, c) => a -> c.length } { collection.breakOut }
(grouped sortBy (_._2)).reverse
}
val authors: Seq[(String, Int)] =
commits
.groupBy(_.author)
.map{case (a, c) => a -> c.length}
.toVector
.sortBy(_._2)

val fixCommits =
for {
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/IO.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import java.io.File

object IO {
def write(f: java.io.File, contents: String) {
val buf = new java.io.BufferedWriter(new java.io.FileWriter(f))
def write(f: java.io.File, contents: String): Unit = {
val buf = new java.io.BufferedWriter(new java.io.FileWriter(f))
try buf.write(contents)
finally buf.close()
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/MakeDownloadPage.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class MakeDownloadPage(version: String, releaseDate: Date = new Date()) {
import scala.sys.process._
println("## fetching size of "+ url)
scala.util.Try {
val responseHeader = Process(s"curl -m 5 --silent -D - -X HEAD $url").lineStream
val responseHeader = Process(s"curl -m 5 --silent -D - -X HEAD $url").lazyLines
val contentLength = responseHeader.map(_.toLowerCase).find(_.startsWith("content-length"))
val bytes = contentLength.map(_.split(":",2)(1).trim.toInt)
bytes map (b => (responseHeader.head, b))
Expand Down
9 changes: 5 additions & 4 deletions src/main/scala/MakeReleaseNotes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ object MakeReleaseNotes {
}
}

def apply(scalaDir: String, version: String, previousTag: String, currentTag: String, releaseDate: Date) {
Seq(Html, MarkDown).foreach(fmt => apply(new java.io.File(scalaDir), version, previousTag, currentTag, fmt, releaseDate))
}
def apply(scalaDir: String, version: String, previousTag: String, currentTag: String, releaseDate: Date): Unit =
Seq(Html, MarkDown).foreach(fmt =>
apply(new java.io.File(scalaDir), version, previousTag, currentTag, fmt, releaseDate))

def apply(scalaDir: java.io.File, version: String, previousTag: String, currentTag: String, targetLanguage: TargetLanguage = MarkDown, releaseDate: Date = new Date()): Unit = {
val out = targetLanguage match {
case Html => new java.io.File("release-notes.html")
Expand Down Expand Up @@ -75,7 +76,7 @@ object MakeReleaseNotes {
def rawHandWrittenNotes(file: java.io.File = new java.io.File(s"hand-written.md")): String = {
val lines: List[String] = if (file.exists) {
val src = Source.fromFile(file)
src.getLines.toList
src.getLines().toList
} else Nil
// if you don't have the next line, sub-bullets would be screwed!
// please take this case into account and comment out 2 next lines and uncomment the line after!
Expand Down

0 comments on commit c42175d

Please sign in to comment.