Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add jenkins scripts #37

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
139 changes: 139 additions & 0 deletions jenkins-scripts/api-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
#!/bin/bash -ex

TOOLS_PREFIX='/opt/tools'
JAVA_PREFIX="${TOOLS_PREFIX}/java/oracle"
MVN_HOME="${TOOLS_PREFIX}/apache-maven/latest"
JAVA_HOME="${JAVA_PREFIX}/jdk-8/latest"
PATH="${MVN_HOME}/bin:${JAVA_HOME}/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

# Maven plugins
VERSIONS_PLUGIN='org.codehaus.mojo:versions-maven-plugin:2.7'
HELP_PLUGIN='org.apache.maven.plugins:maven-help-plugin:3.1.0'

# Top level pom.xml is in root directory
# Check whether top level pom.xml contains SNAPSHOT version
if ! grep '<version>' pom.xml | grep 'SNAPSHOT' ; then
echo '-[ Missing SNAPSHOT version in POM! ]-------------------------------------------'
exit 1
fi

# Compute release versions
SNAPSHOT_VERSION=`mvn -B ${HELP_PLUGIN}:evaluate -Dexpression=project.version 2> /dev/null | grep -E '^[0-9]+(\.[0-9]+)+-SNAPSHOT$'`

if [ -z "${RELEASE_VERSION}" ]; then
if [ -z ${SNAPSHOT_VERSION} ]; then
echo '-[ Missing required snapshot version number! ]----------------------------------'
fi
RELEASE_VERSION=`echo ${SNAPSHOT_VERSION} | sed -e 's/-SNAPSHOT//'`
fi

# Bash specific code
if [ -z "${NEXT_VERSION}" ]; then
NEXT_VERSION=`echo ${RELEASE_VERSION} | sed -e 's/\([0-9][0-9]*\.[0-9][0-9]*\).*/\1/'`
set -f
NEXT_COMPONENTS=(${RELEASE_VERSION//\./ })
LAST_INDEX=$((${#NEXT_COMPONENTS[@]} - 1))
NEXT_COMPONENTS[${LAST_INDEX}]=$((${NEXT_COMPONENTS[${LAST_INDEX}]} + 1))
NEXT_VERSION=`echo ${NEXT_COMPONENTS[@]} | tr ' ' '.'`'-SNAPSHOT'
fi

RELEASE_TAG="${RELEASE_VERSION}"
RELEASE_BRANCH="${RELEASE_VERSION}"-BRANCH

echo "Current version: ${SNAPSHOT_VERSION}"
echo "Release version: ${RELEASE_VERSION}"
echo "Next version: ${NEXT_VERSION}"
echo "Release tag: ${RELEASE_TAG}"

if [ -z "${SNAPSHOT_VERSION}" -o -z "${RELEASE_VERSION}" -o -z "${NEXT_VERSION}" ]; then
echo '-[ Missing required version numbers! ]------------------------------------------'
exit 1
fi

if [ ${DRY_RUN} = 'true' ]; then
echo '-[ Dry run turned on ]----------------------------------------------------------'
MVN_DEPLOY_ARGS=''
echo '-[ Skipping GitHub branch and tag checks ]--------------------------------------'
else
MVN_DEPLOY_ARGS='deploy:deploy'
GIT_ORIGIN=`git remote`
echo '-[ Prepare branch ]-------------------------------------------------------------'
if [[ -n `git branch -r | grep "${GIT_ORIGIN}/${RELEASE_BRANCH}"` ]]; then
if [ "${OVERWRITE}" = 'true' ]; then
echo "${GIT_ORIGIN}/${RELEASE_BRANCH} branch already exists, deleting"
git push --delete origin "${RELEASE_BRANCH}" && true
else
echo "Error: ${GIT_ORIGIN}/${RELEASE_BRANCH} branch already exists"
exit 1
fi
fi
echo '-[ Release tag cleanup ]--------------------------------------------------------'
if [[ -n `git ls-remote --tags ${GIT_ORIGIN} | grep "${RELEASE_TAG}"` ]]; then
if [ "${OVERWRITE}" = 'true' ]; then
echo "${RELEASE_TAG} tag already exists, deleting"
git push --delete origin "${RELEASE_TAG}" && true
else
echo "Error: ${RELEASE_TAG} tag already exists"
exit 1
fi
fi
fi

# Always delete local branch if exists
git branch --delete "${RELEASE_BRANCH}" && true
git checkout -b ${RELEASE_BRANCH}
# Always delete local tag if exists
git tag --delete "${RELEASE_TAG}" && true

# Setup jakartaee-stable-bot account information
git config --global user.email "[email protected]"
git config --global user.name "Eclipse jakartaee-stable Bot"
# Workaround: GPG initialization
gpg --batch --import ${KEYRING}
for fpr in $(gpg --list-keys --with-colons | awk -F: '/fpr:/ {print $10}' | sort -u);
do
echo -e "5\ny\n" | gpg --batch --command-fd 0 --expert --edit-key $fpr trust;
done

# Project identifiers
ARTIFACT_ID=$(mvn -B ${HELP_PLUGIN}:evaluate -Dexpression=project.artifactId | grep -Ev '(^\[)')
GROUP_ID=$(mvn -B ${HELP_PLUGIN}:evaluate -Dexpression=project.groupId | grep -Ev '(^\[)')

echo '-[ Set release version ]--------------------------------------------------------'
# Set release version
mvn -U -C \
-DnewVersion="${RELEASE_VERSION}" \
-DgenerateBackupPoms=false \
clean ${VERSIONS_PLUGIN}:set

echo '-[ Commit modified pom.xml files ]----------------------------------------------'
POM_FILES=`git status | grep -E 'modified:.*pom\.xml' | sed -e 's/[[:space:]][[:space:]]*modified:[[:space:]][[:space:]]*//'`
git add ${POM_FILES} && \
git commit -m "Prepare release ${GROUP_ID}:${ARTIFACT_ID}:${RELEASE_VERSION}"

echo '-[ Deploy artifacts to staging repository ]-------------------------------------'
mvn -U -C -s /home/jenkins/.m2/settings-jakartaee-stable.xml \
-DskipTests -Ddoclint=none -Dstatus="${STATUS}" -Poss-release -Pstaging \
clean package source:jar javadoc:jar gpg:sign install:install ${MVN_DEPLOY_ARGS}

echo '-[ Tag release ]----------------------------------------------------------------'
git tag "${RELEASE_TAG}" -m "Release ${GROUP_ID}:${ARTIFACT_ID}:${RELEASE_VERSION}"

echo '-[ Set next snapshot version ]--------------------------------------------------'
mvn -U -C \
-DnewVersion="${NEXT_VERSION}" \
-DgenerateBackupPoms=false \
clean ${VERSIONS_PLUGIN}:set

echo '-[ Commit modified pom.xml files ]----------------------------------------------'
POM_FILES=`git status | grep -E 'modified:.*pom\.xml' | sed -e 's/[[:space:]][[:space:]]*modified:[[:space:]][[:space:]]*//'`
git add ${POM_FILES} && \
git commit -m "Prepare next development cycle for ${NEXT_VERSION}"

if [ ${DRY_RUN} = 'true' ]; then
echo '-[ Skipping GitHub update ]-----------------------------------------------------'
else
echo '-[ Push branch and tag to GitHub ]----------------------------------------------'
git push origin "${RELEASE_BRANCH}"
git push origin "${RELEASE_TAG}"
fi
36 changes: 36 additions & 0 deletions jenkins-scripts/nexus-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash -ex

TOOLS_PREFIX='/opt/tools'
JAVA_PREFIX="${TOOLS_PREFIX}/java/oracle"
MVN_HOME="${TOOLS_PREFIX}/apache-maven/latest"
JAVA_HOME="${JAVA_PREFIX}/jdk-8/latest"
PATH="${MVN_HOME}/bin:${JAVA_HOME}/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

# Maven plugins
HELP_PLUGIN='org.apache.maven.plugins:maven-help-plugin:3.1.0'
NEXUS_PLUGIN='org.sonatype.plugins:nexus-staging-maven-plugin:1.6.7'
NEXUS_PLUGIN_PARAMS='-DnexusUrl=https://oss.sonatype.org/ -DserverId=ossrh'


mvnq() {
# filter out progress reports (-B) and download details
mvn -B "$@" | grep -v '^\[INFO\] Download'
}

#
# List all the profiles, then for each profile,
# list all the repositories and release them.
# XXX - Assumes we want to release everything that's currently staged.
#
for name in $(mvnq -B ${NEXUS_PLUGIN_PARAMS} ${NEXUS_PLUGIN}:rc-list-profiles | \
grep -v 'Central Bundles' | \
awk '$3 == "BOTH" {print $4}')
do
name=${name//./} # squash out all the dots
for id in $(mvnq -B ${NEXUS_PLUGIN_PARAMS} ${NEXUS_PLUGIN}:rc-list | \
awk '$1 ~ /\[INFO\]/ && $2 ~ /^'"${name}"'\-[0-9]+$/ {print $2}')
do
echo "Releasing $id"
mvnq -DstagingRepositoryId="$id" ${NEXUS_PLUGIN_PARAMS} ${NEXUS_PLUGIN}:rc-release
done
done
135 changes: 135 additions & 0 deletions jenkins-scripts/nexus-staging.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
#!/bin/bash -ex

TOOLS_PREFIX='/opt/tools'
JAVA_PREFIX="${TOOLS_PREFIX}/java/oracle"
MVN_HOME="${TOOLS_PREFIX}/apache-maven/latest"
JAVA_HOME="${JAVA_PREFIX}/jdk-8/latest"
PATH="${MVN_HOME}/bin:${JAVA_HOME}/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

# Maven plugins
HELP_PLUGIN='org.apache.maven.plugins:maven-help-plugin:3.1.0'
NEXUS_PLUGIN='org.sonatype.plugins:nexus-staging-maven-plugin:1.6.7'
NEXUS_PLUGIN_PARAMS='-DnexusUrl=https://oss.sonatype.org/ -DserverId=ossrh'

case "${PROJECT}" in

'Enterprise-Deployment')
GIT_REPO='[email protected]:eclipse-ee4j/enterprise-deployment.git'
STAGING_NAME='jakartaenterprisedeploy'
;;

'JAX-RPC-API')
GIT_REPO='[email protected]:eclipse-ee4j/jax-rpc-api.git'
STAGING_NAME='jakartaxmlrpc'
;;

'JAXR-API')
GIT_REPO='[email protected]:eclipse-ee4j/jaxr-api.git'
STAGING_NAME='jakartaxmlregistry'
;;

'Management-API')
GIT_REPO='[email protected]:eclipse-ee4j/management-api.git'
STAGING_NAME='jakartamanagementj2ee'
;;

*)
if [ "${ACTION}" != 'list' ]; then
echo '-[ Error ]----------------------------------------------------------------------'
echo 'No project selected, exitting.'
exit 1
else
GIT_REPO=''
fi
;;

esac

if [ -n "${GIT_REPO}" ]; then
echo '-[ Cloning Project Repository ]-------------------------------------------------'
git clone ${GIT_REPO} . && git checkout ${BRANCH}
echo '-[ Reading project identifiers ]------------------------------------------------'
if [ -n "${BUILD_DIR}" ]; then
cd ${BUILD_DIR}
fi
# Project identifiers
ARTIFACT_ID=$(mvn -B ${HELP_PLUGIN}:evaluate -Dexpression=project.artifactId | grep -Ev '(^\[)')
GROUP_ID=$(mvn -B ${HELP_PLUGIN}:evaluate -Dexpression=project.groupId | grep -Ev '(^\[)')
fi


echo "Project: ${PROJECT} API"
echo "Action: ${ACTION}"
echo "Repository ID prefix: ${STAGING_NAME}"
echo "Artifact: ${GROUP_ID}:${ARTIFACT_ID}"


case "${ACTION}" in

'list')

echo '-[ Profiles List ]--------------------------------------------------------------'
mvn -B ${NEXUS_PLUGIN_PARAMS} ${NEXUS_PLUGIN}:rc-list-profiles
echo '-[ Staging Repository List ]----------------------------------------------------'
if [ -n "${STAGING_NAME}" ]; then
mvn -B ${NEXUS_PLUGIN_PARAMS} ${NEXUS_PLUGIN}:rc-list | egrep "^\[INFO\] ${STAGING_NAME}\-[0-9]+[ ]+[A-Z]+[ ]" || true
else
mvn -B ${NEXUS_PLUGIN_PARAMS} ${NEXUS_PLUGIN}:rc-list
fi
;;

'close')

if [ -z "${VERSION}" ]; then
echo '-[ Missing version number ]-----------------------------------------------------'
exit 1
fi
STAGING_DESC="${GROUP_ID}:${ARTIFACT_ID}:${VERSION}"
echo "Project description: ${STAGING_DESC}"
echo '-[ Searching for open deployment ]----------------------------------------------'

# Get the ID of the opem staging repository
# if [ "${PROJECT}" = 'JAX-RPC-API' ]; then
# STAGING_REPO_ID=$(mvn -B ${NEXUS_PLUGIN_PARAMS} ${NEXUS_PLUGIN}:rc-list | \
# egrep "^\[INFO\] .*\-[0-9]+[ ]+OPEN[ ]+.*${STAGING_NAME}" | \
# awk '{print $2}' | head -1)
# else
STAGING_REPO_ID=$(mvn -B ${NEXUS_PLUGIN_PARAMS} ${NEXUS_PLUGIN}:rc-list | \
egrep "^\[INFO\] ${STAGING_NAME}\-[0-9]+[ ]+OPEN[ ]" | \
awk '{print $2}' | head -1)
# fi
echo "Nexus staging repository ID: ${STAGING_REPO_ID}"

if [ -n "${STAGING_REPO_ID}" ]; then
echo '-[ Closing Nexus staging repository ]-------------------------------------------'
mvn -B ${NEXUS_PLUGIN_PARAMS} ${NEXUS_PLUGIN}:rc-close \
-DstagingRepositoryId="${STAGING_REPO_ID}" \
-DstagingDescription="${STAGING_DESC}"
else
echo '-[ Delpoyment '${STAGING_NAME}' was not found ]------------------------------------'
fi
;;

'drop')

if [ -z "${VERSION}" ]; then
echo '-[ Searching for deployments ]----------------------------------------------'
for REPO_ID in $(mvn -B ${NEXUS_PLUGIN_PARAMS} ${NEXUS_PLUGIN}:rc-list | \
egrep "^\[INFO\] ${STAGING_NAME}\-[0-9]+[ ]+[A-Z]+[ ]" | \
awk '{print $2}' | head -1); do
echo '-[ Dropping Nexus staging repository ]------------------------------------------'
echo "Deployment: ${REPO_ID}"
mvn -B ${NEXUS_PLUGIN_PARAMS} ${NEXUS_PLUGIN}:rc-drop \
-DstagingRepositoryId="${REPO_ID}"
done
else
mvn -B ${NEXUS_PLUGIN_PARAMS} ${NEXUS_PLUGIN}:rc-drop \
-DstagingRepositoryId="${VERSION}"
fi
;;

release)
echo '-[ Action denied for security reasons ]-------------------------------------'
;;

esac