Skip to content

Commit

Permalink
Adopt gha-scala-rel-workflow in the project
Browse files Browse the repository at this point in the history
gha-scala process ref: https://github.com/guardian/gha-scala-library-release-workflow/blob/main/docs/configuration.md

Since it requires release on both maven and npm. hence we have taken npm release changes from content-api-models. ref:https://github.com/guardian/content-api-models/blob/main/.github/workflows/release.yml
  • Loading branch information
Divs-B committed Jan 29, 2024
1 parent dcf0568 commit d6e4687
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 166 deletions.
77 changes: 18 additions & 59 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,76 +1,35 @@
name: Release Sonatype
name: Release

on:
release:
types: [published]
workflow_dispatch:

jobs:
release_snapshot_sonatype:
if: "github.event.release.prerelease"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
base: main #see https://github.com/peter-evans/create-pull-request/blob/main/docs/concepts-guidelines.md#pull-request-events
- uses: actions/setup-java@v3
with:
distribution: corretto
java-version: 11
cache: sbt
- name: Release Snapshot (prerelease) to Sonatype
run: |
VERSION=$(git describe --tags | cut -f2 -d"@")
if [[ ${VERSION:0:1} == "v" ]] ; then
VERSION=${VERSION:1}
fi
if [[ ${VERSION: -9} != "-SNAPSHOT" ]] ; then
echo "Version must end in -SNAPSHOT. Adding -SNAPSHOT suffix"
VERSION="$VERSION-SNAPSHOT"
fi
echo $PGP_SECRET | base64 --decode | gpg --batch --import
export GPG_TTY=$(tty)
echo "Releasing version $VERSION Sonatype as snapshot"
yes | sbt -DRELEASE_TYPE=snapshot "clean" "release cross release-version $VERSION with-defaults"
env:
PGP_SECRET: ${{ secrets.PGP_SECRET }}
PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }}
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
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 }}

release_production_sonatype:
if: "! github.event.release.prerelease"
typescript-npm-release:
name: NPM Release
needs: scala-maven-release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
base: main #see https://github.com/peter-evans/create-pull-request/blob/main/docs/concepts-guidelines.md#pull-request-events
- uses: actions/setup-java@v3
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: corretto
java-version: 11
cache: sbt
- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
registry-url: https://registry.npmjs.org
- name: Release Production to Sonatype and NPM
- name: Release Typescript to NPM
run: |
VERSION=$(git describe --tags | cut -f2 -d"@")
if [[ ${VERSION:0:1} == "v" ]] ; then
VERSION=${VERSION:1}
fi
if [[ ${VERSION: -9} == "-SNAPSHOT" ]] ; then
echo "Version must NOT end in -SNAPSHOT."
exit 1
fi
echo $PGP_SECRET | base64 --decode | gpg --batch --import
export GPG_TTY=$(tty)
echo "Releasing version $VERSION Sonatype as production"
yes | sbt -DRELEASE_TYPE=production "clean" "release cross release-version $VERSION with-defaults" "project typescriptClasses" "releaseNpm $VERSION"
sbt "project typescript" "releaseNpm ${{ needs.scala-maven-release.outputs.RELEASE_VERSION }}"
env:
PGP_SECRET: ${{ secrets.PGP_SECRET }}
PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }}
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
RELEASE_TYPE: ${{ needs.scala-maven-release.outputs.RELEASE_TYPE }}
125 changes: 24 additions & 101 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -5,117 +5,40 @@ val contentEntityVersion = "2.2.1"
val scroogeVersion = "22.1.0" // remember to also update plugins.sbt if the scrooge version changes
val thriftVersion = "0.15.0" // remember to also update package.json if the thrift version changes

//https://github.com/xerial/sbt-sonatype/issues/103
publishTo := sonatypePublishToBundle.value

lazy val mavenSettings = Seq(
pomExtra := <url>https://github.com/guardian/content-atom</url>
<developers>
<developer>
<id>paulmr</id>
<name>Paul Roberts</name>
<url>https://github.com/paulmr</url>
</developer>
<developer>
<id>LATaylor-guardian</id>
<name>Luke Taylor</name>
<url>https://github.com/LATaylor-guardian</url>
</developer>
<developer>
<id>mchv</id>
<name>Mariot Chauvin</name>
<url>https://github.com/mchv</url>
</developer>
<developer>
<id>tomrf1</id>
<name>Tom Forbes</name>
<url>https://github.com/tomrf1</url>
</developer>
<developer>
<id>annebyrne</id>
<name>Anne Byrne</name>
<url>https://github.com/annebyrne</url>
</developer>
<developer>
<id>regiskuckaertz</id>
<name>Regis Kuckaertz</name>
<url>https://github.com/regiskuckaertz</url>
</developer>
<developer>
<id>justinpinner</id>
<name>Justin Pinner</name>
<url>https://github.com/justinpinner</url>
</developer>
</developers>,
licenses := Seq("Apache V2" -> url("http://www.apache.org/licenses/LICENSE-2.0.html")),
publishTo := sonatypePublishToBundle.value,
publishConfiguration := publishConfiguration.value.withOverwrite(true)
)

val snapshotReleaseType = "snapshot"

lazy val releaseProcessSteps: Seq[ReleaseStep] = {
val commonSteps:Seq[ReleaseStep] = Seq(
checkSnapshotDependencies,
inquireVersions,
runClean,
runTest,
setReleaseVersion,
)

val localExtraSteps:Seq[ReleaseStep] = Seq(
commitReleaseVersion,
tagRelease,
publishArtifacts,
setNextVersion,
commitNextVersion
)

val snapshotSteps:Seq[ReleaseStep] = Seq(
publishArtifacts,
releaseStepCommand("sonatypeReleaseAll")
)

val prodSteps:Seq[ReleaseStep] = Seq(
releaseStepCommandAndRemaining("+publishSigned"),
releaseStepCommand("sonatypeBundleRelease")
)

val localPostRelease:Seq[ReleaseStep] = Seq(
pushChanges,
)

(sys.props.get("RELEASE_TYPE"), sys.env.get("CI")) match {
case (Some(v), None) if v == snapshotReleaseType => commonSteps ++ localExtraSteps ++ snapshotSteps ++ localPostRelease
case (_, None) => commonSteps ++ localExtraSteps ++ prodSteps ++ localPostRelease
case (Some(v), _) if v == snapshotReleaseType => commonSteps ++ snapshotSteps
case (_, _)=> commonSteps ++ prodSteps
}
}

val commonSettings = Seq(
val artifactProductionSettings = Seq(
organization := "com.gu",
scalaVersion := "2.13.2",
scalaVersion := "2.13.12",
// downgrade scrooge reserved word clashes to warnings
Compile / scroogeDisableStrict := true,
// Scrooge 21.3.0 dropped support for scala < 2.12, so we can only build for Scala 2.12+
// https://twitter.github.io/scrooge/changelog.html#id11
crossScalaVersions := Seq("2.12.11", scalaVersion.value),
scmInfo := Some(ScmInfo(url("https://github.com/guardian/content-atom"),
"scm:git:[email protected]:guardian/content-atom.git")),
releasePublishArtifactsAction := PgpKeys.publishSigned.value,
) ++ mavenSettings
crossScalaVersions := Seq("2.12.18", scalaVersion.value),
licenses := Seq(License.Apache2)
/*
Test / testOptions +=
Tests.Argument(TestFrameworks.ScalaTest, "-u", s"test-results/scala-${scalaVersion.value}", "-o")
*/ // Need to uncomment when testcases gets added.Also to change ci.yml to add "Build and Test" as well.
)

lazy val root = Project(id = "root", base = file("."))
.settings(commonSettings)
.aggregate(thrift, scalaClasses)
.settings(
publishArtifact := false,
releaseProcess := releaseProcessSteps
publish / skip := true,
releaseProcess := Seq[ReleaseStep](
checkSnapshotDependencies,
inquireVersions,
runClean,
runTest,
setReleaseVersion,
commitReleaseVersion,
tagRelease,
setNextVersion,
commitNextVersion
)
)

lazy val thrift = Project(id = "content-atom-model-thrift", base = file("thrift"))
.settings(commonSettings)
.settings(artifactProductionSettings)
.disablePlugins(ScroogeSBT)
.settings(
description := "Content atom model Thrift files",
Expand All @@ -127,7 +50,7 @@ lazy val thrift = Project(id = "content-atom-model-thrift", base = file("thrift"
)

lazy val scalaClasses = Project(id = "content-atom-model", base = file("scala"))
.settings(commonSettings)
.settings(artifactProductionSettings)
.settings(
description := "Scala library built from Content-atom thrift definition",
Compile / scroogeThriftSourceFolder := baseDirectory.value / "../thrift/src/main/thrift",
Expand All @@ -147,7 +70,7 @@ lazy val scalaClasses = Project(id = "content-atom-model", base = file("scala"))

lazy val typescriptClasses = (project in file("ts"))
.enablePlugins(ScroogeTypescriptGen)
.settings(commonSettings)
.settings(artifactProductionSettings)
.settings(
name := "content-atom-typescript",
scroogeTypescriptNpmPackageName := "@guardian/content-atom-model",
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.9.7
sbt.version=1.9.8
13 changes: 8 additions & 5 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.1.2")
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.10")
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.10.0")
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.7.0")
addSbtPlugin("com.github.sbt" % "sbt-release" % "1.1.0")

addSbtPlugin("com.github.sbt" % "sbt-release" % "1.4.0")
addSbtPlugin("com.twitter" % "scrooge-sbt-plugin" % "22.1.0")

addSbtPlugin("com.gu" % "sbt-scrooge-typescript" % "1.6.0")
addSbtPlugin("ch.epfl.scala" % "sbt-version-policy" % "3.2.0")





0 comments on commit d6e4687

Please sign in to comment.