From 773481d84e11482fe3b7c0bcc5b5b63ef41976dc Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Wed, 16 Oct 2024 02:36:28 -0400 Subject: [PATCH] Command chaining --- .../scala/com/geirsson/CiReleasePlugin.scala | 28 ++++++++----- .../scala/com/geirsson/CiReleaseTest.scala | 8 ++++ readme.md | 39 +++++++++++++++++++ 3 files changed, 66 insertions(+), 9 deletions(-) diff --git a/plugin/src/main/scala/com/geirsson/CiReleasePlugin.scala b/plugin/src/main/scala/com/geirsson/CiReleasePlugin.scala index 8286ffa..3c46d4f 100644 --- a/plugin/src/main/scala/com/geirsson/CiReleasePlugin.scala +++ b/plugin/src/main/scala/com/geirsson/CiReleasePlugin.scala @@ -244,15 +244,25 @@ object CiReleasePlugin extends AutoPlugin { def backPubVersionToCommand(ver: String): String = if (ver.contains("@")) { - val afterAt = ver.split("@").drop(1).mkString("@") - val cmd = - if (afterAt.contains("#")) afterAt.split("#").head - else afterAt - if (cmd.isEmpty) sys.error(s"Invalid back-publish version: $ver") - else { - if (!cmd.head.isDigit) cmd - else if (cmd.contains(".x")) s";++${cmd};publishSigned" - else s";++${cmd}!;publishSigned" + val nonComment = + if (ver.contains("#")) ver.split("#").head + else ver + val commands0 = nonComment.split("@").toList.drop(1) + var nonDigit = false + val commands = (commands0.map { cmd => + if (cmd.isEmpty) sys.error(s"Invalid back-publish version: $ver") + else { + if (!cmd.head.isDigit) { + nonDigit = true + cmd + } + else if (cmd.contains(".x")) s"++${cmd}" + else s"++${cmd}!" + } + }) ::: (if (nonDigit) Nil else List("publishSigned")) + commands match { + case x :: Nil => x + case xs => xs.mkString(";", ";", "") } } else "+publishSigned" diff --git a/plugin/src/test/scala/com/geirsson/CiReleaseTest.scala b/plugin/src/test/scala/com/geirsson/CiReleaseTest.scala index 4cdd39f..9de7c71 100644 --- a/plugin/src/test/scala/com/geirsson/CiReleaseTest.scala +++ b/plugin/src/test/scala/com/geirsson/CiReleaseTest.scala @@ -26,6 +26,14 @@ class CiReleaseTest extends munit.FunSuite { assertEquals(dropBackPubCommand("1.1.0@+foo/publishSigned"), expectedVer) } + test("Commands can be chained") { + assertEquals(backPubVersionToCommand("1.1.0@2.12.20@foo/publishSigned"), ";++2.12.20!;foo/publishSigned") + assertEquals(dropBackPubCommand("1.1.0@2.12.20@foo/publishSigned"), expectedVer) + + assertEquals(backPubVersionToCommand("1.1.0@foo/something@bar/publishSigned"), ";foo/something;bar/publishSigned") + assertEquals(dropBackPubCommand("1.1.0@foo/something@bar/publishSigned"), expectedVer) + } + test("Treat # as comments") { assertEquals(backPubVersionToCommand("1.1.0#comment"), "+publishSigned") assertEquals(dropBackPubCommand("1.1.0#comment"), expectedVer) diff --git a/readme.md b/readme.md index 7f2ed1c..615afa6 100644 --- a/readme.md +++ b/readme.md @@ -356,6 +356,45 @@ page will look like this: Enjoy 👌 +### Back-publishing support + +sbt-ci-release implements a mini-DSL for the Git tag for back publishing purpose, which is useful if you maintain a compiler plugin, library for Scala Native, or an sbt plugin during 2.x migration etc. + +``` +v1.2.3[@3.x|@2.n.x|@a.b.c][@command][#comment] +``` + +- `#` is used for comments, which is useful if you need to use the same command multiple times +- `@3.x` expands to `++3.x`, and if no other commands follow, `;++3.x;publishSigned` +- `@2.13.x` expands to `++2.13.x`, and if no other commands follow, `;++2.13.x;publishSigned` +- Other commands such as `@foo/publishSigned` expands to `foo/publishSigned` + +#### Case 1: Publish all subprojects for Scala 2.13.15 + +`v1.2.3@2.13.15` + +#### Case 2: Publish all subprojects for Scala 3.x + +`v1.2.3@3.x`. Optionally we can add a comment: `v1.2.3@3.x#comment`. + +We can use this to back publish sbt 2.x plugins. + +1. Branch off of `v1.2.3` to create `release/1.2.3` branch, and send a PR to bump sbt version +2. Tag the brach to `v1.2.3@3.x#sbt2.0.0-Mn` + +#### Case 3: Publish some subprojects for Scala 2.13.15 + +`v1.2.3@2.13.15@foo/publishSigned` + +You can create a subproject to aggregate 2 or more subprojects. + +#### Case 4: Publish some subprojects for supported Scala versions + +`v1.2.3@+foo_native/publishSigned#comment` + +1. Branch off of `v1.2.3` to create `release/1.2.3` branch, and send a PR to bump the Scala Native version. +2. Tag the branch to `v1.2.3@+foo_native/publishSigned#native=0.5` + ## FAQ ### How do I publish to Sonatype Central?