From 7038ff05e9b65a4c806eb1699ade9709e06351ef Mon Sep 17 00:00:00 2001 From: Jonathon Herbert Date: Mon, 9 Oct 2023 13:38:16 +0100 Subject: [PATCH 01/11] Add workflow for release via gh actions taken from: https://github.com/guardian/content-api-firehose-client/blob/main/.github/workflows/release-snapshot.yml --- .github/workflows/release.yml | 70 +++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..91a88bd8 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,70 @@ +name: Release Sonatype + +on: + release: + types: [published] + +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 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 }} + + release_production_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 Production 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 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" + env: + PGP_SECRET: ${{ secrets.PGP_SECRET }} + PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }} + SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} + SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} From 1da6d8b11de6cebe7557828fb18fe3926221d76c Mon Sep 17 00:00:00 2001 From: Jonathon Herbert Date: Mon, 9 Oct 2023 14:28:33 +0100 Subject: [PATCH 02/11] First pass at GHA workflow --- .github/workflows/release.yml | 40 ++++++++++++++++++++++++++--------- .nvmrc | 1 + 2 files changed, 31 insertions(+), 10 deletions(-) create mode 100644 .nvmrc diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 91a88bd8..2f9b9a80 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -17,20 +17,34 @@ jobs: distribution: corretto java-version: 11 cache: sbt - - name: Release Snapshot to Sonatype + - uses: actions/setup-node@v3 + with: + node-version-file: .nvmrc + cache: npm + - name: Release pre-release version to Sonatype and NPM run: | - VERSION=$(git describe --tags | cut -f2 -d"@") - if [[ ${VERSION:0:1} == "v" ]] ; then - VERSION=${VERSION:1} + BASE_VERSION=$(git describe --tags | cut -f2 -d"@") + + # Because NPM releases are not mutable, and it'd be difficult to generate a suffix for a beta-release, + # we must ask the user to supply the NPM version for pre-release. + if [[ ! $BASE_VERSION =~ (alpha|beta) ]] ; then + echo "Received $BASE_VERSION, but for pre-release, the version number must be an npm-compatible alpha or beta release - please label preleases in an npm-compatible format, e.g. 17.7.0-alpha.0, 20.25.1-beta.5" + exit 1 fi - if [[ ${VERSION: -9} != "-SNAPSHOT" ]] ; then - echo "Version must end in -SNAPSHOT. Adding -SNAPSHOT suffix" - VERSION="$VERSION-SNAPSHOT" + + if [[ ${BASE_VERSION:0:1} == "v" ]] ; then + BASE_VERSION=${BASE_VERSION:1} fi + + # For Sonatype releases, we remove the beta prefix from the version, and add -SNAPSHOT instead. + SONATYPE_VERSION=$(echo "$BASE_VERSION" | sed -e "s/-(alpha|beta)\.[[:digit:]]*//g")-SNAPSHOT + + NPM_VERSION="$BASE_VERSION" + 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" + echo "Releasing version $BASE_VERSION as pre-release to Sonatype as $SONATYPE_VERSION and NPM as $BASE_VERSION" + echo "yes | sbt -DRELEASE_TYPE=snapshot \"clean\" \"release cross release-version $SONATYPE_VERSION with-defaults\" \"typescript/releaseNpm $NPM_VERSION\"" env: PGP_SECRET: ${{ secrets.PGP_SECRET }} PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }} @@ -49,20 +63,26 @@ jobs: distribution: corretto java-version: 11 cache: sbt + - uses: actions/setup-node@v3 + with: + node-version-file: .nvmrc + cache: npm - name: Release Production 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 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" + yes | sbt -DRELEASE_TYPE=production "clean" "release cross release-version $VERSION with-defaults" "typescript/releaseNpm $VERSION" env: PGP_SECRET: ${{ secrets.PGP_SECRET }} PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }} diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 00000000..3d325430 --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +20.8.0 From 250187c4f287567ceb4cfe681469648a2b41419e Mon Sep 17 00:00:00 2001 From: Jonathon Herbert Date: Mon, 9 Oct 2023 15:25:25 +0100 Subject: [PATCH 03/11] Remove npm cache, which relies on a non-existent lockfile --- .github/workflows/release.yml | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2f9b9a80..c513555d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,12 +1,16 @@ -name: Release Sonatype +name: Publish to Sonatype and NPM on: + workflow_dispatch: + push: + branches: + - 'jsh/release-via-gh-actions' release: types: [published] jobs: release_snapshot_sonatype: - if: "github.event.release.prerelease" + # if: "github.event.release.prerelease || github.event_name == 'workflow_dispatch'" runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -20,13 +24,15 @@ jobs: - uses: actions/setup-node@v3 with: node-version-file: .nvmrc - cache: npm + # We cannot cache our environment, as it is dynamically generated by the plugin + - name: Get tags + run: git fetch --tags origin - name: Release pre-release version to Sonatype and NPM run: | - BASE_VERSION=$(git describe --tags | cut -f2 -d"@") + BASE_VERSION=17.7.0-beta.0 # Because NPM releases are not mutable, and it'd be difficult to generate a suffix for a beta-release, - # we must ask the user to supply the NPM version for pre-release. + # we must ask the user to supply the NPM-compatible version for pre-release. if [[ ! $BASE_VERSION =~ (alpha|beta) ]] ; then echo "Received $BASE_VERSION, but for pre-release, the version number must be an npm-compatible alpha or beta release - please label preleases in an npm-compatible format, e.g. 17.7.0-alpha.0, 20.25.1-beta.5" exit 1 @@ -37,14 +43,14 @@ jobs: fi # For Sonatype releases, we remove the beta prefix from the version, and add -SNAPSHOT instead. - SONATYPE_VERSION=$(echo "$BASE_VERSION" | sed -e "s/-(alpha|beta)\.[[:digit:]]*//g")-SNAPSHOT + SONATYPE_VERSION=$(echo "$BASE_VERSION" | sed -e "s/-beta\.[[:digit:]]*//g")-SNAPSHOT NPM_VERSION="$BASE_VERSION" echo $PGP_SECRET | base64 --decode | gpg --batch --import export GPG_TTY=$(tty) echo "Releasing version $BASE_VERSION as pre-release to Sonatype as $SONATYPE_VERSION and NPM as $BASE_VERSION" - echo "yes | sbt -DRELEASE_TYPE=snapshot \"clean\" \"release cross release-version $SONATYPE_VERSION with-defaults\" \"typescript/releaseNpm $NPM_VERSION\"" + yes | sbt -DRELEASE_TYPE=snapshot \"clean\" \"release cross release-version $SONATYPE_VERSION with-defaults\" \"typescript/releaseNpm $NPM_VERSION\" env: PGP_SECRET: ${{ secrets.PGP_SECRET }} PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }} @@ -52,7 +58,7 @@ jobs: SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} release_production_sonatype: - if: "! github.event.release.prerelease" + if: "github.event.release.prerelease" runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -66,7 +72,6 @@ jobs: - uses: actions/setup-node@v3 with: node-version-file: .nvmrc - cache: npm - name: Release Production to Sonatype run: | VERSION=$(git describe --tags | cut -f2 -d"@") From 1a203e746ee1c74598f4f1e2684f52bf4abdcf73 Mon Sep 17 00:00:00 2001 From: Jonathon Herbert Date: Mon, 9 Oct 2023 16:14:22 +0100 Subject: [PATCH 04/11] Add NPM token to secrets exposed in env vars --- .github/workflows/release.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c513555d..3b77cf64 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -50,12 +50,13 @@ jobs: echo $PGP_SECRET | base64 --decode | gpg --batch --import export GPG_TTY=$(tty) echo "Releasing version $BASE_VERSION as pre-release to Sonatype as $SONATYPE_VERSION and NPM as $BASE_VERSION" - yes | sbt -DRELEASE_TYPE=snapshot \"clean\" \"release cross release-version $SONATYPE_VERSION with-defaults\" \"typescript/releaseNpm $NPM_VERSION\" + yes | sbt -DRELEASE_TYPE=snapshot "clean; release cross release-version $SONATYPE_VERSION with-defaults; typescript/releaseNpm $NPM_VERSION" env: PGP_SECRET: ${{ secrets.PGP_SECRET }} PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }} SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} release_production_sonatype: if: "github.event.release.prerelease" From eb411b438c1a5f1f0de75411a873318913224a77 Mon Sep 17 00:00:00 2001 From: Jonathon Herbert Date: Wed, 11 Oct 2023 10:46:39 +0100 Subject: [PATCH 05/11] Add NPM token env var; remove local version --- .github/workflows/release.yml | 1 + version.sbt | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) delete mode 100644 version.sbt diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3b77cf64..4ee9c00e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -94,3 +94,4 @@ jobs: PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }} SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/version.sbt b/version.sbt deleted file mode 100644 index ce0695bf..00000000 --- a/version.sbt +++ /dev/null @@ -1 +0,0 @@ -ThisBuild / version := "17.8.1-SNAPSHOT" From 6d2697ccf90df0b4c3c3f01a9b3e861dc890340d Mon Sep 17 00:00:00 2001 From: Jonathon Herbert Date: Thu, 12 Oct 2023 16:40:39 +0100 Subject: [PATCH 06/11] Update release steps to prepare for remote release --- .github/workflows/release.yml | 36 ++++++++----------- build.sbt | 66 +++++++++++------------------------ project/plugins.sbt | 2 +- 3 files changed, 36 insertions(+), 68 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4ee9c00e..3b8f1cc3 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -10,7 +10,7 @@ on: jobs: release_snapshot_sonatype: - # if: "github.event.release.prerelease || github.event_name == 'workflow_dispatch'" + # if: "github.event.release.prerelease" runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -29,35 +29,29 @@ jobs: run: git fetch --tags origin - name: Release pre-release version to Sonatype and NPM run: | - BASE_VERSION=17.7.0-beta.0 - - # Because NPM releases are not mutable, and it'd be difficult to generate a suffix for a beta-release, - # we must ask the user to supply the NPM-compatible version for pre-release. - if [[ ! $BASE_VERSION =~ (alpha|beta) ]] ; then - echo "Received $BASE_VERSION, but for pre-release, the version number must be an npm-compatible alpha or beta release - please label preleases in an npm-compatible format, e.g. 17.7.0-alpha.0, 20.25.1-beta.5" - exit 1 + VERSION=17.7.0 + if [[ ${VERSION:0:1} == "v" ]] ; then + VERSION=${VERSION:1} fi - - if [[ ${BASE_VERSION:0:1} == "v" ]] ; then - BASE_VERSION=${BASE_VERSION:1} + if [[ ${VERSION: -9} != "-SNAPSHOT" ]] ; then + echo "Version must end in -SNAPSHOT. Adding -SNAPSHOT suffix" + VERSION="$VERSION-SNAPSHOT" fi - - # For Sonatype releases, we remove the beta prefix from the version, and add -SNAPSHOT instead. - SONATYPE_VERSION=$(echo "$BASE_VERSION" | sed -e "s/-beta\.[[:digit:]]*//g")-SNAPSHOT - - NPM_VERSION="$BASE_VERSION" - echo $PGP_SECRET | base64 --decode | gpg --batch --import export GPG_TTY=$(tty) - echo "Releasing version $BASE_VERSION as pre-release to Sonatype as $SONATYPE_VERSION and NPM as $BASE_VERSION" - yes | sbt -DRELEASE_TYPE=snapshot "clean; release cross release-version $SONATYPE_VERSION with-defaults; typescript/releaseNpm $NPM_VERSION" + echo "Releasing version $VERSION Sonatype as snapshot" + + # No need to support NPM releases – there's no direct analogue to a SNAPSHOT release. + # Beta releases are classed as 'production' releases. + yes | sbt -DRELEASE_TYPE=snapshot "clean; release cross release-version $VERSION with-defaults" env: + # We use armour formatted files for keys, but we know the newlines they contain don't survive + # passing through environment vars, so this secret should be an armour-formatted PGP key passed + # through base64. PGP_SECRET: ${{ secrets.PGP_SECRET }} PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }} SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} - NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - release_production_sonatype: if: "github.event.release.prerelease" runs-on: ubuntu-latest diff --git a/build.sbt b/build.sbt index 0feadbc6..f1ae2089 100644 --- a/build.sbt +++ b/build.sbt @@ -126,68 +126,42 @@ lazy val checkReleaseType: ReleaseStep = ReleaseStep({ st: State => }) lazy val releaseProcessSteps: Seq[ReleaseStep] = { - val commonSteps = Seq( - checkReleaseType, + val commonSteps:Seq[ReleaseStep] = Seq( checkSnapshotDependencies, inquireVersions, runClean, - runTest + runTest, + setReleaseVersion, ) - val prodSteps: Seq[ReleaseStep] = Seq( - setReleaseVersion, + val localExtraSteps:Seq[ReleaseStep] = Seq( commitReleaseVersion, tagRelease, - releaseStepCommandAndRemaining("+publishSigned"), - releaseStepCommand("sonatypeBundleRelease"), + publishArtifacts, setNextVersion, - commitNextVersion, - pushChanges + commitNextVersion ) - /* - SNAPSHOT versions are published directly to Sonatype snapshot repo and no local bundle is assembled - Also, we cannot use `sonatypeBundleUpload` or `sonatypeRelease` commands which are usually wrapped up - within a call to `sonatypeBundleRelease` (https://github.com/xerial/sbt-sonatype#publishing-your-artifact). - - Therefore SNAPSHOT versions are not promoted to Maven Central and clients will have to ensure they have the - appropriate resolver entry in their build.sbt, e.g. - - resolvers += Resolver.sonatypeRepo("snapshots") - - */ - val snapshotSteps: Seq[ReleaseStep] = Seq( - setReleaseVersion, - releaseStepCommandAndRemaining("+publishSigned"), - setNextVersion + val snapshotSteps:Seq[ReleaseStep] = Seq( + publishArtifacts, + releaseStepCommand("sonatypeReleaseAll") ) - /* - Beta assemblies can be published to Sonatype and Maven. - - To make this work, start SBT with the candidate releaseType; - 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.0, 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 candidateSteps: Seq[ReleaseStep] = Seq( - setReleaseVersion, + val prodSteps:Seq[ReleaseStep] = Seq( releaseStepCommandAndRemaining("+publishSigned"), - releaseStepCommand("sonatypeBundleRelease"), - setNextVersion + releaseStepCommand("sonatypeBundleRelease") ) - // remember to set with sbt -DRELEASE_TYPE=snapshot|candidate if running a non-prod release - commonSteps ++ (sys.props.get("RELEASE_TYPE") match { - case Some(v) if v == snapshotReleaseType => snapshotSteps // this deploys -SNAPSHOT build to sonatype snapshot repo only - case Some(v) if v == betaReleaseType => candidateSteps // this enables a beta build to sonatype and Maven - case None => prodSteps // our normal deploy route - }) + 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 + } } /** diff --git a/project/plugins.sbt b/project/plugins.sbt index fc550847..c7913800 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,5 +1,5 @@ addSbtPlugin("com.github.sbt" % "sbt-release" % "1.1.0") -addSbtPlugin("com.jsuereth" % "sbt-pgp" % "2.0.1") +addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.1.2") addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.10") addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.3.5") From de02a801ed4ce9d0e64945ceed858f4c5f15850e Mon Sep 17 00:00:00 2001 From: Jonathon Herbert Date: Tue, 17 Oct 2023 09:37:58 +0100 Subject: [PATCH 07/11] More stack To prevent stack overflow errors on compile --- .github/workflows/release.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3b8f1cc3..eb48b78c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -43,7 +43,8 @@ jobs: # No need to support NPM releases – there's no direct analogue to a SNAPSHOT release. # Beta releases are classed as 'production' releases. - yes | sbt -DRELEASE_TYPE=snapshot "clean; release cross release-version $VERSION with-defaults" + sbt -J-Xss32M -DRELEASE_TYPE=snapshot "clean" "release cross release-version $VERSION with-defaults" + env: # We use armour formatted files for keys, but we know the newlines they contain don't survive # passing through environment vars, so this secret should be an armour-formatted PGP key passed From c9b6ededd26564a32fac427a5416b1c1f002a708 Mon Sep 17 00:00:00 2001 From: Jonathon Herbert Date: Tue, 17 Oct 2023 15:41:21 +0100 Subject: [PATCH 08/11] Correct environment variable, and add registry-url MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Both of which are required for setup-node to write an npmrc file to disk, and for npm to read the appropriate env var from the npmrc file – see https://github.com/actions/setup-node/blob/ee36e8b5c0fdd6014a0398aed18ce9876360bd63/src/authutil.ts#L48 and https://npm.github.io/installation-setup-docs/customizing/the-npmrc-file.html --- .github/workflows/release.yml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index eb48b78c..042b8798 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -10,7 +10,7 @@ on: jobs: release_snapshot_sonatype: - # if: "github.event.release.prerelease" + if: "github.event.release.prerelease" runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -54,7 +54,7 @@ jobs: SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} release_production_sonatype: - if: "github.event.release.prerelease" + # if: "github.event.release.prerelease" runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -68,9 +68,10 @@ jobs: - uses: actions/setup-node@v3 with: node-version-file: .nvmrc + registry-url: https://registry.npmjs.org - name: Release Production to Sonatype run: | - VERSION=$(git describe --tags | cut -f2 -d"@") + VERSION=17.7.0-beta.1 if [[ ${VERSION:0:1} == "v" ]] ; then VERSION=${VERSION:1} fi @@ -83,10 +84,10 @@ jobs: 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" "typescript/releaseNpm $VERSION" + sbt -J-Xss32M -DRELEASE_TYPE=snapshot "clean" "release cross release-version $VERSION with-defaults" "project typescript" "releaseNpm $VERSION" env: PGP_SECRET: ${{ secrets.PGP_SECRET }} PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }} SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} - NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} From c6b74ad745ad70e921b7f74a8eb777a04084d32c Mon Sep 17 00:00:00 2001 From: Jonathon Herbert Date: Mon, 13 Nov 2023 14:51:21 +0000 Subject: [PATCH 09/11] Reinstate version and prerelease conditional --- .github/workflows/release.yml | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 042b8798..d5e5cd1f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -2,9 +2,6 @@ name: Publish to Sonatype and NPM on: workflow_dispatch: - push: - branches: - - 'jsh/release-via-gh-actions' release: types: [published] @@ -29,7 +26,7 @@ jobs: run: git fetch --tags origin - name: Release pre-release version to Sonatype and NPM run: | - VERSION=17.7.0 + VERSION=$(git describe --tags | cut -f2 -d"@") if [[ ${VERSION:0:1} == "v" ]] ; then VERSION=${VERSION:1} fi @@ -53,8 +50,9 @@ jobs: PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }} SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} + release_production_sonatype: - # if: "github.event.release.prerelease" + if: "!github.event.release.prerelease" runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -71,7 +69,7 @@ jobs: registry-url: https://registry.npmjs.org - name: Release Production to Sonatype run: | - VERSION=17.7.0-beta.1 + VERSION=$(git describe --tags | cut -f2 -d"@") if [[ ${VERSION:0:1} == "v" ]] ; then VERSION=${VERSION:1} fi From a996b51081083fbc207c36b19d41091d79397ddc Mon Sep 17 00:00:00 2001 From: Jonathon Herbert Date: Mon, 13 Nov 2023 15:02:30 +0000 Subject: [PATCH 10/11] Test release --- .github/workflows/release.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d5e5cd1f..a5c33101 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -52,7 +52,7 @@ jobs: SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} release_production_sonatype: - if: "!github.event.release.prerelease" + #if: "!github.event.release.prerelease" runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -82,7 +82,7 @@ jobs: echo $PGP_SECRET | base64 --decode | gpg --batch --import export GPG_TTY=$(tty) echo "Releasing version $VERSION Sonatype as production" - sbt -J-Xss32M -DRELEASE_TYPE=snapshot "clean" "release cross release-version $VERSION with-defaults" "project typescript" "releaseNpm $VERSION" + yes | sbt -J-Xss32M "clean" "release cross release-version $VERSION with-defaults" "project typescript" "releaseNpm $VERSION" env: PGP_SECRET: ${{ secrets.PGP_SECRET }} PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }} From 8c01466f80c93d05b7c7b7cbc6b2ae05bd0268ca Mon Sep 17 00:00:00 2001 From: Jonathon Herbert Date: Mon, 13 Nov 2023 16:13:57 +0000 Subject: [PATCH 11/11] Add release instructions to README --- README.md | 53 +++++++++++------------------------------------------ 1 file changed, 11 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index 78567f9b..eb528e7e 100644 --- a/README.md +++ b/README.md @@ -9,51 +9,20 @@ ### 17.0.0 * This release imports the `sbt-scrooge-typescript 1.4.0` sbt plugin which has the potential to introduce some [breaking changes](https://github.com/apache/thrift/blob/master/CHANGES.md#breaking-changes-2) for generated typescript mappings via thrift 0.13.0, specifically related to the [handling of `Int64`](https://issues.apache.org/jira/browse/THRIFT-4675) data. -## Releasing +# Publishing a new release -Ensure the version is composed of three parts (`1.2.3`) as NPM doesn't accept shorter versions such as `1.2`. +This repository has a Github Action that will create new releases for Sonatype and NPM when a new release is created in Github. -The `release cross` command will publish to [Maven Central](http://search.maven.org/) via Sonatype. You will need Sonatype credentials and a PGP key. It can take up to 2hrs to show up in search. +- Push the branch with the changes you want to release to Github. +- Begin creating a new release (here's a [quick link.](https://github.com/guardian/flexible-model/releases/new)) +- Set the `Target` to your branch. +- Create a tag: +- - For a production release, the tag should be the new version number, e.g. `vX.X.X`. Beta releases are production releases – for example `v1.0.0-beta.0`. +- - For a snapshot release, the tag should ideally have the format `vX.X.X-SNAPSHOT`. +- **If you are intending to release a snapshot,** double-check that the "Set as pre-release" box is ticked. +- Click the "Publish release" button. The action will trigger, and your release should be on its way. -`release NPM` will release the typescript package to NPM. Ensure you have an NPM account, part of the [@guardian](https://www.npmjs.com/org/guardian) org with a [configured token](https://docs.npmjs.com/creating-and-viewing-authentication-tokens) - -To release, in the SBT repl: -```sbtshell -release cross // will release the scala / thrift projects -project typescript -releaseNpm // you have to specify the version again i.e releaseNpm 1.0.0 -``` - -If you see the message `Cannot run program "tsc"` you will need to install TypeScript: -``` -npm install -g typescript -``` - -It is worth noting that different teams follow different practices for model releases. In CAPI, we always release from master/main, so when you are happy with your local release, you can go ahead and make your PR. Once that is merged into main, you can publish your release to Maven. Two consecutive commits will automatically be made to master/main updating the next version number. - -### Releasing SNAPSHOT or beta versions - -It's also possible to release a snapshot build to Sonatype's snapshot repo with no promotion to Maven Central. This can be useful for trialling a test or upgraded dependency internally. - -To do this, start sbt with a RELEASE_TYPE variable; - -`sbt -DRELEASE_TYPE=snapshot` - -Then, when you run `release cross`, you'll be asked to confirm that you intend to make a SNAPSHOT release, and if you proceed will be prompted to complete the snapshot version details. Whatever you specify here will be written back to the `version.sbt` but this won't be automatically committed back to github. - -You are able to re-release the same snapshot version repeatedly (which is handy if you're having GPG-related issues etc.) - -Making a beta release is also possible by using the appropriate RELEASE_TYPE variable; - -`sbt -DRELEASE_TYPE=beta` - -Here, the main differences are that the version number is expected to be of the format 1.2.3-beta.n, and the release will be promoted to Maven Central. - -As with the snapshot release process you'll be prompted to confirm and specify the version number you need to use, and changes applied to `version.sbt` will not be automatically committed to github etc. - -Unlike a production release, these alternatives are useful for testing/developing with another team or application and can be executed from a branch so there's no need to have everything merged into main/master branches prior to making your changes available. - -**Note:** `releaseNpm` (provided by our sbt-scrooge-typescript plugin) has been updated to apply a beta tag to the release, just be sure to use the `x.y.z-beta.n` version number format or NPM may reject it. +To release a package from your local machine, follow the instructions for [publishing a new version to Maven Central via Sonatype](https://docs.google.com/document/d/1rNXjoZDqZMsQblOVXPAIIOMWuwUKe3KzTCttuqS7AcY/edit#). ## Information about built bundles