Skip to content

Commit ce48ba0

Browse files
committed
Actually run Scala Steward - given that generating config succeeded
1 parent 870f534 commit ce48ba0

File tree

6 files changed

+53
-28
lines changed

6 files changed

+53
-28
lines changed

.github/workflows/generate-targeted-prs.yml

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,11 @@ jobs:
2323
TARGETED_RELEASES_GITHUB_APP_CLIENT_ID: 214238
2424
TARGETED_RELEASES_GITHUB_APP_PRIVATE_KEY: ${{ secrets.SCALA_STEWARD_APP_PRIVATE_KEY }}
2525
run: sbt "run ${{ inputs.target_pr }} targeted-scala-steward.conf"
26-
- name: Pretend to run Scala Steward
27-
run: echo "Hi there!"
28-
# - name: Execute Scala Steward
29-
# uses: scala-steward-org/scala-steward-action@v2.76.0
30-
# with:
31-
# github-app-id: 214238
32-
# github-app-installation-id: 26822732
33-
# github-app-key: ${{ secrets.SCALA_STEWARD_APP_PRIVATE_KEY }}
34-
# repo-config: targeted-scala-steward.conf
35-
# other-args: "--add-labels"
26+
- name: Execute Scala Steward
27+
uses: scala-steward-org/scala-steward-action@v2.76.0
28+
with:
29+
github-app-id: 214238
30+
github-app-installation-id: 26822732
31+
github-app-key: ${{ secrets.SCALA_STEWARD_APP_PRIVATE_KEY }}
32+
repo-config: targeted-scala-steward.conf
33+
other-args: "--add-labels"

build.sbt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
scalaVersion := "3.3.6"
22
scalacOptions := Seq("-deprecation", "-release:21")
33

4-
libraryDependencies += "com.madgag.play-git-hub" %% "core" % "10.0.0-PREVIEW.examine-default-branch.2025-10-01T1252.5ed70273"
4+
libraryDependencies ++= Seq(
5+
"com.madgag.play-git-hub" %% "core" % "10.0.0-PREVIEW.examine-default-branch.2025-10-01T1252.5ed70273",
6+
"org.scalatest" %% "scalatest" % "3.2.19" % Test
7+
)
58

69
Compile / run / fork := true

src/main/scala/com/gu/scalasteward/targeted/WriteConfigToTargetArtefact.scala renamed to src/main/scala/com/gu/scalasteward/targeted/WriteConfigTargetingPreviewRelease.scala

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,35 @@ import cats.data.*
55
import cats.effect.unsafe.implicits.global
66
import cats.effect.{ExitCode, IO, IOApp}
77
import cats.implicits.*
8-
import cats.syntax.all.*
98
import com.gu.scalasteward.targeted.model.{Artifact, Config}
109
import com.madgag.github.apps.GitHubAppAuth
1110
import com.madgag.scalagithub
1211
import com.madgag.scalagithub.GitHub
1312
import com.madgag.scalagithub.model.{Comment, PullRequest, RepoId}
14-
import play.api.libs.json.Json.toJson
15-
import play.api.libs.json.{Json, OWrites}
1613
import sttp.model.*
1714

1815
import java.nio.file.{Files, Path}
1916
import scala.collection.immutable.SortedSet
2017
import scala.concurrent.ExecutionContext.Implicits.global
2118

22-
val gitHubAppAuth: GitHubAppAuth = GitHubAppAuth.fromConfigMap(sys.env, "TARGETED_RELEASES")
19+
object WriteConfigTargetingPreviewRelease extends IOApp {
20+
val gitHubAppAuth: GitHubAppAuth = GitHubAppAuth.fromConfigMap(sys.env, "TARGETED_RELEASES")
2321

24-
object HelloWorld extends IOApp {
25-
26-
def run(args: List[String]) = {
22+
def run(args: List[String]): IO[ExitCode] = {
2723
val prId = PullRequest.Id.from(Uri.unsafeParse(args(0)))
2824
val outputFile = Path.of(args(1))
2925
for {
3026
installationAccess <- gitHubAppAuth.accessSoleInstallation()
31-
_ <- IO.println(s"Hello, ${installationAccess.installedOnAccount.atLogin}!")
3227
given GitHub = installationAccess.accountAccess().gitHub
3328
pr <- summon[GitHub].getPullRequest(prId).map(_.result)
3429
configOpt <- scalaStewardConfigForMostRecentPreviewReleaseOf(pr).value
3530
exitCode <- IO {
3631
configOpt.fold {
37-
Console.err.println(s"Couldn't generate config for ${pr.html_url}")
32+
Console.err.println(s"Could not generate config for ${pr.html_url}")
3833
ExitCode.Error
3934
} { config =>
4035
Files.writeString(outputFile, config.text)
41-
println(s"Wrote config to ${outputFile.toAbsolutePath}")
36+
println(s"Wrote config to ${outputFile.toAbsolutePath} :\n\n${config.text}")
4237
ExitCode.Success
4338
}
4439
}
@@ -54,13 +49,14 @@ object HelloWorld extends IOApp {
5449
def findPreviewVersionIn(comment: Comment): Option[String] = comment.body.linesIterator.find(_.contains("-PREVIEW"))
5550

5651
def tagMessageFor(repoId: RepoId, version: String)(using g: GitHub): IO[String] = for {
52+
_ <- IO.println(s"Looking for '${repoId.fullName}' release tag: $version")
5753
repo <- g.getRepo(repoId).map(_.result)
5854
ref <- repo.refs.get(s"tags/v$version").map(_.result)
5955
tag <- repo.tags.get(ref.objectId.name).map(_.result)
6056
} yield tag.message
6157

6258
def artifactsFrom(tagMessage: String): Seq[Artifact] =
63-
tagMessage.linesIterator.filter(_.endsWith(".pom")).flatMap(Artifact.fromSha256PomLine).toSeq
59+
tagMessage.linesIterator.filter(_.endsWith(".pom")).flatMap(Artifact.fromHashdeepPomLine).toSeq
6460

6561
def scalaStewardConfigFor(pr: PullRequest, version: String)(using GitHub): OptionT[IO, Config] = OptionT(for {
6662
tagMessage <- tagMessageFor(pr.prId.repo, version)

src/main/scala/com/gu/scalasteward/targeted/model/Artifact.scala

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,19 @@ import cats.Order
44
import play.api.libs.json.{Json, OWrites}
55

66
object Artifact {
7-
// c96c2303d065496792e7edb379b0e671f57edbb13cecb6b2d94deb22d1a504d4 ./com/gu/panda-hmac-core_3/11.0.0/panda-hmac-core_3-11.0.0.pom
8-
def fromSha256PomLine(pomLine: String): Option[Artifact] = {
7+
/**
8+
* Parses a single line from the HashDeep (https://github.com/jessek/hashdeep) output included in
9+
* the annotated Git Tag message for a release by our Scala Library Release workflow:
10+
*
11+
* https://github.com/guardian/gha-scala-library-release-workflow/blob/fa09703460a2eae0fd7d47b3f3088b34c400f973/actions/sign/action.yml#L106-L110
12+
*
13+
* An example line would look like this:
14+
*
15+
* `c96c2303d065496792e7edb379b0e671f57edbb13cecb6b2d94deb22d1a504d4 ./com/gu/panda-hmac-core_3/11.0.0/panda-hmac-core_3-11.0.0.pom`
16+
*
17+
* We only want to extract the groupId, artifactId & version (not the hash).
18+
*/
19+
def fromHashdeepPomLine(pomLine: String): Option[Artifact] = {
920
val segments = pomLine.split(' ').last.split('/').drop(1).dropRight(1).reverse.toList
1021
segments match {
1122
case version :: artifactId :: groupSegments =>
@@ -14,7 +25,7 @@ object Artifact {
1425
}
1526
}
1627

17-
given Order[Artifact] = Order.by(Tuple.fromProductTyped)
28+
given Order[Artifact] = Order.by(Tuple.fromProductTyped) // required by NonEmptySet
1829

1930
given OWrites[Artifact] = Json.writes
2031
}

src/main/scala/com/gu/scalasteward/targeted/model/Config.scala

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ case class Config(
99
pr: PullRequest,
1010
updates: NonEmptySet[Artifact]
1111
) {
12-
val groupIds: NonEmptySet[String] = updates.map(_.groupId)
13-
val versions: NonEmptySet[String] = updates.map(_.version)
14-
1512
val commitsMessage: String = "Update ${artifactName} from ${currentVersion} to ${nextVersion}"
1613

1714
val updatesJson: String = toJson(updates.toSortedSet.toSeq).toString
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.gu.scalasteward.targeted.model
2+
3+
import org.scalatest.OptionValues
4+
import org.scalatest.flatspec.AnyFlatSpec
5+
import org.scalatest.matchers.should.Matchers
6+
7+
class ArtifactTest extends AnyFlatSpec with Matchers with OptionValues {
8+
it should "read artifact coordinates from a hashdeep line, as written by gha-scala-library-release-workflow" in {
9+
Artifact.fromHashdeepPomLine("c96c2303d065496792e7edb379b0e671f57edbb13cecb6b2d94deb22d1a504d4 ./com/gu/panda-hmac-core_3/11.0.0/panda-hmac-core_3-11.0.0.pom").value shouldBe
10+
Artifact("com.gu", "panda-hmac-core_3", "11.0.0")
11+
}
12+
13+
it should "remove the Scala version from the artifact id" in {
14+
Artifact("com.gu", "panda-hmac-core_3", "11.0.0").artifactIdWithoutScalaOrSbtVersion shouldBe "panda-hmac-core"
15+
}
16+
17+
it should "remove the Scala & sbt version from a sbt plugin artifact" in {
18+
Artifact("com.gu", "sbt-scrooge-typescript_2.12_1.0", "4.0.0").artifactIdWithoutScalaOrSbtVersion shouldBe "sbt-scrooge-typescript"
19+
}
20+
}

0 commit comments

Comments
 (0)