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
24 changes: 22 additions & 2 deletions deploy.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
#!/usr/bin/env -S bash -e

USE_JRELEASER_RELEASE=false

while getopts 'j:' opt; do
case "$opt" in
j)
USE_JRELEASER_RELEASE=true
;;
\?)
usage
exit 1
;;
esac
done

shift $((OPTIND - 1))

SCRIPTS_DIR="$(readlink -f ${BASH_SOURCE[0]} | xargs dirname)"

PROJECT=$1
Expand Down Expand Up @@ -47,11 +63,15 @@ else
$ADDITIONAL_OPTIONS
fi

if [ -f "./jreleaser.yml" ]; then
if [ -f "./jreleaser.yml" ] || [ "$USE_JRELEASER_RELEASE" == "true" ]; then
# JReleaser-based build
source "$SCRIPTS_DIR/jreleaser-setup.sh"
# Execute a JReleaser command such as 'full-release'
$SCRIPTS_DIR/jreleaser/bin/jreleaser full-release -Djreleaser.project.version="$RELEASE_VERSION"
$SCRIPTS_DIR/jreleaser/bin/jreleaser full-release \
-Djreleaser.project.version="$RELEASE_VERSION" \
-Djreleaser.project.java.group.id=$($SCRIPTS_DIR/determine-current-project-groupid.sh $PROJECT) \
--config-file $($SCRIPTS_DIR/determine-jreleaser-config-file.sh $PROJECT) \
--basedir $WORKSPACE
fi

popd
35 changes: 35 additions & 0 deletions determine-current-project-groupid.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env -S bash -e

SCRIPTS_DIR="$(readlink -f ${BASH_SOURCE[0]} | xargs dirname)"

PROJECT=$1
WORKSPACE=${WORKSPACE:-'.'}

if [ -z "$PROJECT" ]; then
echo "ERROR: Project not supplied"
exit 1
fi

if [ "$PROJECT" == "orm" ]; then
BRANCH_NAME=$(git symbolic-ref -q HEAD)
BRANCH_NAME=${BRANCH_NAME##refs/heads/}
BRANCH_NAME=${BRANCH_NAME:-HEAD}

if [[ $BRANCH_NAME =~ ^5\..+ ]]; then
echo "org.hibernate"
else
echo "org.hibernate.orm"
fi
elif [ "$PROJECT" == "reactive" ]; then
echo "org.hibernate.reactive"
elif [ "$PROJECT" == "models" ]; then
echo "org.hibernate.models"
elif [ -f './gradlew' ]; then
# Gradle-based build
echo "ERROR: An unsupported Gradle project: $PROJECT"
exit 1
else
# Maven-based build

mvn -f $WORKSPACE/pom.xml org.apache.maven.plugins:maven-help-plugin:evaluate -Dexpression=project.groupId -q -DforceStdout
fi
35 changes: 35 additions & 0 deletions determine-jreleaser-config-file.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env -S bash -e

SCRIPTS_DIR="$(readlink -f ${BASH_SOURCE[0]} | xargs dirname)"

PROJECT=$1
WORKSPACE=${WORKSPACE:-'.'}

if [ -f "./jreleaser.yml" ]; then
# There is a jreleaser.yml in the project root. Using this configuration:
echo "./jreleaser.yml"
exit 0
fi

if [ -z "$PROJECT" ]; then
echo "ERROR: Project not supplied"
exit 1
fi

BRANCH_NAME=$(git symbolic-ref -q HEAD)
BRANCH_NAME=${BRANCH_NAME##refs/heads/}
BRANCH_NAME=${BRANCH_NAME:-HEAD}

if [ "$PROJECT" == "orm" ]; then
if [ "$BRANCH_NAME" == "main" ]; then
echo "$SCRIPTS_DIR/jreleaser/configuration/jreleaser_manual.yml"
else
echo "$SCRIPTS_DIR/jreleaser/configuration/jreleaser_automatic.yml"
fi
elif [ "$PROJECT" == "reactive" ]; then
echo "$SCRIPTS_DIR/jreleaser/configuration/jreleaser_automatic_alternative.yml"
elif [ "$PROJECT" == "models" ]; then
echo "$SCRIPTS_DIR/jreleaser/configuration/jreleaser_automatic_alternative.yml"
else
echo "$SCRIPTS_DIR/jreleaser/configuration/jreleaser_manual.yml"
fi
7 changes: 4 additions & 3 deletions jreleaser-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@

SCRIPTS_DIR="$(readlink -f ${BASH_SOURCE[0]} | xargs dirname)"

if [ -d "${SCRIPTS_DIR}/jreleaser/bin/jreleaser" ]; then
if [ -f "${SCRIPTS_DIR}/jreleaser/bin/jreleaser" ]; then
echo "JReleaser was already set up. Skipping installation"
$SCRIPTS_DIR/jreleaser/bin/jreleaser --version
return
fi

echo "About to install JReleaser."
wget https://github.com/jreleaser/jreleaser/releases/download/v1.17.0/jreleaser-1.17.0.zip -qO jreleaser.zip
wget https://github.com/jreleaser/jreleaser/releases/download/v1.18.0/jreleaser-1.18.0.zip -qO jreleaser.zip
unzip -qq jreleaser.zip
mv jreleaser-1.17.0/* $SCRIPTS_DIR/jreleaser
mv jreleaser-1.18.0/* $SCRIPTS_DIR/jreleaser
rm -r jreleaser-1.18.0
rm jreleaser.zip

$SCRIPTS_DIR/jreleaser/bin/jreleaser --version
1 change: 1 addition & 0 deletions jreleaser/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# The folder into which we install jreleaser into
*
!.gitignore
!/configuration
36 changes: 36 additions & 0 deletions jreleaser/configuration/jreleaser_automatic.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# This configuration automatically releases the staging nexus repository,
# hence less human interactions are expected for the release.
release:
github:
skipTag: true
skipRelease: true
tagName: '{{projectVersion}}'

# File signing is always active
signing:
mode: COMMAND
active: RELEASE
armored: true

deploy:
maven:
# TODO: Remove the entire nexus2 section:
nexus2:
maven-central:
active: RELEASE
url: https://oss.sonatype.org/service/local
snapshotUrl: https://oss.sonatype.org/content/repositories/snapshots/
closeRepository: true
releaseRepository: true
stagingRepositories:
- target/staging-deploy/maven
mavenCentral:
maven-central:
# TODO: Change to RELEASE once switching to Maven-Central:
# Note, this is an untested configuration, hence might need further adjustments
active: NEVER
url: https://central.sonatype.com/api/v1/publisher
snapshotSupported: false
applyMavenCentralRules: true
stagingRepositories:
- target/staging-deploy/maven
38 changes: 38 additions & 0 deletions jreleaser/configuration/jreleaser_automatic_alternative.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Overall this config file is the same as the jreleaser_automatic.yml
# but it uses a different `stagingRepositories` (`build` instead of `target`).
#
# `stagingRepositories` cannot be parameterized, hence we need to keep two versions of the file.
release:
github:
skipTag: true
skipRelease: true
tagName: '{{projectVersion}}'

# File signing is always active
signing:
mode: COMMAND
active: RELEASE
armored: true

deploy:
maven:
# TODO: Remove the entire nexus2 section:
nexus2:
maven-central:
active: RELEASE
url: https://oss.sonatype.org/service/local
snapshotUrl: https://oss.sonatype.org/content/repositories/snapshots/
closeRepository: true
releaseRepository: true
stagingRepositories:
- build/staging-deploy/maven
mavenCentral:
maven-central:
# TODO: Change to RELEASE once switching to Maven-Central:
# Note, this is an untested configuration, hence might need further adjustments
active: NEVER
url: https://central.sonatype.com/api/v1/publisher
snapshotSupported: false
applyMavenCentralRules: true
stagingRepositories:
- build/staging-deploy/maven
36 changes: 36 additions & 0 deletions jreleaser/configuration/jreleaser_manual.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# This configuration does not automatically release the staging nexus repository,
# The releaser has to go to the Nexus and release the repository manually.
release:
github:
skipTag: true
skipRelease: true
tagName: '{{projectVersion}}'

# File signing is always active
signing:
mode: COMMAND
active: RELEASE
armored: true

deploy:
maven:
# TODO: Remove the entire nexus2 section:
nexus2:
maven-central:
active: RELEASE
url: https://oss.sonatype.org/service/local
snapshotUrl: https://oss.sonatype.org/content/repositories/snapshots/
closeRepository: true
releaseRepository: false
stagingRepositories:
- target/staging-deploy/maven
mavenCentral:
maven-central:
# TODO: Change to RELEASE once switching to Maven-Central:
# Note, this is an untested configuration, hence might need further adjustments
active: NEVER
url: https://central.sonatype.com/api/v1/publisher
snapshotSupported: false
applyMavenCentralRules: true
stagingRepositories:
- target/staging-deploy/maven
12 changes: 9 additions & 3 deletions prepare-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@
# Default to a well-known CI environment variable
BRANCH="$BRANCH_NAME"

while getopts 'd:b:' opt; do
while getopts 'djv:b:' opt; do
case "$opt" in
d)
DRY_RUN=true
;;
j)
USE_JRELEASER_RELEASE=true
;;
b)
BRANCH="$OPTARG"
;;
d)
v)
DEVELOPMENT_VERSION="$OPTARG"
;;
\?)
Expand Down Expand Up @@ -67,7 +73,7 @@ if [ "$PROJECT" == "orm" ] || [ "$PROJECT" == "reactive" ] || [ "$PROJECT" == "m
"$SCRIPTS_DIR/validate-release.sh" $PROJECT $RELEASE_VERSION

EXTRA_ARGS=""
if [ -f "./jreleaser.yml" ]; then
if [ -f "./jreleaser.yml" ] || [ "$USE_JRELEASER_RELEASE" == "true" ]; then
EXTRA_ARGS+=" publishAllPublicationsToStagingRepository"
fi

Expand Down
54 changes: 39 additions & 15 deletions publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,23 @@ function exec_or_dry_run() {
}
PUSH_CHANGES=true
DRY_RUN=false
USE_JRELEASER_RELEASE=false

while getopts 'dhb:' opt; do
while getopts 'djh:' opt; do
case "$opt" in
h)
usage
exit 0
;;
j)
USE_JRELEASER_RELEASE=true
;;
d)
# Dry run
echo "DRY RUN: will not push/deploy/publish anything."
DRY_RUN=true
PUSH_CHANGES=false
export JRELEASER_DRY_RUN=true
function exec_or_dry_run() {
echo "DRY RUN; would have executed:" "${@}"
}
Expand Down Expand Up @@ -118,6 +123,23 @@ function cleanup() {

trap "cleanup" EXIT

#--------------------------------------------

function runJReleaser() {
if [ -f "./jreleaser.yml" ] || [ "$USE_JRELEASER_RELEASE" == "true" ]; then
# JReleaser-based build
source "$SCRIPTS_DIR/jreleaser-setup.sh"
# Execute a JReleaser command such as 'full-release'
$SCRIPTS_DIR/jreleaser/bin/jreleaser full-release \
-Djreleaser.project.version="$RELEASE_VERSION" \
-Djreleaser.project.java.group.id=$($SCRIPTS_DIR/determine-current-project-groupid.sh $PROJECT) \
--config-file $($SCRIPTS_DIR/determine-jreleaser-config-file.sh $PROJECT) \
--basedir $(realpath $WORKSPACE)
fi
}

#--------------------------------------------

#--------------------------------------------
# Actual script

Expand All @@ -132,8 +154,8 @@ export JRELEASER_GPG_HOMEDIR="$RELEASE_GPG_HOMEDIR"
mkdir -p -m 700 "$RELEASE_GPG_HOMEDIR"
IMPORTED_KEY="$(gpg_import "$RELEASE_GPG_PRIVATE_KEY_PATH")"
if [ -z "$IMPORTED_KEY" ]; then
echo "Failed to import GPG key"
exit 1
echo "Failed to import GPG key"
exit 1
fi

RELEASE_VERSION_FAMILY=$(echo "$RELEASE_VERSION" | sed -E 's/^([0-9]+\.[0-9]+).*/\1/')
Expand All @@ -142,26 +164,28 @@ if [ "$PROJECT" == "orm" ] || [ "$PROJECT" == "reactive" ] || [ "$PROJECT" == "m
git config user.email ci@hibernate.org
git config user.name Hibernate-CI

EXTRA_ARGS=""
EXTRA_ARGS=""
if [ "$DRY_RUN" == "true" ]; then
EXTRA_ARGS=" --dry-run"
EXTRA_ARGS=" --dry-run"
fi

if [ -f "./jreleaser.yml" ]; then
# JReleaser-based build
source "$SCRIPTS_DIR/jreleaser-setup.sh"
# Execute a JReleaser command such as 'full-release'
$SCRIPTS_DIR/jreleaser/bin/jreleaser full-release -Djreleaser.project.version="$RELEASE_VERSION"
else
if [ ! -f "./jreleaser.yml" ] && [ "$USE_JRELEASER_RELEASE" == "false" ]; then
EXTRA_ARGS+=" closeAndReleaseSonatypeStagingRepository"
fi
runJReleaser

./gradlew releasePerform -x test \
--no-scan --no-daemon --no-build-cache --stacktrace $EXTRA_ARGS \
-PreleaseVersion=$RELEASE_VERSION -PdevelopmentVersion=$DEVELOPMENT_VERSION \
-PdocPublishBranch=production -PgitRemote=origin -PgitBranch=$BRANCH
--no-scan --no-daemon --no-build-cache --stacktrace $EXTRA_ARGS \
-PreleaseVersion=$RELEASE_VERSION -PdevelopmentVersion=$DEVELOPMENT_VERSION \
-PdocPublishBranch=production -PgitRemote=origin -PgitBranch=$BRANCH
else
bash -xe "$SCRIPTS_DIR/deploy.sh" "$PROJECT"
EXTRA_ARGS=""
if [ "$USE_JRELEASER_RELEASE" == "true" ]; then
EXTRA_ARGS=" -j"
fi
bash -xe "$SCRIPTS_DIR/deploy.sh" "$EXTRA_ARGS" "$PROJECT"
runJReleaser

if [[ "$PROJECT" != "tools" && "$PROJECT" != "hcann" && ! $PROJECT =~ ^infra-.+ ]]; then
exec_or_dry_run bash -xe "$SCRIPTS_DIR/upload-distribution.sh" "$PROJECT" "$RELEASE_VERSION"
exec_or_dry_run bash -xe "$SCRIPTS_DIR/upload-documentation.sh" "$PROJECT" "$RELEASE_VERSION" "$RELEASE_VERSION_FAMILY"
Expand Down
Loading