|
| 1 | +// run with `scala-cli run publish.sc` |
| 2 | + |
| 3 | +//> using scala 3.4 |
| 4 | +//> using toolkit default |
| 5 | + |
| 6 | +println("*** Publish the reqT-lang jar to github using sbt and gh ***\n") |
| 7 | + |
| 8 | +val wd = os.pwd |
| 9 | + |
| 10 | +def yes(msg: String): Boolean = |
| 11 | + scala.io.StdIn.readLine(msg).headOption.map(_.toUpper) == Some('Y') |
| 12 | + |
| 13 | +def getFromBuild(key: String): Option[String] = util.Try{ |
| 14 | + val lines = os.read(wd / "build.sbt").split("\n").toSeq |
| 15 | + val line: String = lines.filter(_.contains(s"val $key")).head |
| 16 | + val value: String = line.split("=").toSeq.last.trim.takeWhile(!_.isWhitespace) |
| 17 | + value.stripPrefix("\"").stripSuffix("\"") |
| 18 | + }.toOption |
| 19 | + |
| 20 | +extension (s: Seq[String]) def showSeq = s.mkString(" ") |
| 21 | + |
| 22 | +val scalaVer = getFromBuild("scalaVer").getOrElse("") |
| 23 | +val reqTLangVer = getFromBuild("reqTLangVer").getOrElse("") |
| 24 | + |
| 25 | +println("from build.sbt:") |
| 26 | +println(s"""val reqTLangVer = "$reqTLangVer"""") |
| 27 | +println(s"""val scalaVer = "$scalaVer"""") |
| 28 | + |
| 29 | +println(s"""\n*** Step 1: sbt "clean; package" """) |
| 30 | + |
| 31 | +if yes("Do you want a clean build (Y/n)? ") then |
| 32 | + os.proc("sbt", "clean;package").call(cwd = wd, stdout = os.Inherit) |
| 33 | + |
| 34 | + |
| 35 | +val dir = s"${os.pwd}/target/scala-$scalaVer" |
| 36 | +val jar = s"$dir/reqt-lang_3-$reqTLangVer.jar" |
| 37 | + |
| 38 | +if !os.exists(os.Path(jar)) then |
| 39 | + println(s"Error: Missing jar-file; $jar") |
| 40 | + System.exit(1) |
| 41 | +else |
| 42 | + println(s"\n*** Step 2: publish to github using gh") |
| 43 | + if reqTLangVer.isEmpty then |
| 44 | + println("val reqTLangVer not found in build.sbt") |
| 45 | + sys.exit(1) |
| 46 | + else |
| 47 | + val preRel = |
| 48 | + if reqTLangVer.contains("-M") || reqTLangVer.contains("_RC") then Seq("--prerelease") else Seq() |
| 49 | + val assemblyCmd = Seq() |
| 50 | + val createCmd = Seq("gh", "release", "create", reqTLangVer, "--generate-notes") ++ preRel |
| 51 | + |
| 52 | + val uploadCmd = Seq("gh", "release", "upload", reqTLangVer, jar) |
| 53 | + |
| 54 | + val ghOpt = util.Try{os.proc("which", "gh").call(cwd = wd)}.toOption |
| 55 | + |
| 56 | + if ghOpt == None then |
| 57 | + println("You need the github CLI 'gh' command on your path") |
| 58 | + println("Install from here: https://github.com/cli/cli/") |
| 59 | + |
| 60 | + println("\nRun these commands in terminal:\n") |
| 61 | + println(createCmd.showSeq) |
| 62 | + println(uploadCmd.showSeq) |
| 63 | + |
0 commit comments