Skip to content

Commit

Permalink
Command chaining
Browse files Browse the repository at this point in the history
  • Loading branch information
eed3si9n committed Oct 16, 2024
1 parent e46a9fb commit 773481d
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 9 deletions.
28 changes: 19 additions & 9 deletions plugin/src/main/scala/com/geirsson/CiReleasePlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
8 changes: 8 additions & 0 deletions plugin/src/test/scala/com/geirsson/CiReleaseTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
39 changes: 39 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down

0 comments on commit 773481d

Please sign in to comment.