Skip to content

Commit

Permalink
Ensure we restore the capability to publish Snapshot versions (#172)
Browse files Browse the repository at this point in the history
* Archived github-dependency related workflows until they are supported by mill 0.12.x

* tagged and released builds are normal others are SNAPSHOT
  • Loading branch information
DamianReeves authored Oct 5, 2024
1 parent 43fade6 commit 474b1b7
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 37 deletions.
43 changes: 22 additions & 21 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ on:
pull_request:
push:
branches: [main]
tags:
- "v*.*.*"
release:
types:
- published
Expand All @@ -14,14 +16,13 @@ env:
scala_212_version: "2.12.20"
scala_213_version: "2.13.15"
scala_3_version: "3.3.4"
SonatypeUrl: 'https://finos.sonatype.app/platform/'
SonatypeUrl: "https://finos.sonatype.app/platform/"
SonatypeAppId: morphir-jvm
SonatypeStage: 'build'
SonatypeScanTarget: '.' # depCache/coursier/v1/https/repo1.maven.org/maven2/
SonatypeStage: "build"
SonatypeScanTarget: "." # depCache/coursier/v1/https/repo1.maven.org/maven2/
ExcludeDirectory: " -D fileExcludes='*.class, **/website/, **/docs/, **/.*, **/*mill*.jar' "

# Build support Test: 002

# Build support Test: 002

# cancel older runs of a pull request;
# this will not cancel anything for normal git pushes
Expand All @@ -37,7 +38,7 @@ jobs:
fail-fast: false
matrix:
java: ["11", "17"]
scala: ["2.12.20","2.13.15", "3.3.4"]
scala: ["2.12.20", "2.13.15", "3.3.4"]
steps:
- name: Checkout current branch
uses: actions/checkout@v4
Expand All @@ -53,10 +54,10 @@ jobs:

- name: Run JVM tests
run: |
./mill -i -k -j 0 "morphir[${{matrix.scala}}].__.jvm.__.compile" + "morphir[${{matrix.scala}}].__.jvm.publishArtifacts" + "morphir[${{matrix.scala}}].__.jvm.__.test"
./mill -i -k -j 0 "morphir[${{matrix.scala}}].__.jvm.__.compile" + "morphir[${{matrix.scala}}].__.jvm.publishArtifacts" + "morphir[${{matrix.scala}}].__.jvm.__.test"
- name: Lint Scala (JVM)
run: ./mill -i -k -j 0 "morphir[${{matrix.scala}}].__.jvm.__.checkFormat"
run: ./mill -i -k -j 0 "morphir[${{matrix.scala}}].__.jvm.__.checkFormat"

- name: Cache JVM build output
# when in master repo: all commits to main branch and all additional tags
Expand All @@ -75,7 +76,7 @@ jobs:
fail-fast: false
matrix:
java: ["17"] # Note there is no need ro actually run this for multiple JVM versions for JS
scala: [ "2.12.20", "2.13.15", "3.3.4"]
scala: ["2.12.20", "2.13.15", "3.3.4"]
steps:
- name: Checkout current branch
uses: actions/checkout@v4
Expand All @@ -92,9 +93,9 @@ jobs:
- name: Run JS tests
run: |
./mill -i -k -j 0 "morphir[${{matrix.scala}}].__.js.__.compile" + "morphir[${{matrix.scala}}].__.js.publishArtifacts" + "morphir[${{matrix.scala}}].__.js.__.test"
- name: Lint ScalaJS
run: ./mill -i -k -j 0 "morphir[${{matrix.scala}}].__.js.__.checkFormat"
run: ./mill -i -k -j 0 "morphir[${{matrix.scala}}].__.js.__.checkFormat"

- name: Cache JS build output
# when in master repo: all commits to main branch and all additional tags
Expand All @@ -112,7 +113,7 @@ jobs:
fail-fast: false
matrix:
java: ["11"] # Note there is no need ro actually run this for multiple JVM versions for native
scala: ["2.12.20","2.13.15", "3.3.4"]
scala: ["2.12.20", "2.13.15", "3.3.4"]
steps:
- name: Checkout current branch
uses: actions/checkout@v4
Expand All @@ -137,7 +138,7 @@ jobs:
./mill -i -k -j 0 "morphir[${{matrix.scala}}].__.native.__.compile" + "morphir[${{matrix.scala}}].__.native.publishArtifacts" + "morphir[${{matrix.scala}}].__.native.__.test"
- name: Lint ScalaNative
run: ./mill -i -k -j 0 "morphir[${{matrix.scala}}].__.native.__.checkFormat"
run: ./mill -i -k -j 0 "morphir[${{matrix.scala}}].__.native.__.checkFormat"

- name: Cache Native build output
# when in master repo: all commits to main branch and all additional tags
Expand Down Expand Up @@ -206,26 +207,26 @@ jobs:
with:
name: ${{ env.SonatypeAppId }} Sonatype SBOM (SPDX)
path: reports/
#############################################
#############################################

cd:
cd:
needs: [sonatype-scan, ci]

runs-on: ubuntu-latest
# when in primary repo: all commits to main branch and all additional tags
if: github.repository == 'finos/morphir-jvm' && ( github.ref == 'refs/heads/main' || (github.ref != 'refs/heads/main' && startsWith( github.ref, 'refs/tags/') ) )
if: github.repository == 'finos/morphir-jvm' && ( github.ref == 'refs/heads/main' || (github.ref != 'refs/heads/main' && startsWith( github.ref, 'refs/tags/') ) )

# only run one publish job for the same sha at the same time
# e.g. when a main-branch push is also tagged
concurrency:
concurrency:
group: ${{ github.workflow}}-publish-${{ github.sha }}

env:
MILL_PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }}
MILL_PGP_SECRET_BASE64: ${{ secrets.PGP_SECRET_BASE64 }}
MILL_SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
MILL_SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
PUBLISH_AS_SNAPSHOT: true
PUBLISH_AS_SNAPSHOT: ${{ github.event_name != 'release' && !startsWith(github.ref, 'refs/tags/') }}
LANG: "en_US.UTF-8"
LC_MESSAGES: "en_US.UTF-8"
LC_ALL: "en_US.UTF-8"
Expand Down Expand Up @@ -253,7 +254,7 @@ jobs:
out/morphir/2.12.20/**/jvm/
out/morphir/build/
key: ${{ runner.os }}-mill-jvm-11-2.12.20-${{ github.sha }}-${{ hashFiles('out') }}
restore-keys: ${{ runner.os }}-mill-jvm-11-2.12.20-${{ github.sha }}-
restore-keys: ${{ runner.os }}-mill-jvm-11-2.12.20-${{ github.sha }}-

- name: Restore Scala 2.13 JVM Build Output From Cache
uses: actions/cache/restore@v4
Expand All @@ -278,7 +279,7 @@ jobs:
path: |
out/morphir/2.12.20/**/js/
key: ${{ runner.os }}-mill-js-11-2.12.20-${{ github.sha }}-${{ hashFiles('out') }}
restore-keys: ${{ runner.os }}-mill-js-11-2.12.20-${{ github.sha }}-
restore-keys: ${{ runner.os }}-mill-js-11-2.12.20-${{ github.sha }}-

- name: Restore Scala 2.13 JS Build Output From Cache
uses: actions/cache/restore@v4
Expand Down Expand Up @@ -320,7 +321,7 @@ jobs:
key: ${{ runner.os }}-mill-native-11-3.3.4-${{ github.sha }}-${{ hashFiles('out') }}
restore-keys: ${{ runner.os }}-mill-native-11-3.3.4-${{ github.sha }}-

- name: Publish artifacts to Sonatype
- name: Publish artifacts to Sonatype
run: ./mill -i -j 0 mill.scalalib.PublishModule/

ci:
Expand Down
46 changes: 30 additions & 16 deletions build.mill.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package build
package build

import $meta._
import $ivy.`com.lihaoyi::mill-contrib-buildinfo:$MILL_VERSION`
Expand All @@ -7,7 +7,7 @@ import com.carlosedp.aliases._
import coursier.maven.MavenRepository
import io.github.davidgregory084.TpolecatModule
import millbuild._
import millbuild.{Versions => Vers}
import millbuild.{ Versions => Vers }
import millbuild.crossplatform._
import millbuild.settings._
import mill._, mill.scalalib._, mill.scalajslib._, mill.scalanativelib._, scalafmt._
Expand All @@ -16,16 +16,15 @@ import mill.scalajslib.api.ModuleKind
import mill.contrib.buildinfo.BuildInfo
import de.tobiasroeser.mill.vcs.version.VcsVersion


object `package` extends RootModule {
implicit val buildSettings: BuildSettings = interp.watchValue(MyBuild.cachedBuildSettings)
def resolvedBuildSettings = T.input(MyBuild.buildSettings())
val scala212 = buildSettings.scala.scala212Version
val scala213 = buildSettings.scala.scala213Version
val scala3x = buildSettings.scala.scala3xVersion

/** The version of Scala natively supported by the toolchain. Morphir itself may provide backends that generate code for
* other Scala versions. We may also directly cross-compile to additional Scla versions.
implicit val buildSettings: BuildSettings = interp.watchValue(MyBuild.cachedBuildSettings)
def resolvedBuildSettings = T.input(MyBuild.buildSettings())
val scala212 = buildSettings.scala.scala212Version
val scala213 = buildSettings.scala.scala213Version
val scala3x = buildSettings.scala.scala3xVersion

/** The version of Scala natively supported by the toolchain. Morphir itself may provide backends that generate code
* for other Scala versions. We may also directly cross-compile to additional Scla versions.
*/
val morphirScalaVersion: String = interp.watchValue(buildSettings.scala.defaultVersion)

Expand Down Expand Up @@ -152,10 +151,9 @@ object `package` extends RootModule {
}
}


//-----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Build settings and common code
//-----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
trait MorphirScalaModule extends ScalaModule with TpolecatModule with CommonCoursierModule { self =>

override def scalacOptions = T {
Expand All @@ -168,7 +166,23 @@ object `package` extends RootModule {
trait MorphirPublishModule extends PublishModule with JavaModule {
import mill.scalalib.publish._
def packageDescription: String = s"The $artifactName package"
override def publishVersion: T[String] = VcsVersion.vcsState().format()
def publishAsSnapshot = T.input {
val publishAsSnapshotVar = T.env.getOrElse("PUBLISH_AS_SNAPSHOT", "false")
T.log.info(s"PUBLISH_AS_SNAPSHOT: $publishAsSnapshotVar")
publishAsSnapshotVar match {
case "true" | "1" | "yes" => true
case _ => false
}
}
override def publishVersion: T[String] = T {
val version = VcsVersion.vcsState().format()
if (publishAsSnapshot()) {
s"${version}-SNAPSHOT"
} else {
version
}

}

def pomSettings = PomSettings(
description = packageDescription,
Expand Down Expand Up @@ -207,7 +221,7 @@ object `package` extends RootModule {

// With this we can now just do ./mill reformatAll __.sources
// instead of ./mill -w mill.scalalib.scalafmt.ScalafmtModule/reformatAll __.sources
def reformatAll(evaluator: Evaluator, @mainargs.arg(short='s')sources: mill.main.Tasks[Seq[PathRef]]) = T.command {
def reformatAll(evaluator: Evaluator, @mainargs.arg(short = 's') sources: mill.main.Tasks[Seq[PathRef]]) = T.command {
ScalafmtModule.reformatAll(sources)()
}

Expand Down

0 comments on commit 474b1b7

Please sign in to comment.