-
Notifications
You must be signed in to change notification settings - Fork 44
/
release.sc
124 lines (106 loc) · 3.8 KB
/
release.sc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import $ivy.`com.lihaoyi:ammonite-ops_2.13:2.4.1`
import ammonite.ops._
import scala.util.Try
case class DemoRepo(repo: String, name: String)(implicit path: os.Path) {
def update(): Unit = {
%.git("checkout", "master")
%.git("fetch")
%.git("reset", "--hard", "origin/master")
// pick up changes from `update` branch if any
Try(%.git("merge", "origin/update"))
}
def build(version: String): Unit = {
val pluginsFile = path / "project" / "plugins.sbt"
val newLines = os.read.lines(pluginsFile).flatMap {
case line if line.contains(s"""addSbtPlugin("org.scala-js" % "sbt-scalajs" %""") =>
Some(s"""addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.13.1")""")
case line if line.contains(s"""addSbtPlugin("ch.epfl.scala" % "sbt-scalajs-bundler" %""") =>
Some(s"""addSbtPlugin("ch.epfl.scala" % "sbt-scalajs-bundler" % "0.21.1")""")
case line if line.contains(s"""addSbtPlugin("org.scalablytyped.converter" % "sbt-converter" %""") =>
Some(s"""addSbtPlugin("org.scalablytyped.converter" % "sbt-converter" % "$version")""")
case line if line.contains("resolvers +=") =>
None
case line => Some(line)
}
os.write.over(path / "project" / "build.properties", "sbt.version=1.9.0")
os.write.over(pluginsFile, newLines.mkString("\n"))
%.sbt("compile", "dist")
%.git("add", "-A")
%.git("commit", "-m", s"Bump to $version")
}
def pushCache(): Unit =
%.sbt("stPublishCache")
def pushGit(): Unit =
%.git("push", "origin", "HEAD")
}
object DemoRepo {
val repos = List("Demos", "ScalaJsReactDemos", "SlinkyDemos")
def initialized(in: os.Path): List[DemoRepo] = {
os.makeDir.all(in)
repos.map { name =>
val repo = s"[email protected]:ScalablyTyped/$name.git"
val repoPath = in / name
if (!os.exists(repoPath)) {
%.git("clone", repo)(in)
}
DemoRepo(repo, name)(repoPath)
}
}
}
case class Repo(version: String)(implicit val wd: os.Path) {
val tag = s"v$version"
def assertClean() =
%%.git("status", "--porcelain").out.string match {
case "" => ()
case nonEmpty => sys.error(s"Expected clean directory, git changes:\n$nonEmpty")
}
def refreshTag() = {
Try(%%.git("tag", "-d", tag))
%.git("tag", tag)
}
def cleanLocal() = {
val existing = os.walk(os.home / ".ivy2" / "local" / "org.scalablytyped.converter").filter(_.last == version)
if (existing.nonEmpty) {
println(s"Cleaning existing locally published")
existing.foreach(println)
existing.foreach(folder => os.remove.all(folder))
}
}
def publishLocalScripted() =
%("sbt", "clean", "publishLocal", "test", "scripted")
def publish() = {
%("sbt", "ci-release", "docs/mdoc")
%("yarn")(wd / "website")
%("yarn", "publish-gh-pages")(wd / "website")
%.git("push", "origin", "HEAD")
%.git("push", "origin", tag)
}
}
def mustHave(name: String) =
sys.env.getOrElse(name, sys.error(s"Set env $name"))
@main
def doRelease(version: String): Int = {
mustHave("PGP_PASSPHRASE")
mustHave("PGP_SECRET")
mustHave("SONATYPE_PASSWORD")
mustHave("SONATYPE_USERNAME")
mustHave("CI_COMMIT_TAG") // just set to true
val repo = Repo(version)(os.pwd)
repo.assertClean()
repo.refreshTag()
repo.cleanLocal()
repo.publishLocalScripted()
val demoRepos = DemoRepo.initialized(os.Path("/tmp/st-release-temp"))
demoRepos.foreach(_.update())
demoRepos.foreach(_.build(version))
demoRepos.foreach(_.pushCache())
// at this point we're ready to push everything
repo.assertClean()
repo.publish()
// wait for libraries to be accessible through maven central
println("Sleeping two hours before pushing demos, in order for ST to propagate through maven central")
val Hour = 60 * 60 * 1000
Thread.sleep(2 * Hour)
demoRepos.foreach(_.pushGit())
0
}