Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions .github/scripts/project-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env bash
#
# Sets or verifies the version of all Maven POMs in this repository.
#
# The modules have no <parent>, 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 <<USAGE
Usage: $(basename "$0") --set <version> | --verify

--set <version> set <version> 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
23 changes: 11 additions & 12 deletions .github/workflows/maven-central-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 <parent> 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: |
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion performance-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>io.github.java-helpers</groupId>
<artifactId>simple-builders-performance-test</artifactId>
<version>0.6.0-SNAPSHOT</version>
<version>0.7.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Simple Builders - Performance Test</name>
Expand Down
Loading