Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update publish mechanism #57

Merged
merged 2 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,10 @@ jobs:

- name: Compile
run: mill -k --disable-ticker __.compile

- name: Publish ${{ github.ref }}
run: ./ci/publish.sh && echo "PUBLISH_VERSION=$(mill -k --disable-ticker show lsp.publishVersion | tr -d '\"')" >> $GITHUB_ENV

- run: ./mill -i io.kipp.mill.ci.release.ReleaseModule/publishAll
env:
PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }}
PGP_SECRET: ${{ secrets.PGP_SECRET }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
SONATYPE_PASSWORD: ${{ secrets.S01_SONATYPE_PASSWORD }}
SONATYPE_USERNAME: ${{ secrets.S01_SONATYPE_USERNAME }}
97 changes: 6 additions & 91 deletions build.sc
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import $ivy.`io.chris-kipp::mill-ci-release::0.1.10`
import mill._
import scalalib._
import mill.scalalib.publish._
import scala.util.Try
import io.kipp.mill.ci.release.CiReleaseModule
import io.kipp.mill.ci.release.SonatypeHost

object lsp extends MavenModule with PublishModule {
object lsp extends MavenModule with CiReleaseModule {

override def sonatypeHost = Some(SonatypeHost.s01)

def millSourcePath: os.Path = os.pwd

Expand All @@ -15,8 +20,6 @@ object lsp extends MavenModule with PublishModule {
ivy"software.amazon.smithy:smithy-syntax:1.50.0"
)

def publishVersion = T { gitVersion() }

def javacOptions = T {
super.javacOptions() ++ Seq(
"-source",
Expand All @@ -43,94 +46,6 @@ object lsp extends MavenModule with PublishModule {
Seq(Developer("baccata", "Olivier Mélois", "https://github.com/baccata"))
)

def gitVersion: T[String] = T.input {

val gitDirty =
os.proc("git", "diff", "HEAD").call().out.lines.nonEmpty

if (gitDirty) sys.error("Dirty workspace !")

val commitHash =
os.proc("git", "rev-parse", "--short", "HEAD").call().out.lines.head.trim

val describeResult = os
.proc(
"git",
"describe",
"--long",
"--tags",
"--abbrev=8",
"--match",
"v[0-9]*",
"--always",
"--dirty=+dirty"
)
.call()
.out
.lines
.lastOption
.map(_.replaceAll("-([0-9]+)-g([0-9a-f]{8})", "+$1-$2"))
.getOrElse(s"v0.0.0-$commitHash")
parseVersion(describeResult)
}

def mainBranch: T[String] = "dss"

def latestTag: T[Option[String]] = T {
val branch = mainBranch()
os.proc("git", "describe", branch, "--abbrev=0", "--tags")
.call()
.out
.lines
.headOption
}

object int {
def unapply(s: String) = s.toIntOption
}

object distanceToTag {
def unapply(s: String): Option[Int] = {
Option(s).flatMap(_.toIntOption).orElse(Some(0))
}
}

object sha {
private val shaRegex = """([0-9a-f]{8})""".r
def unapply(s: String): Option[String] =
if (shaRegex.pattern.matcher(s).matches()) Some(s) else None
}

object nonCommittedCode {
def unapply(s: String): Option[Boolean] = Some(Option(s).isDefined)
}

def parseVersion(s: String): String = s.trim match {
case s"v$tag+${int(dist)}-${sha(s)}+dirty" =>
version(Some(tag), dist, s, dirty = true)
case s"v$tag+${int(dist)}-${sha(s)}" =>
version(Some(tag), dist, s, dirty = false)
case s"${sha(s)}+dirty" =>
version(None, 0, s, dirty = true)
case s"${sha(s)}" =>
version(None, 0, s, dirty = false)
case s"v$tag" =>
version(Some(tag), 0, s, dirty = false)
}

def version(
maybeTag: Option[String],
distance: Int,
sha: String,
dirty: Boolean
): String = {
val untagged = if (sha.isEmpty) "" else s"+$distance-$sha"
val tagged = if (distance > 0) s"+$distance-$sha" else ""
val version = maybeTag.fold(s"0.0.0$untagged")(tag => s"$tag$tagged")
val dirtySuffix = if (dirty) "-SNAPSHOT" else ""
s"$version$dirtySuffix"
}

def writeVersion: T[PathRef] = T {
val version = publishVersion()
val targetDir = T.ctx().dest / "resources"
Expand Down
27 changes: 0 additions & 27 deletions ci/publish.sh

This file was deleted.

Loading