From ff91dd7c140fd69f6027d91c95bc08648b5f571d Mon Sep 17 00:00:00 2001 From: Domenic Cassisi Date: Tue, 1 Dec 2026 23:42:15 +0100 Subject: [PATCH] Automate releases from GitHub Release tags - Derive the release version from the tag; the development version moves to gradle.properties, so releases need no version commits - Publish workflow builds and tests first, publishes and releases to Maven Central automatically, and runs once per release - Open a post-release pull request that updates the README snippets and bumps to the next snapshot - Categorize generated release notes via .github/release.yml - Let Dependabot update GitHub Actions and group gRPC/protobuf and test dependency updates; update actions to current major versions - Target Java 25 explicitly and document the requirement - Document the release process in RELEASING.md --- .github/dependabot.yml | 25 +++++- .github/release.yml | 25 ++++++ .github/scripts/post-release-update.sh | 25 ++++++ .github/workflows/gradle.yml | 27 ++++--- .github/workflows/publish.yml | 106 +++++++++++++++++++++---- README.md | 3 + RELEASING.md | 48 +++++++++++ build.gradle | 8 +- gradle.properties | 6 +- 9 files changed, 241 insertions(+), 32 deletions(-) create mode 100644 .github/release.yml create mode 100755 .github/scripts/post-release-update.sh create mode 100644 RELEASING.md diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 3e02120..26c0c75 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,11 +1,28 @@ -# To get started with Dependabot version updates, you'll need to specify which -# package ecosystems to update and where the package manifests are located. -# Please see the documentation for all configuration options: +# Dependabot version updates. # https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file version: 2 updates: - package-ecosystem: "gradle" - directory: "/" # Location of package manifests + directory: "/" schedule: interval: "weekly" + groups: + # gRPC and protobuf are released in lockstep and must stay compatible. + grpc-protobuf: + patterns: + - "io.grpc:*" + - "com.google.protobuf:*" + test-dependencies: + patterns: + - "org.junit*" + - "org.testcontainers*" + + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" + groups: + github-actions: + patterns: + - "*" diff --git a/.github/release.yml b/.github/release.yml new file mode 100644 index 0000000..1666147 --- /dev/null +++ b/.github/release.yml @@ -0,0 +1,25 @@ +# Categories for GitHub's automatically generated release notes +# ("Generate release notes" when drafting a release). Pull requests are sorted by label; +# Dependabot labels its pull requests "dependencies" automatically. +# https://docs.github.com/repositories/releasing-projects-on-github/automatically-generated-release-notes + +changelog: + categories: + - title: Breaking changes + labels: + - breaking-change + - title: New features + labels: + - enhancement + - title: Bug fixes + labels: + - bug + - title: Documentation + labels: + - documentation + - title: Dependency updates + labels: + - dependencies + - title: Other changes + labels: + - "*" diff --git a/.github/scripts/post-release-update.sh b/.github/scripts/post-release-update.sh new file mode 100755 index 0000000..662137b --- /dev/null +++ b/.github/scripts/post-release-update.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash +# Updates the repository after version $1 has been published: +# - points the README's Gradle and Maven snippets at the released version +# - bumps gradle.properties to the next minor snapshot, unless it was already moved on +# +# Usage: post-release-update.sh (e.g. 0.8 or 0.8.1) +set -euo pipefail + +version="${1:?usage: post-release-update.sh }" +if [[ ! "$version" =~ ^[0-9]+\.[0-9]+(\.[0-9]+)?$ ]]; then + echo "Not a release version: $version" >&2 + exit 1 +fi + +# README: Gradle coordinates and the Maven directly following our artifactId. +perl -pi -e "s/(io\.github\.domenicdev:umadb-java-client:)[^\"')]+/\${1}${version}/g" README.md +perl -0pi -e "s|(umadb-java-client\s*)[^<]+()|\${1}${version}\${2}|g" README.md + +# gradle.properties: X.Y[.Z] -> X.(Y+1)-SNAPSHOT, but only while the snapshot still names the +# version just released, so a manual bump (e.g. straight to 1.0-SNAPSHOT) is left alone. +current="$(sed -n 's/^version=//p' gradle.properties)" +IFS=. read -r major minor _ <<< "$version" +if [[ "$current" == "${major}.${minor}-SNAPSHOT" || "$current" == "${version}-SNAPSHOT" ]]; then + sed -i "s/^version=.*/version=${major}.$((minor + 1))-SNAPSHOT/" gradle.properties +fi diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 1076a8b..e956ef9 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -1,9 +1,6 @@ -# This workflow uses actions that are not certified by GitHub. -# They are provided by a third-party and are governed by -# separate terms of service, privacy policy, and support -# documentation. -# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time -# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle +# Builds and tests every push and pull request to main, and submits the dependency graph +# so that Dependabot alerts cover all Gradle dependencies. +# See: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle name: Java CI with Gradle @@ -13,17 +10,22 @@ on: pull_request: branches: [ "main" ] +concurrency: + group: ci-${{ github.ref }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} + jobs: build: runs-on: ubuntu-latest + timeout-minutes: 30 permissions: contents: read steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v7 - name: Set up JDK 25 - uses: actions/setup-java@v4 + uses: actions/setup-java@v6 with: java-version: '25' distribution: 'temurin' @@ -31,7 +33,7 @@ jobs: # Configure Gradle for optimal use in GitHub Actions, including caching of downloaded dependencies. # See: https://github.com/gradle/actions/blob/main/setup-gradle/README.md - name: Setup Gradle - uses: gradle/actions/setup-gradle@v5 + uses: gradle/actions/setup-gradle@v6 - name: Build with Gradle Wrapper run: ./gradlew build @@ -39,13 +41,14 @@ jobs: dependency-submission: runs-on: ubuntu-latest + timeout-minutes: 15 permissions: contents: write steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v7 - name: Set up JDK 25 - uses: actions/setup-java@v4 + uses: actions/setup-java@v6 with: java-version: '25' distribution: 'temurin' @@ -53,4 +56,4 @@ jobs: # Generates and submits a dependency graph, enabling Dependabot Alerts for all project dependencies. # See: https://github.com/gradle/actions/blob/main/dependency-submission/README.md - name: Generate and submit dependency graph - uses: gradle/actions/dependency-submission@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0 + uses: gradle/actions/dependency-submission@v6 diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index f6ea76a..9664864 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,29 +1,107 @@ name: Publish +# Publishing a GitHub Release (or pre-release) tagged vX.Y[.Z][-suffix] releases that +# version to Maven Central. The version comes from the tag, so no release commit is needed. +# `published` fires once per release; promoting a pre-release to a release does not +# re-publish. on: release: - types: [released, prereleased] + types: [published] + +concurrency: + group: publish-${{ github.event.release.tag_name }} + cancel-in-progress: false + +permissions: + contents: read jobs: publish: - name: Release build and publish + name: Build, test and publish to Maven Central runs-on: ubuntu-latest - permissions: - contents: read + timeout-minutes: 30 + outputs: + version: ${{ steps.version.outputs.version }} steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v7 + + - name: Derive version from tag + id: version + env: + TAG: ${{ github.event.release.tag_name }} + run: | + if [[ ! "$TAG" =~ ^v[0-9]+\.[0-9]+(\.[0-9]+)?(-[0-9A-Za-z.]+)?$ ]] || [[ "$TAG" == *-SNAPSHOT ]]; then + echo "::error::Release tag '$TAG' is not a release version (expected vX.Y, vX.Y.Z or vX.Y.Z-suffix)" + exit 1 + fi + echo "version=${TAG#v}" >> "$GITHUB_OUTPUT" + - name: Set up JDK 25 - uses: actions/setup-java@v4 + uses: actions/setup-java@v6 with: java-version: '25' distribution: 'temurin' - - name: Publish to MavenCentral - run: ./gradlew publishToMavenCentral --no-configuration-cache + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v6 + + - name: Build and test + run: ./gradlew build + env: + ORG_GRADLE_PROJECT_version: ${{ steps.version.outputs.version }} + + - name: Publish and release to Maven Central + run: ./gradlew publishAndReleaseToMavenCentral --no-configuration-cache + env: + ORG_GRADLE_PROJECT_version: ${{ steps.version.outputs.version }} + ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVEN_CENTRAL_USERNAME }} + ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.MAVEN_CENTRAL_PASSWORD }} + ORG_GRADLE_PROJECT_signingInMemoryKeyId: ${{ secrets.SIGNING_KEY_ID }} + ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.SIGNING_PASSWORD }} + ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.GPG_KEY_CONTENTS }} + + post-release: + name: Open pull request updating README and next snapshot + needs: publish + # Pre-releases are not advertised in the README. + if: ${{ !github.event.release.prerelease }} + runs-on: ubuntu-latest + timeout-minutes: 10 + permissions: + contents: write + pull-requests: write + + steps: + - uses: actions/checkout@v7 + with: + ref: ${{ github.event.repository.default_branch }} + + - name: Update README and gradle.properties + env: + VERSION: ${{ needs.publish.outputs.version }} + run: .github/scripts/post-release-update.sh "$VERSION" + + - name: Open pull request env: - ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVEN_CENTRAL_USERNAME }} - ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.MAVEN_CENTRAL_PASSWORD }} - ORG_GRADLE_PROJECT_signingInMemoryKeyId: ${{ secrets.SIGNING_KEY_ID }} - ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.SIGNING_PASSWORD }} - ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.GPG_KEY_CONTENTS }} - + GH_TOKEN: ${{ github.token }} + VERSION: ${{ needs.publish.outputs.version }} + BASE: ${{ github.event.repository.default_branch }} + run: | + if git diff --quiet; then + echo "Nothing to update." + exit 0 + fi + branch="post-release/v${VERSION}" + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + git switch -c "$branch" + git commit -am "Update README to ${VERSION} and bump to next snapshot" + git push --force origin "$branch" + if gh pr view "$branch" --json state --jq .state 2>/dev/null | grep -q OPEN; then + echo "Pull request for $branch already open; branch updated." + exit 0 + fi + gh pr create --base "$BASE" --head "$branch" \ + --title "Post-release: ${VERSION}" \ + --body "Points the README's installation snippets at ${VERSION}, which is now on Maven Central, and bumps \`gradle.properties\` to the next development snapshot (only if it still named the released version)." diff --git a/README.md b/README.md index ed420e2..2cf05eb 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,9 @@ A lightweight Java client for interacting with the [UmaDB event store](https://u ## Installation +> **Requires Java 25 or newer.** The library is compiled for Java 25 and does not run on +> older JVMs. + Add the following dependency to either the `build.gradle` or `pom.xml` file in your project. ### Gradle diff --git a/RELEASING.md b/RELEASING.md new file mode 100644 index 0000000..0b5a84f --- /dev/null +++ b/RELEASING.md @@ -0,0 +1,48 @@ +# Releasing + +Releases are driven entirely by GitHub Releases. There are no release commits: the version +is taken from the release tag. + +## Cutting a release + +1. Make sure `main` is green and the README's "Migrating from …" section describes any + breaking changes. +2. On GitHub, draft a new release: + - **Tag:** `vX.Y` or `vX.Y.Z` (for example `v0.8`), created from `main`. + - **Release notes:** click *Generate release notes*. Pull requests are grouped by label + (see `.github/release.yml`); add highlights or migration notes by hand if needed. + - Tick *Set as a pre-release* for versions such as `v0.9.0-rc1`. +3. Publish the release. The [Publish workflow](.github/workflows/publish.yml) then: + 1. derives the version from the tag (`v0.8` → `0.8`) and rejects tags that are not + release versions, + 2. builds and runs all tests against that version, + 3. signs, uploads and **automatically releases** the artifacts on Maven Central, + 4. for full releases only, opens a pull request that points the README's installation + snippets at the new version and bumps `gradle.properties` to the next minor snapshot. +4. Review and merge the post-release pull request. + +Artifacts usually appear on Maven Central within about 30 minutes of the workflow finishing. +A published version cannot be replaced or deleted. If something is wrong, release a new +version. + +## Versions + +- `gradle.properties` holds the development version (`X.Y-SNAPSHOT`) used for local builds. + Release builds override it with `-Pversion`/`ORG_GRADLE_PROJECT_version`. +- The post-release pull request bumps the snapshot only if it still names the version just + released. To skip ahead (for example to `1.0-SNAPSHOT`), edit `gradle.properties` by hand. + +## One-time repository setup + +- **Secrets** used by the Publish workflow: `MAVEN_CENTRAL_USERNAME`, + `MAVEN_CENTRAL_PASSWORD` (a Central Portal user token), `SIGNING_KEY_ID`, + `SIGNING_PASSWORD`, `GPG_KEY_CONTENTS`. +- **Settings → Actions → General → Workflow permissions:** enable *Allow GitHub Actions to + create and approve pull requests*, so that the post-release pull request can be opened. +- **Labels** for release notes: `breaking-change` (create it), `enhancement`, `bug`, + `documentation`, `dependencies` (GitHub and Dependabot defaults). + +Pull requests opened by the workflow do not trigger the CI workflow themselves, because +GitHub does not start workflows for events caused by `GITHUB_TOKEN`. They only touch the +README and `gradle.properties`, so this is harmless. If branch protection requires status +checks, push an empty commit to the branch or merge with admin rights. diff --git a/build.gradle b/build.gradle index 754d48a..1ca9a10 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,13 @@ plugins { } group = 'io.umadb' -version = '0.8-SNAPSHOT' +// The version lives in gradle.properties. Releases override it from the Git tag +// (see .github/workflows/publish.yml), so it never needs a release commit. + +// Published bytecode targets Java 25, independent of the JDK running the build. +tasks.withType(JavaCompile).configureEach { + options.release = 25 +} repositories { mavenCentral() diff --git a/gradle.properties b/gradle.properties index 713c79e..8b08284 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,6 @@ +# Development version. Releases override it from the Git tag (vX.Y -> X.Y); +# the post-release pull request bumps it to the next snapshot. +version=0.8-SNAPSHOT + mavenCentralPublishing=true -signAllPublications=true \ No newline at end of file +signAllPublications=true