Skip to content

Commit

Permalink
Move to gha-scala-library-release-workflow as a means of releasing ne…
Browse files Browse the repository at this point in the history
…w versions
  • Loading branch information
rhystmills committed Jun 26, 2024
1 parent d919f86 commit b8eee77
Show file tree
Hide file tree
Showing 16 changed files with 75 additions and 321 deletions.
37 changes: 0 additions & 37 deletions .github/workflows/changesets.yaml

This file was deleted.

54 changes: 0 additions & 54 deletions .github/workflows/release-snapshot.yaml

This file was deleted.

36 changes: 36 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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_TOKEN: ${{ secrets.AUTOMATED_MAVEN_RELEASE_SONATYPE_TOKEN }}
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 tsApiModels" "releaseNpm ${{ needs.scala-maven-release.outputs.RELEASE_VERSION }}"
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
RELEASE_TYPE: ${{ needs.scala-maven-release.outputs.RELEASE_TYPE }}
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
java corretto-11.0.23.9.1
66 changes: 0 additions & 66 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,72 +8,6 @@ This project contains Thrift models and a way to publish them as Scala and TypeS
- MAPI (uses the Scala package): https://github.com/guardian/mobile-apps-api
- Apps-Rendering (uses the TypeScript package): https://github.com/guardian/dotcom-rendering/tree/main/apps-rendering

## How to release to NPM and Sonatype

This repository uses [`changesets`](https://github.com/changesets/changesets) to manage versions and releases.

To create a changeset, ensure you are using the correct Node (and associated npm) version defined in [`.nvmrc`](./.nvmrc) and project dependencies installed by running `npm install`. Then:

- Run `npx changeset`. Select the type of change and enter a description
- Commit and push the changeset file to your branch
- When your feature PR is merged to `main`, the [changesets action](.github/workflows/changesets.yaml) will open a PR against `main` with the details of all unreleased changes. This is a "Release PR"
- When ready to release, merge the Release PR

### Diagram

```mermaid
flowchart TD
Title([Releasing a new version])
Title ~~~ AddChangeset
AddChangeset[Add changeset to your branch]
GHBranchActions[Create and merge PR]
GHA[GitHub Actions]
ReleasePR[Release PR]
GHA2[GitHub Actions]
ReleaseNPM[Release to NPM]
ReleaseSonatype[Release to Sonatype]
AddChangeset-->GHBranchActions-.triggers.->GHA-.opens.->ReleasePR--merge-->GHA2
GHA2-.->ReleaseNPM
GHA2-.->ReleaseSonatype
```

## How to release a Snapshot to NPM and Sonatype

- Push the branch with the changes you want to test to GitHub
- [**Click here**](https://github.com/guardian/apps-rendering-api-models/releases/new?prerelease=true) to create a **Prerelease** using GitHub Releases
- Set the Target to your branch
- You must also create a tag for the snapshot release. Use the following format: `v0.0.0-YYYY-MM-DD-SNAPSHOT`. For example, `v0.0.0-2022-10-20-SNAPSHOT`. It is important the tag **begins** with `v` and **ends** with `-SNAPSHOT`.
- Make sure the "Set as pre-release" box is ticked:
- <img src="docs/assets/prerelease.png" width="500" />
- To automatically release the snapshot to `npm` and `sonatype`, publish the prerelease
- Snapshots are released to the `snapshot` tag on `npm`. You can install them with `npm install @guardian/apps-rendering-api-models@snapshot`

### Diagram

```mermaid
flowchart TD
Title([Releasing a Snapshot])
Title ~~~ PushBranch
PushBranch[Push branch]
CreatePrerelease[Create & Publish a prerelease in GitHub]
Info>Tag must end in '-SNAPSHOT']
PushBranch -- then --> CreatePrerelease
Info -.-> CreatePrerelease
GHA[GitHub Action]
CreatePrerelease -. triggers .-> GHA
Sonatype[Publish to Sonatype]
NPM[Publish to NPM]
GHA-.->Sonatype
GHA-.->NPM
```

## How to run the tests

If you run `sbt test` it will fail, you can only run `sbt compile` to check that it's working correctly. This project doesn't have tests because it's used to auto-generate Scala and TypeScript packages from Thrift definitions, there's no Scala or TS source code.
73 changes: 34 additions & 39 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import ReleaseTransformations._
import sbtversionpolicy.withsbtrelease.ReleaseVersion

val contentEntityVersion = "3.0.3"
val contentAtomVersion = "4.0.0"
Expand Down Expand Up @@ -27,17 +28,44 @@ lazy val commonSettings = Seq(
Compile / scroogeThriftDependencies ++= scroogeDependencies,
)

ThisBuild / organization := "com.gu"
ThisBuild / scalaVersion := "2.13.11"
ThisBuild / licenses += ("Apache-2.0", url("https://www.apache.org/licenses/LICENSE-2.0.html"))
val artifactProductionSettings = Seq(
organization := "com.gu",
scalaVersion := "2.13.14",
// 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),
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")
)

lazy val root = (project in file("."))
.settings(artifactProductionSettings)
.aggregate(scalaApiModels)
.settings(
publish / skip := true,
releaseVersion := ReleaseVersion.fromAggregatedAssessedCompatibilityWithLatestRelease().value,
releaseCrossBuild := true,
releaseProcess := Seq[ReleaseStep](
checkSnapshotDependencies,
inquireVersions,
runClean,
runTest,
setReleaseVersion,
commitReleaseVersion,
tagRelease,
setNextVersion,
commitNextVersion
)
)

lazy val scalaApiModels = project.in(file("models") / "scala")
.settings(commonSettings)
.settings(
name := "apps-rendering-api-models",
scalacOptions := Seq("-release:11"),

crossScalaVersions := Seq(scalaVersion.value, "2.12.17"),
releaseCrossBuild := true,
crossScalaVersions := Seq(scalaVersion.value, "2.12.19"),

Compile / scroogeLanguages := Seq("scala"),

Expand All @@ -46,39 +74,6 @@ lazy val scalaApiModels = project.in(file("models") / "scala")
"com.twitter" %% "scrooge-core" % "22.1.0",
"com.gu" %% "content-api-models-scala" % contentApiModelsVersion
) ++ libraryDeps,

publishTo := sonatypePublishToBundle.value,

scmInfo := Some(ScmInfo(
url("https://github.com/guardian/apps-rendering-api-models"),
"scm:git:git@github.com:guardian/apps-rendering-api-models.git"
)),

homepage := Some(url("https://github.com/guardian/apps-rendering-api-models")),

developers := List(Developer(
id = "Guardian",
name = "Guardian",
email = null,
url = url("https://github.com/guardian")
)),

releaseProcess := {
val process = Seq[ReleaseStep](
checkSnapshotDependencies,
inquireVersions,
runClean,
runTest,
setReleaseVersion,
releaseStepCommandAndRemaining("+publishSigned"),
)

if (!isSnapshot.value) {
process ++ Seq[ReleaseStep](releaseStepCommand("sonatypeBundleRelease"))
} else {
process
}
}
)

lazy val tsApiModels = project.in(file("models") / "ts")
Expand All @@ -90,7 +85,7 @@ lazy val tsApiModels = project.in(file("models") / "ts")
Compile / scroogeDefaultJavaNamespace := scroogeTypescriptNpmPackageName.value,

scroogeTypescriptPackageLicense := "Apache-2.0",
Compile / scroogeLanguages := Seq("typescript"),
Compile / scroogeLanguages := Seq("typescript"),

scroogeTypescriptPackageMapping := Map(
"content-api-models" -> "@guardian/content-api-models",
Expand Down
6 changes: 3 additions & 3 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ addSbtPlugin("com.twitter" % "scrooge-sbt-plugin" % "22.1.0")

addSbtPlugin("com.gu" % "sbt-scrooge-typescript" % "2.0.0")

addSbtPlugin("com.github.sbt" % "sbt-release" % "1.1.0")
addSbtPlugin("com.github.sbt" % "sbt-release" % "1.4.0")

addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.2.1")
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.10.0")

addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.21")
addSbtPlugin("ch.epfl.scala" % "sbt-version-policy" % "3.2.1")

addDependencyTreePlugin
3 changes: 0 additions & 3 deletions scripts/ci/configure-gpg.sh

This file was deleted.

3 changes: 0 additions & 3 deletions scripts/ci/get-version.sh

This file was deleted.

12 changes: 0 additions & 12 deletions scripts/ci/release-both.sh

This file was deleted.

21 changes: 0 additions & 21 deletions scripts/ci/release-npm.sh

This file was deleted.

13 changes: 0 additions & 13 deletions scripts/ci/release-snapshot-npm.sh

This file was deleted.

Loading

0 comments on commit b8eee77

Please sign in to comment.