From 52dfa5b5cf70f192b1f0d4e53f48a1a9b0bbda99 Mon Sep 17 00:00:00 2001 From: Divya Bhatt Date: Mon, 29 Jan 2024 15:54:17 +0000 Subject: [PATCH 1/4] Adopt gha-scala-rel-workflow in the project 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 --- .github/workflows/release.yml | 77 +++++---------------- build.sbt | 125 +++++++--------------------------- project/build.properties | 2 +- project/plugins.sbt | 13 ++-- 4 files changed, 51 insertions(+), 166 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8fe4917..427373c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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 }} \ No newline at end of file diff --git a/build.sbt b/build.sbt index ea6ec64..a7a3de8 100644 --- a/build.sbt +++ b/build.sbt @@ -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 := https://github.com/guardian/content-atom - - - paulmr - Paul Roberts - https://github.com/paulmr - - - LATaylor-guardian - Luke Taylor - https://github.com/LATaylor-guardian - - - mchv - Mariot Chauvin - https://github.com/mchv - - - tomrf1 - Tom Forbes - https://github.com/tomrf1 - - - annebyrne - Anne Byrne - https://github.com/annebyrne - - - regiskuckaertz - Regis Kuckaertz - https://github.com/regiskuckaertz - - - 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) -) - -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:git@github.com: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", @@ -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", @@ -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", diff --git a/project/build.properties b/project/build.properties index e8a1e24..abbbce5 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=1.9.7 +sbt.version=1.9.8 diff --git a/project/plugins.sbt b/project/plugins.sbt index 6c2993b..c3be74d 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -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") + + + + + From 7b6ef435ba737b65c1c93adaa5d5e5904ee095bb Mon Sep 17 00:00:00 2001 From: Divya Bhatt Date: Mon, 29 Jan 2024 16:20:38 +0000 Subject: [PATCH 2/4] Change readme to reflect gha-scala-rel process --- README.md | 45 ++++----------------------------------------- 1 file changed, 4 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index b9ba03d..1854b5d 100644 --- a/README.md +++ b/README.md @@ -28,45 +28,8 @@ Prior to releasing, you will need to ensure that: for publishing to Maven and Sonatype -#### Non-production releases (Sonatype only): +#### How to make releases (maven and npm): -The easiest way to release a snapshot version is via the github UI. -[This](https://github.com/guardian/content-api-firehose-client/pull/28/373) PR introduced the ability to use a github action to trigger the release. - -The steps you should take are: -- Push the branch with the changes you want to release to Github. -- [Click here](https://github.com/guardian/content-api-firehose-client/releases/new?prerelease=true) to create prerelease using Github releases. - -- You must then: -- Set the Target to your branch. -- Create a tag for the snapshot release (the tag can be created from this same UI if it doesn't already exist). -- The tag should ideally have format "vX.X.X-SNAPSHOT". -- Double-check that the "Set as pre-release" box is ticket. -- To automatically release the snapshot to sonatype then click the "Publish release" button. - -And then manually release the npm module: -`npm i -g typescript && sbt 'project typescriptClasses; releaseNpm X.X.X-SNAPSHOT'` - - -#### Production releases (Sonatype and NPM): - -When your changes are done and tested and you're ready to release a new production version, edit the `version.sbt` file to reflect the version you are about to release. - -Typically this should just require the removal of the -SNAPSHOT part, but check in [maven](https://repo1.maven.org/maven2/com/gu/content-api-firehose-client_2.13/) to make sure nobody else has released this version before you. - -Open a PR. - -When your PR is approved, merge it to `main` and ensure the build actions complete successfully. - -Then, on the [releases](https://github.com/guardian/content-api-firehose-client/releases) page: -- Choose `Draft a new release` -- Create a new tag of the version number e.g. `v1.0.10` -- Set the target to the `main` branch -- Add a release title (the version number again is fine) -- Add an optional description -- Ensure that `Set as pre-release` is **unchecked** -- Click the `Publish release` button - -When the release process has finished, pull the updated `main` branch locally and update the `version.sbt` file to reflect the next build number, e.g. `1.0.11-SNAPSHOT` and commit that directly back to `main` - there's no need to open a PR for that. - -When your release shows up on [maven](https://repo1.maven.org/maven2/com/gu/content-api-firehose-client_2.13/) the updated version can be referenced in client code. +This repo uses [`gha-scala-library-release-workflow`](https://github.com/guardian/gha-scala-library-release-workflow) +to automate publishing releases (both full & preview releases) - see +[**Making a Release**](https://github.com/guardian/gha-scala-library-release-workflow/blob/main/docs/making-a-release.md). \ No newline at end of file From 639196cd2e06cc215cb1a5dfcf3aa1943326cf6f Mon Sep 17 00:00:00 2001 From: Divya Bhatt Date: Tue, 30 Jan 2024 17:16:21 +0000 Subject: [PATCH 3/4] typescript name updated and so as readme after reviewed by Roberto. --- .github/workflows/release.yml | 2 +- README.md | 20 +------------------- 2 files changed, 2 insertions(+), 20 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 427373c..7f99fe1 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -29,7 +29,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 }} \ No newline at end of file diff --git a/README.md b/README.md index 1854b5d..cd5e71c 100644 --- a/README.md +++ b/README.md @@ -9,26 +9,8 @@ This is the Thrift definition of the Content Atom model, and the published versi In order for the scala code generated from the thrift definitions to be packaged correctly a scala namespace needs to be included. For example for the chart atom this would be: `#@namespace scala com.gu.contentatom.thrift.atom.chart` -## How to release -### A note on version numbers - -The version field in `package.json` should be kept in sync with the version in `version.sbt` - -### Prerequisites - -Prior to releasing, you will need to ensure that: - - `tsc` is installed on your machine (e.g. `brew install typescript`) - - `npm` is installed on your machine - - you have an NPM account which is part of the [@guardian](https://www.npmjs.com/org/guardian) org - - you have configured an NPM [access token](https://docs.npmjs.com/creating-and-viewing-authentication-tokens) to - publish to @guardian; a convenient way to set this up is to execute `npm login` locally and follow the prompts; - this will create/append to an `~/.npmrc` file with the sufficient config - - you have the followed the [guide](https://docs.google.com/document/d/1rNXjoZDqZMsQblOVXPAIIOMWuwUKe3KzTCttuqS7AcY/edit) - for publishing to Maven and Sonatype - - -#### How to make releases (maven and npm): +## How to make releases (maven and npm): This repo uses [`gha-scala-library-release-workflow`](https://github.com/guardian/gha-scala-library-release-workflow) to automate publishing releases (both full & preview releases) - see From 44bc7d983b0d03144240a149b621d3d19ac41538 Mon Sep 17 00:00:00 2001 From: Divya Date: Wed, 6 Mar 2024 14:48:34 +0000 Subject: [PATCH 4/4] Update .github/workflows/release.yml looks great Co-authored-by: Roberto Tyley --- .github/workflows/release.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7f99fe1..d96bde3 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -11,6 +11,7 @@ jobs: 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