From 474b1b7111bf8a0c925b4a54706980367f5f724a Mon Sep 17 00:00:00 2001 From: Damian Reeves <957246+DamianReeves@users.noreply.github.com> Date: Sat, 5 Oct 2024 16:41:16 -0500 Subject: [PATCH] Ensure we restore the capability to publish Snapshot versions (#172) * Archived github-dependency related workflows until they are supported by mill 0.12.x * tagged and released builds are normal others are SNAPSHOT --- .../workflows/github-dependency-graph.yml | 0 .../workflows/github-dependency-review.yml | 0 .github/workflows/ci-cd.yml | 43 ++++++++--------- build.mill.scala | 46 ++++++++++++------- 4 files changed, 52 insertions(+), 37 deletions(-) rename .github/{ => archived}/workflows/github-dependency-graph.yml (100%) rename .github/{ => archived}/workflows/github-dependency-review.yml (100%) diff --git a/.github/workflows/github-dependency-graph.yml b/.github/archived/workflows/github-dependency-graph.yml similarity index 100% rename from .github/workflows/github-dependency-graph.yml rename to .github/archived/workflows/github-dependency-graph.yml diff --git a/.github/workflows/github-dependency-review.yml b/.github/archived/workflows/github-dependency-review.yml similarity index 100% rename from .github/workflows/github-dependency-review.yml rename to .github/archived/workflows/github-dependency-review.yml diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index 23619249..b937160a 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -3,6 +3,8 @@ on: pull_request: push: branches: [main] + tags: + - "v*.*.*" release: types: - published @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -206,18 +207,18 @@ 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: @@ -225,7 +226,7 @@ jobs: 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" @@ -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 @@ -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 @@ -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: diff --git a/build.mill.scala b/build.mill.scala index 5d613108..b8294442 100644 --- a/build.mill.scala +++ b/build.mill.scala @@ -1,4 +1,4 @@ -package build +package build import $meta._ import $ivy.`com.lihaoyi::mill-contrib-buildinfo:$MILL_VERSION` @@ -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._ @@ -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) @@ -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 { @@ -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, @@ -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)() }