diff --git a/.github/scripts/project-version.sh b/.github/scripts/project-version.sh new file mode 100755 index 00000000..1f8f06f3 --- /dev/null +++ b/.github/scripts/project-version.sh @@ -0,0 +1,65 @@ +#!/usr/bin/env bash +# +# Sets or verifies the version of all Maven POMs in this repository. +# +# The modules have no , so every POM carries its own version. The POMs +# are found via git, so new or profile-only modules (e.g. performance-test) +# are always included. + +set -euo pipefail + +usage() { + cat < | --verify + + --set set in all POMs + --verify fail if any POM differs from the version of the root POM + -h, --help show this help +USAGE +} + +all_poms() { + git ls-files pom.xml '*/pom.xml' +} + +pom_version() { + mvn -B -q -N -f "$1" help:evaluate -Dexpression=project.version -DforceStdout +} + +set_version() { + local version="$1" + for pom in $(all_poms); do + echo "Setting version of $pom to $version" + # The reproducible build timestamp is pinned by the release workflow itself. + mvn -B -q -N -f "$pom" versions:set \ + -DnewVersion="$version" \ + -DgenerateBackupPoms=false \ + -DupdateBuildOutputTimestampPolicy=never + done +} + +verify_versions() { + local expected actual failed=0 + expected="$(pom_version pom.xml)" + for pom in $(all_poms); do + actual="$(pom_version "$pom")" + if [[ "$actual" != "$expected" ]]; then + echo "::error file=$pom::$pom has version $actual, expected $expected" + failed=1 + fi + done + return "$failed" +} + +option="${1:-}" + +if [[ "$option" == "--set" && $# -eq 2 ]]; then + set_version "$2" +elif [[ "$option" == "--verify" && $# -eq 1 ]]; then + verify_versions +elif [[ "$option" == "-h" || "$option" == "--help" ]]; then + usage +else + usage >&2 + exit 1 +fi diff --git a/.github/workflows/maven-central-release.yml b/.github/workflows/maven-central-release.yml index 782a28e6..3f7774bd 100644 --- a/.github/workflows/maven-central-release.yml +++ b/.github/workflows/maven-central-release.yml @@ -63,6 +63,10 @@ jobs: CURRENT_VERSION="${CURRENT_VERSION//$'\r'/}" CURRENT_VERSION="${CURRENT_VERSION// /}" + # All POMs must share the root version, otherwise a module would be + # released and bumped from a stale version. + .github/scripts/project-version.sh --verify + if [[ "$CURRENT_VERSION" != *-SNAPSHOT ]]; then echo "::error::Current POM version is '$CURRENT_VERSION', expected a -SNAPSHOT version. main must always be on a snapshot version." exit 1 @@ -85,14 +89,10 @@ jobs: VERSION=${{ steps.version.outputs.VERSION }} echo "Setting version to $VERSION" - # Update parent POM - mvn versions:set -DnewVersion=$VERSION -DgenerateBackupPoms=false - - # Update ALL module POMs. The modules have no element, so - # each must be set individually. Only core and processor are deployed - # to Maven Central, but all modules must share the same version for - # the reactor build to work correctly. - mvn versions:set -DnewVersion=$VERSION -DgenerateBackupPoms=false -pl core,processor,example,example-custom-generator + # Update ALL POMs (root and every module, including profile-only + # ones). Only core and processor are deployed to Maven Central, but + # all modules must share the same version. + .github/scripts/project-version.sh --set "$VERSION" - name: Update reproducible build timestamp run: | @@ -114,7 +114,7 @@ jobs: # update to main goes through a reviewed pull request instead of a # direct push that bypasses branch protection. git checkout -B "$BRANCH" - git add pom.xml core/pom.xml processor/pom.xml example/pom.xml example-custom-generator/pom.xml + git add -- pom.xml '*/pom.xml' echo "branch=$BRANCH" >> "$GITHUB_OUTPUT" # Only commit if there are changes. Note: no "[skip ci]" so the @@ -264,12 +264,11 @@ jobs: echo "Next snapshot version: $NEXT_VERSION" # Set all POMs to the next snapshot version. - mvn versions:set -DnewVersion=$NEXT_VERSION -DgenerateBackupPoms=false - mvn versions:set -DnewVersion=$NEXT_VERSION -DgenerateBackupPoms=false -pl core,processor,example,example-custom-generator + .github/scripts/project-version.sh --set "$NEXT_VERSION" # Commit as a second commit on the release branch. The tag (already # created and pushed on the first commit) is unaffected by this commit. - git add pom.xml core/pom.xml processor/pom.xml example/pom.xml example-custom-generator/pom.xml + git add -- pom.xml '*/pom.xml' git commit -m "release: prepare next version $NEXT_VERSION" # Force-push the updated branch so the remote has both commits. diff --git a/RELEASE.md b/RELEASE.md index 9ed11a80..c7174c67 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -20,7 +20,7 @@ No version input is required. The workflow derives the release version from the ### What the Workflow Does 1. Derives the release version from the current POM snapshot version (strips `-SNAPSHOT`) -2. Updates POM versions to the release version in **all** modules (core, processor, example, example-custom-generator) +2. Updates POM versions to the release version in **all** tracked `pom.xml` files (discovered via git, so new and profile-only modules such as `performance-test` are included) 3. Commits the version bump on a dedicated `release/vX.Y.Z` branch and creates tag `vX.Y.Z` 4. Builds and verifies the project with `-Prelease` (reproducible builds via `project.build.outputTimestamp`) 5. Signs artifacts with GPG @@ -85,4 +85,4 @@ Each release produces, in addition to the GPG-signed jars: - Versions with `-` (e.g., `0.2.0-beta`) are marked as pre-releases - Releases are **staged** to the Sonatype Central portal and require a **manual publish** step; nothing is auto-released - Only `core` and `processor` modules are published to Maven Central -- The `example` and `example-custom-generator` modules are version-updated alongside the released modules but are **not** deployed to Maven Central +- All other modules (e.g. `example`, `example-custom-generator`, `performance-test`) are version-updated alongside the released modules but are **not** deployed to Maven Central; the release workflow fails if any POM differs from the root version diff --git a/performance-test/pom.xml b/performance-test/pom.xml index 61d6a09a..81184dd6 100644 --- a/performance-test/pom.xml +++ b/performance-test/pom.xml @@ -6,7 +6,7 @@ io.github.java-helpers simple-builders-performance-test - 0.6.0-SNAPSHOT + 0.7.0-SNAPSHOT jar Simple Builders - Performance Test