From 9852e11d9ef39225900ce4a5c6b034cab91d711b Mon Sep 17 00:00:00 2001 From: Divya Bhatt Date: Tue, 12 Mar 2024 16:16:37 +0000 Subject: [PATCH 1/5] Adopt gha-scala-release process --- .github/workflows/release.yml | 36 +++++++++ build.sbt | 147 +++++++--------------------------- project/build.properties | 2 +- project/plugins.sbt | 7 +- 4 files changed, 71 insertions(+), 121 deletions(-) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..a82370e --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,36 @@ +name: Release + +on: + workflow_dispatch: + +jobs: + scala-maven-release: + name: Maven Release + uses: guardian/gha-scala-library-release-workflow/.github/workflows/reusable-release.yml@main + permissions: { contents: write, pull-requests: write } + secrets: + SONATYPE_PASSWORD: ${{ secrets.AUTOMATED_MAVEN_RELEASE_SONATYPE_PASSWORD }} + PGP_PRIVATE_KEY: ${{ secrets.AUTOMATED_MAVEN_RELEASE_PGP_SECRET }} + GITHUB_APP_PRIVATE_KEY: ${{ secrets.AUTOMATED_MAVEN_RELEASE_GITHUB_APP_PRIVATE_KEY }} + + typescript-npm-release: + name: NPM Release + needs: scala-maven-release + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-java@v4 + with: + distribution: corretto + java-version: 11 + cache: sbt + - uses: actions/setup-node@v4 + with: + node-version-file: .nvmrc + registry-url: https://registry.npmjs.org + - name: Release Typescript to NPM + run: | + sbt "project typescript" "releaseNpm ${{ needs.scala-maven-release.outputs.RELEASE_VERSION }}" + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + RELEASE_TYPE: ${{ needs.scala-maven-release.outputs.RELEASE_TYPE }} diff --git a/build.sbt b/build.sbt index 115924e..438d614 100644 --- a/build.sbt +++ b/build.sbt @@ -1,133 +1,48 @@ import sbtrelease._ import ReleaseStateTransformations._ +import sbtrelease.ReleaseStateTransformations._ +import sbtversionpolicy.withsbtrelease.ReleaseVersion val scroogeVersion = "22.1.0" -val thriftVersion = "0.15.0" +val thriftVersion = "0.19.0" val betaReleaseType = "beta" val betaReleaseSuffix = "-beta.0" -lazy val versionSettingsMaybe = { - sys.props.get("RELEASE_TYPE").map { - case v if v == betaReleaseType => betaReleaseSuffix - }.map { suffix => - releaseVersion := { - ver => Version(ver).map(_.withoutQualifier.string).map(_.concat(suffix)).getOrElse(versionFormatError(ver)) - } - }.toSeq -} - -lazy val mavenSettings = Seq( - pomExtra := ( - https://github.com/guardian/content-entity - - - LATaylor-guardian - Luke Taylor - https://github.com/LATaylor-guardian - - - tomrf1 - Tom Forbes - https://github.com/tomrf1 - - - justinpinner - Justin Pinner - https://github.com/justinpinner - - - ), - licenses := Seq("Apache V2" -> url("http://www.apache.org/licenses/LICENSE-2.0.html")), - publishTo := sonatypePublishToBundle.value, - publishConfiguration := publishConfiguration.value.withOverwrite(true) -) - -lazy val checkReleaseType: ReleaseStep = ReleaseStep({ st: State => - val releaseType = sys.props.get("RELEASE_TYPE").map { - case v if v == betaReleaseType => betaReleaseType.toUpperCase - }.getOrElse("PRODUCTION") - - SimpleReader.readLine(s"This will be a $releaseType release. Continue? [y/N]: ") match { - case Some(v) if Seq("Y", "YES").contains(v.toUpperCase) => // we don't care about the value - it's a flow control mechanism - case _ => sys.error(s"Release aborted by user!") - } - // we haven't changed state, just pass it on if we haven't thrown an error from above - st -}) - -lazy val releaseProcessSteps: Seq[ReleaseStep] = { - val commonSteps = Seq( - checkReleaseType, - checkSnapshotDependencies, - inquireVersions, - runClean, - runTest - ) - - val prodSteps: Seq[ReleaseStep] = Seq( - setReleaseVersion, - commitReleaseVersion, - tagRelease, - publishArtifacts, - releaseStepCommandAndRemaining("+publishSigned"), - releaseStepCommand("sonatypeBundleRelease"), - setNextVersion, - commitNextVersion, - pushChanges - ) - - /* - Beta assemblies can be published to Sonatype and Maven. - - To make this work, start SBT with the candidate RELEASE_TYPE variable set; - sbt -DRELEASE_TYPE=beta - - This gets around the "problem" of sbt-sonatype assuming that a -SNAPSHOT build should not be delivered to Maven. - - In this mode, the version number will be presented as e.g. 1.2.3.beta.n, but the git tagging and version-updating - steps are not triggered, so it's up to the developer to keep track of what was released and manipulate subsequent - release and next versions appropriately. - */ - val betaSteps: Seq[ReleaseStep] = Seq( - setReleaseVersion, - releaseStepCommandAndRemaining("+publishSigned"), - releaseStepCommand("sonatypeBundleRelease"), - setNextVersion - ) - - commonSteps ++ (sys.props.get("RELEASE_TYPE") match { - case Some(v) if v == betaReleaseType => betaSteps // this enables a beta build to sonatype and Maven - case None => prodSteps // our normal deploy route - }) - -} - -val commonSettings = Seq( +val artifactProductionSettings = Seq( organization := "com.gu", - scalaVersion := "2.13.2", + scalaVersion := "2.13.12", // scrooge 21.3.0: Builds are now only supported for Scala 2.12+ // https://twitter.github.io/scrooge/changelog.html#id11 - crossScalaVersions := Seq("2.12.11", scalaVersion.value), + crossScalaVersions := Seq("2.12.18", scalaVersion.value), releaseCrossBuild := true, - scmInfo := Some(ScmInfo(url("https://github.com/guardian/content-entity"), - "scm:git:git@github.com:guardian/content-entity.git")), - releasePublishArtifactsAction := PgpKeys.publishSigned.value -) ++ mavenSettings ++ versionSettingsMaybe + scalacOptions ++= Seq("-release:11"),// do we need these as well? - ("-feature", "-deprecation", "-unchecked", "-Xfatal-warnings") + licenses := Seq(License.Apache2), +) lazy val root = (project in file(".")) - .settings(commonSettings) + .settings(artifactProductionSettings) .aggregate(thrift, scalaClasses) .settings( - publishArtifact := false, - releaseProcess := releaseProcessSteps + publish / skip := true, + releaseVersion := ReleaseVersion.fromAggregatedAssessedCompatibilityWithLatestRelease().value, + releaseProcess := Seq[ReleaseStep]( + checkSnapshotDependencies, + inquireVersions, + runClean, + runTest, + setReleaseVersion, + commitReleaseVersion, + tagRelease, + setNextVersion, + commitNextVersion + ) ) lazy val scalaClasses = (project in file("scala")) - .settings(commonSettings) + .settings(artifactProductionSettings) .settings( name := "content-entity-model", description := "Scala library built from Content-entity thrift definition", - Compile / scroogeThriftSourceFolder := baseDirectory.value / "../thrift/src/main/thrift", Compile / scroogeThriftOutputFolder := sourceManaged.value, Compile / scroogePublishThrift := true, @@ -136,19 +51,19 @@ lazy val scalaClasses = (project in file("scala")) libraryDependencies ++= Seq( "org.apache.thrift" % "libthrift" % thriftVersion, "com.twitter" %% "scrooge-core" % scroogeVersion, - "org.scalacheck" %% "scalacheck" % "1.14.0" % "test" + "org.scalacheck" %% "scalacheck" % "1.17.0" % "test" ) ) lazy val thrift = (project in file("thrift")) - .settings(commonSettings) + .settings(artifactProductionSettings) .disablePlugins(ScroogeSBT) .settings( name := "content-entity-thrift", description := "Content entity model Thrift files", crossPaths := false, - packageDoc / publishArtifact := false, - packageSrc / publishArtifact := false, + packageDoc / publishArtifact := false, //do we need to remove this? also because if root is using "publish / skip := true" instead? + packageSrc / publishArtifact := false, //do we need to remove this? also because if root is using "publish / skip := true" instead? Compile / unmanagedResourceDirectories += { baseDirectory.value / "src/main/thrift" } ) @@ -163,10 +78,10 @@ lazy val npmBetaReleaseTagMaybe = lazy val typescriptClasses = (project in file("ts")) .enablePlugins(ScroogeTypescriptGen) - .settings(commonSettings) - .settings(npmBetaReleaseTagMaybe) + .settings(artifactProductionSettings) + .settings(npmBetaReleaseTagMaybe)//do we need to remove this? .settings( - publishArtifact := false, + publishArtifact := false, //do we need to remove this? also because if root is using "publish / skip := true" instead? name := "content-entity-typescript", scroogeTypescriptNpmPackageName := "@guardian/content-entity-model", Compile / scroogeDefaultJavaNamespace := scroogeTypescriptNpmPackageName.value, diff --git a/project/build.properties b/project/build.properties index baf5ff3..abbbce5 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=1.5.7 +sbt.version=1.9.8 diff --git a/project/plugins.sbt b/project/plugins.sbt index 9fb99db..a8c307b 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,8 +1,7 @@ addSbtPlugin("com.gu" % "sbt-scrooge-typescript" % "1.6.0") -addSbtPlugin("com.github.sbt" % "sbt-release" % "1.1.0") +addSbtPlugin("com.github.sbt" % "sbt-release" % "1.4.0") -addSbtPlugin("com.jsuereth" % "sbt-pgp" % "2.0.1") - -addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.10") +addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.10.0") +addSbtPlugin("ch.epfl.scala" % "sbt-version-policy" % "3.2.0") \ No newline at end of file From 92edec699f02e58e2b769f01761da44471754995 Mon Sep 17 00:00:00 2001 From: Divya Bhatt Date: Fri, 15 Mar 2024 09:34:46 +0000 Subject: [PATCH 2/5] Add ci.yml, add test entry in build sbt --- .github/workflows/ci.yml | 30 ++++++++++++++++++++++++++++++ build.sbt | 1 + 2 files changed, 31 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..2224e5e --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,30 @@ +name: CI +on: + workflow_dispatch: + pull_request: + + # triggering CI default branch improves caching + # see https://docs.github.com/en/free-pro-team@latest/actions/guides/caching-dependencies-to-speed-up-workflows#restrictions-for-accessing-a-cache + push: + branches: + - main + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup JDK + uses: actions/setup-java@v4 + with: + distribution: corretto + java-version: 11 + cache: sbt + - name: Build and Test + run: sbt compile + - name: Test Summary + uses: test-summary/action@v2 + with: + paths: "test-results/**/TEST-*.xml" + if: always() \ No newline at end of file diff --git a/build.sbt b/build.sbt index 438d614..6cf24d9 100644 --- a/build.sbt +++ b/build.sbt @@ -17,6 +17,7 @@ val artifactProductionSettings = Seq( releaseCrossBuild := true, scalacOptions ++= Seq("-release:11"),// do we need these as well? - ("-feature", "-deprecation", "-unchecked", "-Xfatal-warnings") licenses := Seq(License.Apache2), + Test / testOptions += Tests.Argument(TestFrameworks.ScalaTest, "-u", s"test-results/scala-${scalaVersion.value}", "-o") ) lazy val root = (project in file(".")) From d13a195a3569d27d007edaa4b87324dbf3fa8c9a Mon Sep 17 00:00:00 2001 From: Divya Bhatt Date: Mon, 18 Mar 2024 12:02:21 +0000 Subject: [PATCH 3/5] delete travis.yml --- .travis.yml | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 2f73140..0000000 --- a/.travis.yml +++ /dev/null @@ -1,14 +0,0 @@ -sudo: false -language: scala -scala: - - 2.13.2 - - 2.12.11 -jdk: - - openjdk8 -cache: - directories: - - $HOME/.sbt - - $HOME/.ivy2 -before_cache: - - find $HOME/.sbt -name "*.lock" -type f -delete -print - - find $HOME/.ivy2/cache -name "ivydata-*.properties" -type f -delete -print \ No newline at end of file From d93bb823dc2812e2b5143fa779fab3bc526e7047 Mon Sep 17 00:00:00 2001 From: Divya Bhatt Date: Mon, 18 Mar 2024 12:22:24 +0000 Subject: [PATCH 4/5] changes based on review --- .github/workflows/release.yml | 2 +- build.sbt | 19 +++---------------- 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a82370e..54bb5d6 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -30,7 +30,7 @@ jobs: registry-url: https://registry.npmjs.org - name: Release Typescript to NPM run: | - sbt "project typescript" "releaseNpm ${{ needs.scala-maven-release.outputs.RELEASE_VERSION }}" + sbt "project typescriptClasses" "releaseNpm ${{ needs.scala-maven-release.outputs.RELEASE_VERSION }}" env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} RELEASE_TYPE: ${{ needs.scala-maven-release.outputs.RELEASE_TYPE }} diff --git a/build.sbt b/build.sbt index 6cf24d9..0f0a06b 100644 --- a/build.sbt +++ b/build.sbt @@ -5,8 +5,6 @@ import sbtversionpolicy.withsbtrelease.ReleaseVersion val scroogeVersion = "22.1.0" val thriftVersion = "0.19.0" -val betaReleaseType = "beta" -val betaReleaseSuffix = "-beta.0" val artifactProductionSettings = Seq( organization := "com.gu", @@ -15,7 +13,7 @@ val artifactProductionSettings = Seq( // https://twitter.github.io/scrooge/changelog.html#id11 crossScalaVersions := Seq("2.12.18", scalaVersion.value), releaseCrossBuild := true, - scalacOptions ++= Seq("-release:11"),// do we need these as well? - ("-feature", "-deprecation", "-unchecked", "-Xfatal-warnings") + scalacOptions ++= Seq("-release:11"),// going ahead with release option only. We might add more options if any implementation comes in future : ("-feature", "-deprecation", "-unchecked", "-Xfatal-warnings") licenses := Seq(License.Apache2), Test / testOptions += Tests.Argument(TestFrameworks.ScalaTest, "-u", s"test-results/scala-${scalaVersion.value}", "-o") ) @@ -63,26 +61,15 @@ lazy val thrift = (project in file("thrift")) name := "content-entity-thrift", description := "Content entity model Thrift files", crossPaths := false, - packageDoc / publishArtifact := false, //do we need to remove this? also because if root is using "publish / skip := true" instead? - packageSrc / publishArtifact := false, //do we need to remove this? also because if root is using "publish / skip := true" instead? + publish / skip := true, Compile / unmanagedResourceDirectories += { baseDirectory.value / "src/main/thrift" } ) -lazy val npmBetaReleaseTagMaybe = - sys.props.get("RELEASE_TYPE").map { - case v if v == betaReleaseType => - // Why hard-code "beta" instead of using the value of the variable? That's to ensure it's always presented as - // --tag beta to the npm release process provided by the ScroogeTypescriptGen plugin regardless of how we identify - // a beta release here - scroogeTypescriptPublishTag := "beta" - }.toSeq - lazy val typescriptClasses = (project in file("ts")) .enablePlugins(ScroogeTypescriptGen) .settings(artifactProductionSettings) - .settings(npmBetaReleaseTagMaybe)//do we need to remove this? .settings( - publishArtifact := false, //do we need to remove this? also because if root is using "publish / skip := true" instead? + publish / skip := true, name := "content-entity-typescript", scroogeTypescriptNpmPackageName := "@guardian/content-entity-model", Compile / scroogeDefaultJavaNamespace := scroogeTypescriptNpmPackageName.value, From 70de1c231f61f20774cc5943f28cb741cee4f057 Mon Sep 17 00:00:00 2001 From: Divya Bhatt Date: Tue, 19 Mar 2024 15:50:27 +0000 Subject: [PATCH 5/5] releaseCrossVersion to go in root project settings --- build.sbt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sbt b/build.sbt index 0f0a06b..89a6fc7 100644 --- a/build.sbt +++ b/build.sbt @@ -12,7 +12,6 @@ val artifactProductionSettings = Seq( // scrooge 21.3.0: Builds are now only supported for Scala 2.12+ // https://twitter.github.io/scrooge/changelog.html#id11 crossScalaVersions := Seq("2.12.18", scalaVersion.value), - releaseCrossBuild := true, scalacOptions ++= Seq("-release:11"),// going ahead with release option only. We might add more options if any implementation comes in future : ("-feature", "-deprecation", "-unchecked", "-Xfatal-warnings") licenses := Seq(License.Apache2), Test / testOptions += Tests.Argument(TestFrameworks.ScalaTest, "-u", s"test-results/scala-${scalaVersion.value}", "-o") @@ -24,6 +23,7 @@ lazy val root = (project in file(".")) .settings( publish / skip := true, releaseVersion := ReleaseVersion.fromAggregatedAssessedCompatibilityWithLatestRelease().value, + releaseCrossBuild := true, releaseProcess := Seq[ReleaseStep]( checkSnapshotDependencies, inquireVersions,