From b58759a801770eb9f4de100d39a6d64615491e7b Mon Sep 17 00:00:00 2001 From: "Greg L. Turnquist" Date: Fri, 18 Dec 2020 09:10:33 -0600 Subject: [PATCH] #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 --- Jenkinsfile | 109 ++---------------- ci/Dockerfile | 2 +- ....sh => build-and-deploy-to-artifactory.sh} | 5 + ci/build-and-deploy-to-maven-central.sh | 25 ++++ ci/promote-to-bintray.sh | 42 ------- ci/sync-to-maven-central.sh | 23 ---- pom.xml | 78 ++++++++++++- settings.xml | 12 ++ 8 files changed, 127 insertions(+), 169 deletions(-) rename ci/{build.sh => build-and-deploy-to-artifactory.sh} (70%) create mode 100755 ci/build-and-deploy-to-maven-central.sh delete mode 100755 ci/promote-to-bintray.sh delete mode 100755 ci/sync-to-maven-central.sh create mode 100644 settings.xml diff --git a/Jenkinsfile b/Jenkinsfile index dc847308..7500bf77 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -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 { diff --git a/ci/Dockerfile b/ci/Dockerfile index 756af281..ccffe63b 100644 --- a/ci/Dockerfile +++ b/ci/Dockerfile @@ -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/* diff --git a/ci/build.sh b/ci/build-and-deploy-to-artifactory.sh similarity index 70% rename from ci/build.sh rename to ci/build-and-deploy-to-artifactory.sh index 619bebf6..1c6b6d1e 100755 --- a/ci/build.sh +++ b/ci/build-and-deploy-to-artifactory.sh @@ -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 diff --git a/ci/build-and-deploy-to-maven-central.sh b/ci/build-and-deploy-to-maven-central.sh new file mode 100755 index 00000000..d4f8b48d --- /dev/null +++ b/ci/build-and-deploy-to-maven-central.sh @@ -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 \ No newline at end of file diff --git a/ci/promote-to-bintray.sh b/ci/promote-to-bintray.sh deleted file mode 100755 index a00bb8d6..00000000 --- a/ci/promote-to-bintray.sh +++ /dev/null @@ -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 diff --git a/ci/sync-to-maven-central.sh b/ci/sync-to-maven-central.sh deleted file mode 100755 index 7150ca76..00000000 --- a/ci/sync-to-maven-central.sh +++ /dev/null @@ -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" diff --git a/pom.xml b/pom.xml index 2a9fd8d8..c4cd6b40 100644 --- a/pom.xml +++ b/pom.xml @@ -1,6 +1,6 @@ + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 org.springframework.hateoas @@ -635,6 +635,80 @@ + + central + + + + + + + + org.apache.maven.plugins + maven-gpg-plugin + 1.6 + + + sign-artifacts + verify + + sign + + + + --pinentry-mode + loopback + + + + + + + + + + org.sonatype.plugins + nexus-staging-maven-plugin + 1.6.8 + true + + sonatype + https://oss.sonatype.org/ + true + true + false + + + + + + + + + + org.apache.maven.plugins + maven-gpg-plugin + + + + org.sonatype.plugins + nexus-staging-maven-plugin + + + + + + + + + sonatype + https://oss.sonatype.org/service/local/staging/deploy/maven2/ + + + + + + @@ -839,7 +913,7 @@ org.springframework spring-test ${spring.version} - true + true diff --git a/settings.xml b/settings.xml new file mode 100644 index 00000000..13009166 --- /dev/null +++ b/settings.xml @@ -0,0 +1,12 @@ + + + + + sonatype + ${env.SONATYPE_USR} + ${env.SONATYPE_PSW} + + + \ No newline at end of file