Skip to content

Commit a1fd26b

Browse files
authored
More release job fixes (#26)
* More fixes for the release jobs
1 parent 574082a commit a1fd26b

14 files changed

+331
-427
lines changed

.github/ci_scripts/currentVersion.scala

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,19 @@ def extractVersion(buildContent: String): Option[SemVer] =
1111
SemVer(major.toInt, minor.toInt, patch.toInt)
1212
}
1313

14-
def currentVersion(buildFile: String, cwd: os.Path, console: Console): Unit =
14+
/** Return the current version number from the build file
15+
*
16+
* @param buildFile
17+
* Path to build.sbt
18+
*/
19+
@main def currentVersion(buildFile: String): Unit =
1520

16-
val buildPath = os.Path(buildFile, cwd)
21+
val buildPath = os.Path(buildFile, os.pwd)
1722
require(os.exists(buildPath), s"$buildPath file wasn't found")
1823

1924
val content = os.read(buildPath)
2025
extractVersion(content) match
2126
case Some(semVer) =>
22-
console.println(semVer.asString)
27+
println(semVer.asString)
2328
case None =>
2429
throw new Exception(s"Didn't find version in build file: $content")
25-
26-
/** Return the current version number from the build file
27-
*
28-
* @param buildFile
29-
* Path to build.sbt
30-
*/
31-
@main def currentVersion(buildFile: String): Unit =
32-
runWith(currentVersion(buildFile, _, _))

.github/ci_scripts/project.scala

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -70,35 +70,3 @@ def sed(
7070

7171
if didReplace then Some(lines.mkString("\n")) else None
7272

73-
trait Console:
74-
def print(s: String): Unit
75-
def println(s: String): Unit
76-
def error(s: String): Unit
77-
def errorln(s: String): Unit
78-
79-
def outLines: List[String]
80-
def errLines: List[String]
81-
82-
def printOuts: Unit = System.out.print(outLines.mkString)
83-
def printErrs: Unit = System.err.print(errLines.mkString)
84-
85-
object Console:
86-
def default: Console = new ConsoleImpl
87-
88-
private class ConsoleImpl extends Console:
89-
private val outBuffer: ListBuffer[String] = ListBuffer.empty
90-
private val errBuffer: ListBuffer[String] = ListBuffer.empty
91-
92-
def print(str: String): Unit = outBuffer.append(str)
93-
def println(str: String): Unit = outBuffer.append(s"$str\n")
94-
def error(str: String): Unit = errBuffer.append(str)
95-
def errorln(str: String): Unit = errBuffer.append(s"$str\n")
96-
97-
def outLines: List[String] = outBuffer.toList
98-
def errLines: List[String] = errBuffer.toList
99-
100-
def runWith[A](fn: (os.Path, Console) => Unit): Unit =
101-
val console = Console.default
102-
fn(os.pwd, console)
103-
console.printOuts
104-
console.printErrs

.github/ci_scripts/project.test.scala

Lines changed: 1 addition & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -49,78 +49,4 @@ lazy dog
4949
assertEquals(result2, None)
5050
}
5151

52-
}
53-
54-
object FixtureData:
55-
56-
val ArtifactShas: Map[String, String] = Map(
57-
"bazel-bsp-linux-x86.sha256" -> "83da2ffc0ab594a348f7828888d9e4c761ec128c38b1f013434f51f258cd6b9f",
58-
"bazel-bsp-macos-x86.sha256" -> "2d450d6cb18c8e0f436389ff0fd439694336276f53966e6d01206de4bc1f376f",
59-
"bazel_rules.tar.gz.sha256" -> "11c6fd27bc6cb5d4194dffe772b285a22dc5355a7c64ed53bea5c735ac9ddf04"
60-
)
61-
62-
val BazelRule = raw"""
63-
load("//private:load_tool.bzl", "load_tool")
64-
65-
# <--- Updated automatically by release job
66-
_bazel_bsp_version = "0.0.19"
67-
_build_artifact_shas = {
68-
"linux-x86": "a3453ktnegakjdngf43yt334g34g3g34g34g",
69-
"amiga-m68000": "34534lsbflsldfb43mh34hlmbrebml34h34h",
70-
}
71-
# --->
72-
73-
def _bazel_bsp_load(platform):
74-
name = "bazel-bsp-{}".format(platform)
75-
...
76-
77-
def bazel_bsp_setup():
78-
_bazel_bsp_load("linux-x86")
79-
_bazel_bsp_load("macos-x86")
80-
""".trim
81-
82-
val Readme = """
83-
# Bazel BSP
84-
Current Version: [0.0.19](https://github.com/aishfenton/bazel-bsp/releases/tag/v0.0.19)
85-
86-
```starlark
87-
bazel_bsp_version = "0.0.19"
88-
http_archive(
89-
name = "bazel-bsp-rules",
90-
sha256 = "5da0e3c951a7ea50be908d3b97bf2f0b2da8713b99c6035e826dfce3302d5b39",
91-
strip_prefix = "bazel_rules",
92-
type = "tar.gz",
93-
url = "https://github.com/aishfenton/bazel-bsp/releases/download/v{}/bazel_rules.tar.gz" % bazel_bsp_version,
94-
)
95-
96-
load("@bazel-bsp-rules//bazel_rules:bazel_bsp_setup.bzl", "bazel_bsp_setup")
97-
bazel_bsp_setup()
98-
```
99-
100-
More blah blah blah
101-
""".trim
102-
103-
val BuildFile = """
104-
val scala3Version = "3.2.1"
105-
106-
// <--- Updated automatically by release job
107-
val bazelBspVersion = "0.0.19"
108-
// --->
109-
110-
lazy val root = project
111-
.in(file("."))
112-
.settings(
113-
name := "bazel-bsp",
114-
organization := "afenton",
115-
version := bazelBspVersion,
116-
scalaVersion := scala3Version,
117-
buildInfoKeys := Seq[BuildInfoKey](
118-
name,
119-
version,
120-
scalaVersion,
121-
sbtVersion,
122-
"bspVersion" -> "2.0.0-M2"
123-
),
124-
buildInfoPackage := "afenton.bazel.bsp"
125-
)
126-
""".trim
52+
}

.github/ci_scripts/update.sh

Lines changed: 0 additions & 18 deletions
This file was deleted.

.github/ci_scripts/updateArtifactShas.scala

Lines changed: 36 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22

33
import scala.util.matching.Regex
44

5-
private def join(l1: String, l2: String): String =
5+
def join(l1: String, l2: String): String =
66
if l1.isEmpty then l2
77
else s"$l1\n$l2"
88

9-
// Substitutes bazel_rule SHA into README
109
def substituteReadme(readmeContent: String, newSha: String): String =
1110
sed(readmeContent, "sha256 =".r, s"\"[a-f0-9]{64}\"".r, s"\"$newSha\"") match
1211
case Some(c) => c
@@ -15,7 +14,6 @@ def substituteReadme(readmeContent: String, newSha: String): String =
1514
s"No substitutions made in README.md, with content: $readmeContent"
1615
)
1716

18-
// Substitutes new SHA defintions into Python
1917
def substituteBazelRule(
2018
ruleContent: String,
2119
newDefinitions: String
@@ -76,61 +74,56 @@ def generatePythonMap(artifacts: Map[String, String]): String =
7674
"}"
7775
).mkString("\n")
7876

79-
private def binEntries(map: Map[String, String]): Map[String, String] =
80-
map.filterKeys(_.contains("bazel-bsp")).toMap
81-
82-
def updateArtifactShas(
83-
bazelRuleFile: String,
84-
readmeFile: String,
85-
artifactDir: String,
86-
cwd: os.Path,
87-
console: Console
77+
def updateFile(
78+
filePath: os.Path,
79+
artifactPath: os.Path,
80+
fn: (String, Map[String, String]) => String
8881
): Unit =
89-
90-
val bazelRulePath = os.Path(bazelRuleFile, cwd)
91-
val readmePath = os.Path(readmeFile, cwd)
92-
val artifactPath = os.Path(artifactDir, cwd)
93-
82+
require(os.exists(filePath), s"$filePath wasn't found")
9483
require(os.isDir(artifactPath), s"${artifactPath} is not a directory")
95-
List(bazelRulePath, readmePath).foreach { f =>
96-
require(os.exists(f), s"$f file wasn't found")
97-
}
9884

9985
val artifactShas: Map[String, String] = os
10086
.list(artifactPath)
10187
.filter(_.ext == "sha256")
10288
.map(a => (a.last, os.read(a).trim))
10389
.toMap
10490

105-
val newRule = substituteBazelRule(
106-
os.read(bazelRulePath),
107-
generatePythonMap(binEntries(artifactShas))
108-
)
91+
require(!artifactShas.isEmpty, s"No artifacts SHAs found at $artifactPath")
92+
93+
val newContent = fn(os.read(filePath), artifactShas)
10994

110-
println(s"Writing new $bazelRulePath")
111-
os.write.over(bazelRulePath, newRule)
95+
println(s"Writing new $filePath")
96+
os.write.over(filePath, newContent)
11297

113-
val newReadme = substituteReadme(
114-
os.read(readmePath),
115-
artifactShas("bazel_rules.tar.gz.sha256")
98+
/** Update bazee_rule.tar.gz artifcat SHA in README.md.
99+
*
100+
* @param artifactDir
101+
* The directory where artifacts are stored
102+
*/
103+
@main def updateReadme(artifactDir: String): Unit =
104+
val artifactPath = os.Path(artifactDir, os.pwd)
105+
106+
updateFile(
107+
os.pwd / "README.md",
108+
artifactPath,
109+
(content, artifacts) =>
110+
substituteReadme(content, artifacts("bazel_rules.tar.gz.sha256"))
116111
)
117112

118-
println(s"Writing new $readmePath")
119-
os.write.over(readmePath, newReadme)
113+
def binEntries(map: Map[String, String]): Map[String, String] =
114+
map.filterKeys(_.contains("bazel-bsp")).toMap
120115

121-
/** Update the given inputFile with the SHA256 of the artifacts in artifactDir.
122-
* And print to stdout.
116+
/** Update bin artifact SHA's in bazel_rules.
123117
*
124-
* @param bazelRuleFile
125-
* The bazel_rule file to update
126-
* @param readmeFile
127-
* The README file to update
128118
* @param artifactDir
129119
* The directory where artifacts are stored
130120
*/
131-
@main def updateArtifactShas(
132-
bazelRuleFile: String,
133-
readmeFile: String,
134-
artifactDir: String
135-
): Unit =
136-
runWith(updateArtifactShas(bazelRuleFile, readmeFile, artifactDir, _, _))
121+
@main def updateBazelRule(artifactDir: String): Unit =
122+
val artifactPath = os.Path(artifactDir, os.pwd)
123+
124+
updateFile(
125+
os.pwd / "bazel_rules" / "bazel_bsp_setup.bzl",
126+
artifactPath,
127+
(content, artifacts) => substituteBazelRule(content, generatePythonMap(binEntries(artifacts)))
128+
)
129+
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//> using file "project.scala"
2+
3+
import math.Ordering.Implicits.infixOrderingOps
4+
5+
/**
6+
* Update a SemVer version in a given file
7+
*
8+
* @param file The file to update
9+
* @param linePattern The pattern to find the line to update
10+
* @param newVersion The version string to replace with
11+
*/
12+
@main def updateVersion(
13+
file: String,
14+
linePattern: String,
15+
newVersionStr: String,
16+
): Unit =
17+
val filePath = os.Path(file, os.pwd)
18+
require(os.exists(filePath), s"$filePath file wasn't found")
19+
20+
val newVersion = SemVer.fromString(newVersionStr) match
21+
case Some(semVer) => semVer
22+
case None =>
23+
throw new Exception(s"Invalid version string: $newVersionStr")
24+
25+
val newContent =
26+
sed(
27+
os.read(filePath),
28+
linePattern.r,
29+
raw"(\d+)\.(\d+).(\d+)".r,
30+
newVersion.asString
31+
) match
32+
case Some(value) => value
33+
case None => throw new Exception(s"No substitutions made in $filePath")
34+
35+
println(s"Updating $filePath")
36+
os.write.over(filePath, newContent)

.github/ci_scripts/updateVersions.scala

Lines changed: 0 additions & 74 deletions
This file was deleted.

0 commit comments

Comments
 (0)