#1419 - Backport directly releasing to maven central to 1.2.x.

By removing our need to use bintray for releases and instead deploying directly to maven central, we can reduce the risk of issues.

Related issue: #1417
This commit is contained in:
Greg L. Turnquist
2020-12-18 09:10:33 -06:00
parent 36e3ad1871
commit b58759a801
8 changed files with 127 additions and 169 deletions

109
Jenkinsfile vendored
View File

@@ -36,7 +36,6 @@ pipeline {
}
options { timeout(time: 30, unit: 'MINUTES') }
steps {
sh 'rm -rf ?'
sh 'PROFILE=none ci/test.sh'
}
}
@@ -52,7 +51,6 @@ pipeline {
}
options { timeout(time: 30, unit: 'MINUTES') }
steps {
sh 'rm -rf ?'
sh 'PROFILE=none ci/test.sh'
}
}
@@ -65,7 +63,6 @@ pipeline {
}
options { timeout(time: 30, unit: 'MINUTES') }
steps {
sh 'rm -rf ?'
sh 'PROFILE=none ci/test.sh'
}
}
@@ -78,7 +75,6 @@ pipeline {
}
options { timeout(time: 30, unit: 'MINUTES') }
steps {
sh 'rm -rf ?'
sh 'PROFILE=spring-next ci/test.sh'
}
}
@@ -91,7 +87,6 @@ pipeline {
}
options { timeout(time: 30, unit: 'MINUTES') }
steps {
sh 'rm -rf ?'
sh 'PROFILE=spring-next ci/test.sh'
}
}
@@ -104,14 +99,13 @@ pipeline {
}
options { timeout(time: 30, unit: 'MINUTES') }
steps {
sh 'rm -rf ?'
sh 'PROFILE=spring-next ci/test.sh'
}
}
}
}
stage('Deploy to Artifactory') {
stage('Deploy') {
agent {
docker {
image 'springci/spring-hateoas-openjdk8-with-graphviz-and-jq:latest'
@@ -122,12 +116,13 @@ pipeline {
environment {
ARTIFACTORY = credentials('02bd1690-b54f-4c9f-819d-a77cb7a9822c')
SONATYPE = credentials('oss-token')
KEYRING = credentials('spring-signing-secring.gpg')
PASSPHRASE = credentials('spring-gpg-passphrase')
}
steps {
script {
sh 'rm -rf ?'
// Warm up this plugin quietly before using it.
sh 'MAVEN_OPTS="-Duser.name=jenkins -Duser.home=/tmp/jenkins-home" ./mvnw -q org.apache.maven.plugins:maven-help-plugin:2.1.1:evaluate -Dexpression=project.version'
@@ -147,23 +142,10 @@ pipeline {
RELEASE_TYPE = 'release'
}
// Capture build output...
OUTPUT = sh(
script: "PROFILE=ci,${RELEASE_TYPE} ci/build.sh",
returnStdout: true
).trim()
echo "$OUTPUT"
// ...to extract artifactory build info
build_info_path = OUTPUT.split('\n')
.find { it.contains('Artifactory Build Info Recorder') }
.split('Saving Build Info to ')[1]
.trim()[1..-2]
// Stash the JSON build info to support promotion to bintray
dir(build_info_path + '/..') {
stash name: 'build_info', includes: "*.json"
if (RELEASE_TYPE == 'release') {
sh "PROFILE=ci,central ci/build-and-deploy-to-maven-central.sh ${PROJECT_VERSION}"
} else {
sh "PROFILE=ci,${RELEASE_TYPE} ci/build-and-deploy-to-artifactory.sh"
}
}
}
@@ -198,81 +180,6 @@ pipeline {
}
}
}
stage('Promote to Bintray') {
when {
branch 'release-1.2'
}
agent {
docker {
image 'springci/spring-hateoas-openjdk8-with-graphviz-and-jq:latest'
args '-v $HOME/.m2:/tmp/jenkins-home/.m2'
}
}
options { timeout(time: 20, unit: 'MINUTES') }
environment {
ARTIFACTORY = credentials('02bd1690-b54f-4c9f-819d-a77cb7a9822c')
}
steps {
script {
sh 'rm -rf ?'
// Warm up this plugin quietly before using it.
sh 'MAVEN_OPTS="-Duser.name=jenkins -Duser.home=/tmp/jenkins-home" ./mvnw -q org.apache.maven.plugins:maven-help-plugin:2.1.1:evaluate -Dexpression=project.version'
PROJECT_VERSION = sh(
script: 'MAVEN_OPTS="-Duser.name=jenkins -Duser.home=/tmp/jenkins-home" ./mvnw org.apache.maven.plugins:maven-help-plugin:2.1.1:evaluate -Dexpression=project.version -o | grep -v INFO',
returnStdout: true
).trim()
if (PROJECT_VERSION.matches(/.*\.[0-9]+$/)) {
unstash name: 'build_info'
sh "ci/promote-to-bintray.sh"
} else {
echo "${PROJECT_VERSION} is not a candidate for promotion to Bintray."
}
}
}
}
stage('Sync to Maven Central') {
when {
branch 'release-1.2'
}
agent {
docker {
image 'springci/spring-hateoas-openjdk8-with-graphviz-and-jq:latest'
args '-v $HOME/.m2:/tmp/jenkins-home/.m2'
}
}
options { timeout(time: 20, unit: 'MINUTES') }
environment {
BINTRAY = credentials('Bintray-spring-operator')
SONATYPE = credentials('oss-token')
}
steps {
script {
sh 'rm -rf ?'
// Warm up this plugin quietly before using it.
sh 'MAVEN_OPTS="-Duser.name=jenkins -Duser.home=/tmp/jenkins-home" ./mvnw -q org.apache.maven.plugins:maven-help-plugin:2.1.1:evaluate -Dexpression=project.version'
PROJECT_VERSION = sh(
script: 'MAVEN_OPTS="-Duser.name=jenkins -Duser.home=/tmp/jenkins-home" ./mvnw org.apache.maven.plugins:maven-help-plugin:2.1.1:evaluate -Dexpression=project.version -o | grep -v INFO',
returnStdout: true
).trim()
if (PROJECT_VERSION.matches(/.*\.[0-9]+$/)) {
unstash name: 'build_info'
sh "ci/sync-to-maven-central.sh"
} else {
echo "${PROJECT_VERSION} is not a candidate for syncing to Maven Central."
}
}
}
}
}
post {

View File

@@ -1,6 +1,6 @@
FROM adoptopenjdk/openjdk8:latest
RUN apt-get update && apt-get install -y graphviz jq
RUN apt-get update && apt-get install -y graphviz jq gpg
RUN apt-get clean \
&& rm -rf /var/lib/apt/lists/*

View File

@@ -2,4 +2,9 @@
set -euo pipefail
#
# Deploy the artifactory
#
echo 'Deploying to Artifactory...'
MAVEN_OPTS="-Duser.name=jenkins -Duser.home=/tmp/jenkins-home" ./mvnw -P${PROFILE} -Dmaven.test.skip=true clean deploy -B

View File

@@ -0,0 +1,25 @@
#!/bin/bash -x
set -euo pipefail
PROJECT_VERSION=$1
#
# Stage on Maven Central
#
echo 'Staging on Maven Central...'
GNUPGHOME=/tmp/gpghome
export GNUPGHOME
mkdir $GNUPGHOME
cp $KEYRING $GNUPGHOME
MAVEN_OPTS="-Duser.name=jenkins -Duser.home=/tmp/jenkins-home" ./mvnw \
-s settings.xml \
-P${PROFILE} \
-Dmaven.test.skip=true \
-Dgpg.passphrase=${PASSPHRASE} \
-Dgpg.secretKeyring=${GNUPGHOME}/secring.gpg \
-DstagingDescription="Releasing ${PROJECT_VERSION}" \
clean deploy -B

View File

@@ -1,42 +0,0 @@
#!/bin/bash
set -e -u
buildName=`jq -r '.name' build-info.json`
buildNumber=`jq -r '.number' build-info.json`
groupId=`jq -r '.modules[0].id' build-info.json | sed 's/\(.*\):.*:.*/\1/'`
version=`jq -r '.modules[0].id' build-info.json | sed 's/.*:.*:\(.*\)/\1/'`
echo "Promoting ${buildName}/${buildNumber}/${groupId}/${version} to libs-release-local"
curl \
-s \
--connect-timeout 240 \
--max-time 2700 \
-u ${ARTIFACTORY_USR}:${ARTIFACTORY_PSW} \
-H 'Content-type:application/json' \
-d '{"sourceRepos": ["libs-release-local"], "targetRepo" : "spring-distributions", "async":"true"}' \
-f \
-X \
POST "https://repo.spring.io/api/build/distribute/${buildName}/${buildNumber}" > /dev/null || { echo "Failed to distribute" >&2; exit 1; }
echo "Waiting for artifacts to be published"
ARTIFACTS_PUBLISHED=false
WAIT_TIME=10
COUNTER=0
while [ $ARTIFACTS_PUBLISHED == "false" ] && [ $COUNTER -lt 120 ]; do
result=$( curl -s https://api.bintray.com/packages/spring/jars/"${groupId}" )
versions=$( echo "$result" | jq -r '.versions' )
exists=$( echo "$versions" | grep "$version" -o || true )
if [ "$exists" = "$version" ]; then
ARTIFACTS_PUBLISHED=true
fi
COUNTER=$(( COUNTER + 1 ))
sleep $WAIT_TIME
done

View File

@@ -1,23 +0,0 @@
#!/bin/bash
set -e -u
buildName=`jq -r '.name' build-info.json`
buildNumber=`jq -r '.number' build-info.json`
groupId=`jq -r '.modules[0].id' build-info.json | sed 's/\(.*\):.*:.*/\1/'`
version=`jq -r '.modules[0].id' build-info.json | sed 's/.*:.*:\(.*\)/\1/'`
echo "Syncing ${buildName}/${buildNumber}/${groupId}/${version} to Maven Central..."
curl \
-s \
--connect-timeout 240 \
--max-time 2700 \
-u ${BINTRAY_USR}:${BINTRAY_PSW} \
-H 'Content-Type: application/json' \
-d "{ \"username\": \"${SONATYPE_USR}\", \"password\": \"${SONATYPE_PSW}\"}" \
-f \
-X \
POST "https://api.bintray.com/maven_central_sync/spring/jars/${groupId}/versions/${version}" > /dev/null || { echo "Failed to sync" >&2; exit 1; }
echo "Sync complete"

78
pom.xml
View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.hateoas</groupId>
@@ -635,6 +635,80 @@
</build>
</profile>
<profile>
<id>central</id>
<build>
<pluginManagement>
<plugins>
<!-- Sign JARs -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
<configuration>
<gpgArguments>
<arg>--pinentry-mode</arg>
<arg>loopback</arg>
</gpgArguments>
</configuration>
</execution>
</executions>
</plugin>
<!-- Deploy to Sonatype OSS Nexus -->
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.8</version>
<extensions>true</extensions>
<configuration>
<serverId>sonatype</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
<keepStagingRepositoryOnFailure>true</keepStagingRepositoryOnFailure>
<skipStagingRepositoryClose>false</skipStagingRepositoryClose>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<distributionManagement>
<repository>
<id>sonatype</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
</profile>
</profiles>
<dependencyManagement>
@@ -839,7 +913,7 @@
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
<optional>true</optional>
<optional>true</optional>
</dependency>
<dependency>

12
settings.xml Normal file
View File

@@ -0,0 +1,12 @@
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>sonatype</id>
<username>${env.SONATYPE_USR}</username>
<password>${env.SONATYPE_PSW}</password>
</server>
</servers>
</settings>