Skip to content

Commit

Permalink
Adopt GHA Scala Library Release Workflow
Browse files Browse the repository at this point in the history
This replaces the old release process which had developers manually running
`sbt release` on their own laptops - each developer had to obtain their own
PGP key and Sonatype credentials, which was an elaborate & fiddly process.

Now there's a single set of release credentials, available through GitHub
Organisation Secrets, like we already have with NPM.

The changes required to adopt the automated workflow:

* No need to set these sbt configuration keys, as they're now taken
  care of by the workflow:
  * `scmInfo` & `pomExtra`
  * `homepage`
  * `developers`
  * `releasePublishArtifactsAction`
  * `publishTo`
* Remove the publish, release & push steps of sbt-release's
  `releaseProcess` configuration, because the workflow does those now, and
  the workflow only wants `sbt release` to create the versioning commits,
  and tag them appropriately. The workflow does the rest itself.
* Remove `sbt-pgp` plugin because it's no longer used - the workflow does the signing using `gpg` directly.
* Grant this repo access to the GitHub Organisation Secrets containing the Maven Release
  credentials with guardian/github-secret-access#21

Additionally, we add **automatic version numbering** based on compatibility assessment performed by `sbt-version-policy`:

* Add the `sbt-version-policy` plugin, to allow it to do the compatibility assessment. This also sets the `versionScheme` for this library to `early-semver`, which is the recommended versioning for Scala libraries, and `sbt-version-policy` & correct sbt-eviction-issue-detection pretty much depend on the `versionScheme` being `early-semver`. Thus we also need to switch to using a new semver version number for our library version!
* Add the `releaseVersion := fromAggregatedAssessedCompatibilityWithLatestRelease().value` sbt setting, which will intelligently set the release version based on `sbt-version-policy`'s compatibility assessment, thanks to scalacenter/sbt-version-policy#187 .

This change also drops support for Scala 2.11 since it does not seem to support the -release:11 scalac option which is required to ensure that the Java 17 workflow produces Java 11 compatible bytecode.
  • Loading branch information
davidfurey committed Feb 20, 2024
1 parent 9ea85f1 commit 7bf5fce
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 24 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Release

on:
workflow_dispatch:

jobs:
release:
uses: guardian/gha-scala-library-release-workflow/.github/workflows/reusable-release.yml@main
permissions:
contents: write
secrets:
AUTOMATED_MAVEN_RELEASE_PGP_SECRET: ${{ secrets.AUTOMATED_MAVEN_RELEASE_PGP_SECRET }}
AUTOMATED_MAVEN_RELEASE_SONATYPE_PASSWORD: ${{ secrets.AUTOMATED_MAVEN_RELEASE_SONATYPE_PASSWORD }}
19 changes: 6 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# tags-thrift-schema
# tags-thrift-schema [![Release](https://github.com/guardian/tags-thrift-schema/actions/workflows/release.yml/badge.svg)](https://github.com/guardian/tags-thrift-schema/actions/workflows/release.yml)

This repository contains the Thrift schema required for interaction with [guardian/tagmanager](https://github.com/guardian/tagmanager).

Expand All @@ -14,16 +14,9 @@ If you need to try out your changes with consumer applications (e.g. `tagmanager
- Run `+publishLocal` in sbt (note the `+` makes it cross-compile, e.g. `tagmanager` consumes the 2.11 version)
- Update the version in the consumer application(s) (e.g. https://github.com/guardian/tagmanager/blob/e47465cbbcdf9e3d3312c5c779eb52fe0676ce4a/build.sbt#L29) using the `-SNAPSHOT` version.

### Publishing a new version

1. Follow the instructions for [publishing a new version to Maven Central via Sonatype](https://docs.google.com/document/d/1rNXjoZDqZMsQblOVXPAIIOMWuwUKe3KzTCttuqS7AcY/edit#).
This will include (if not already completed for another project):
- Creating and publishing a PGP key
- Setting up an account on Sonatype and having it added to the `com.gu` group
- Storing your Sonatype credentials in your global sbt configuration
2. Ensure you're on the branch which holds the changes you're ready to release and that these changes have been approved & tested with the application(s) which use this library (using the `-SNAPSHOT` version).
3. Ensure the project still builds with `sbt compile`
4. Run `sbt release`. You will be prompted for a 'release version' – which you should set following semantic versioning as either a patch,
minor or major version bump. You will also be prompted for a 'next version' – which should be a patch version ahead of your release version
and end `-SNAPSHOT`. `version.sbt` will be updated to reflect this 'next version'.
## Building a release

This project uses the [`gha-scala-library-release-workflow`](https://github.com/guardian/gha-scala-library-release-workflow)
to release to Maven Central. To release a new version, execute the
[Release](https://github.com/guardian/tags-thrift-schema/actions/workflows/release.yml)
workflow in the Actions tab on GitHub.
17 changes: 7 additions & 10 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
import ReleaseTransformations._
import sbtversionpolicy.withsbtrelease.ReleaseVersion.fromAggregatedAssessedCompatibilityWithLatestRelease

name := "tags-thrift-schema"
organization := "com.gu"

scmInfo := Some(ScmInfo(url("https://github.com/guardian/tags-thrift-schema"), "scm:[email protected]:guardian/tags-thrift-schema"))
homepage := scmInfo.value.map(_.browseUrl)
developers := List(Developer(id = "guardian", name = "Guardian", email = null, url = url("https://github.com/guardian")))


libraryDependencies ++= Seq(
"org.apache.thrift" % "libthrift" % "0.13.0",
"com.twitter" %% "scrooge-core" % "19.11.0"
)

// Might cross compile more scala versions here depending on who needs this!
scalaVersion := "2.13.1"
crossScalaVersions := Seq("2.11.12", "2.12.10", scalaVersion.value)
scalaVersion := "2.13.11"
crossScalaVersions := Seq("2.12.18", scalaVersion.value)
scalacOptions := Seq(
"-release:11"
)
releaseCrossBuild := true

resolvers += Resolver.jcenterRepo

licenses += ("Apache-2.0", url("https://github.com/guardian/tags-thrift-schema/blob/main/LICENSE"))

releasePublishArtifactsAction := PgpKeys.publishSigned.value
publishTo := sonatypePublishTo.value
releaseVersion := fromAggregatedAssessedCompatibilityWithLatestRelease().value

releaseProcess := Seq[ReleaseStep](
checkSnapshotDependencies,
Expand Down
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Plugin to actually build the thrift
addSbtPlugin("com.twitter" %% "scrooge-sbt-plugin" % "19.11.0")
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "2.0.1")
addSbtPlugin("ch.epfl.scala" % "sbt-version-policy" % "3.2.0")
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.4")
addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.13")

0 comments on commit 7bf5fce

Please sign in to comment.