From 47a924c4181b406416c5530c985541b57f6d7266 Mon Sep 17 00:00:00 2001 From: Qingyang Chen Date: Mon, 30 Oct 2017 16:07:49 -0400 Subject: [PATCH] Adds Kokoro build scripts. (#69) * Adds Kokoro build scripts. * Changes to use gradle-release plugin. --- build.gradle | 11 ++++- kokoro/release_build.sh | 9 ++++ kokoro/release_publish.sh | 67 +++++++++++++++++++++++++++ kokoro/release_sign.sh | 35 +++++++++++++++ scripts/releasing.gradle | 95 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 215 insertions(+), 2 deletions(-) create mode 100644 kokoro/release_build.sh create mode 100755 kokoro/release_publish.sh create mode 100644 kokoro/release_sign.sh create mode 100644 scripts/releasing.gradle diff --git a/build.gradle b/build.gradle index 6d81687..ea32584 100644 --- a/build.gradle +++ b/build.gradle @@ -10,8 +10,8 @@ buildscript { } } dependencies { - classpath 'com.bmuschko:gradle-nexus-plugin:2.3.1' classpath 'gradle.plugin.com.github.sherter.google-java-format:google-java-format-gradle-plugin:0.6' + classpath 'net.researchgate:gradle-release:2.6.0' } } @@ -19,7 +19,7 @@ repositories { mavenCentral() } -apply from: 'scripts/publishing.gradle' +apply from: 'scripts/releasing.gradle' apply from: 'scripts/google-java-format.gradle' apply from: 'scripts/checkstyle.gradle' @@ -52,6 +52,13 @@ jar { } } +test { + testLogging { + showStandardStreams = true + exceptionFormat = 'full' + } +} + task wrapper(type: Wrapper) { gradleVersion = '4.0' } diff --git a/kokoro/release_build.sh b/kokoro/release_build.sh new file mode 100644 index 0000000..81b6042 --- /dev/null +++ b/kokoro/release_build.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +# Fail on any error. +set -e +# Display commands to stderr. +set -x + +cd github/endpoints-framework-gradle-plugin +./gradlew check prepareRelease diff --git a/kokoro/release_publish.sh b/kokoro/release_publish.sh new file mode 100755 index 0000000..a3d64df --- /dev/null +++ b/kokoro/release_publish.sh @@ -0,0 +1,67 @@ +#!/bin/bash + +# Fail on any error. +set -e + +CREDENTIALS="$SONATYPE_USERNAME:$SONATYPE_PASSWORD" + +# Display commands to stderr. +set -x + +# Goes to the GCS directory. +cd $KOKORO_GFILE_DIR + +# Finds the latest ubuntu/release-sign build directory. +LAST_BUILD=$(ls prod/endpoints-framework-gradle-plugin/ubuntu/release-sign/ | sort -rV | head -1) + +# Finds the bundled jar file in the latest signed artifact directory. +BUNDLED_JAR_FILE=$(find `pwd`/prod/endpoints-framework-gradle-plugin/ubuntu/release-sign/${LAST_BUILD}/* -type f \( -iname \*-bundle.jar \)) + +# Usage: GetSessionID +# Uses the environment variable CREDENTIALS. +# Stores the Nexus session ID in the given variable. +GetSessionID() { + local __resultvar=$1 + + # Makes a temporary file to store the login cookies. + local cookies_temp=$(mktemp /tmp/sonatype_cookies.XXXXXXX) + + # Sends a login request. + { local login_response=$(curl 'https://oss.sonatype.org/service/local/authentication/login' -X 'GET' -u "$CREDENTIALS" -c $cookies_temp 2> /dev/null); } 2> /dev/null + + # Checks if login was successful. + echo $login_response | grep -q 'true' + + local login_check=$(echo -n $?) + + if [ "$login_check" -eq "1" ]; then + return 1 + fi + + # Extracts the session ID from the cookies. + local nxsessionid + local nxsessionid_line=$(cat $cookies_temp | grep 'NXSESSIONID') + nxsessionid=$(echo -n $nxsessionid_line | awk '{print $NF}') + + eval $__resultvar="'$nxsessionid'" +} + +# Usage: UploadJAR +# Uploads the bundled JAR file to the Nexus Staging Repository. +UploadJAR() { + curl 'https://oss.sonatype.org/service/local/staging/bundle_upload' -H "Cookie: NXSESSIONID=$1" -H 'Content-Type: multipart/form-data' --compressed -F "file=@$2" +} + +# Gets the session ID. +GetSessionID NXSESSIONID +if [ $? -eq 1 ]; then + echo 'Login failed!' + exit 1 +fi +echo 'Login successful.' + +# Uploads the bundled JAR file. +echo 'Uploading artifact...' +UploadJAR $NXSESSIONID $BUNDLED_JAR_FILE + +# TODO: Release on Sonatype. diff --git a/kokoro/release_sign.sh b/kokoro/release_sign.sh new file mode 100644 index 0000000..d6f780d --- /dev/null +++ b/kokoro/release_sign.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +# Fail on any error. +set -e +# Display commands being run. +set -x + +cd $KOKORO_GFILE_DIR +mkdir signed && chmod 777 signed + +# find the latest directory under prod/endpoints-framework-gradle-plugin/gcp_ubuntu/release-build/ +LAST_BUILD=$(ls prod/endpoints-framework-gradle-plugin/gcp_ubuntu/release-build/ | sort -rV | head -1) + +# find the jars and the pom in the latest build artifact directory +FILES=$(find `pwd`/prod/endpoints-framework-gradle-plugin/gcp_ubuntu/release-build/${LAST_BUILD}/* -type f \( -iname \*.jar -o -iname \*.pom \)) + +for f in $FILES +do + echo "Processing $f file..." + filename=$(basename "$f") + mv $f signed/$filename + if /escalated_sign/escalated_sign.py -j /escalated_sign_jobs -t linux_gpg_sign \ + `pwd`/signed/$filename + then echo "Signed $filename" + else + echo "Could not sign $filename" + exit 1 + fi +done + +# bundle the artifacts for manual deploy to the Maven staging repository +cd signed +POM_NAME=$(ls *.pom) +BUNDLE_NAME=${POM_NAME%.pom}-bundle.jar +jar -cvf ${BUNDLE_NAME} * diff --git a/scripts/releasing.gradle b/scripts/releasing.gradle new file mode 100644 index 0000000..488b2d1 --- /dev/null +++ b/scripts/releasing.gradle @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2017 Google Inc. All Right Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// This script contains +// 1. The release builder (for building releasable bundles) +// 2. The release helper (for git tagging and version automation) + +// Release builder (provides prepareRelease script) +apply plugin: 'maven' + +task sourceJar(type: Jar) { + from sourceSets.main.allJava + classifier 'sources' +} + +task javadocJar(type: Jar, dependsOn: javadoc) { + from javadoc.destinationDir + classifier = 'javadoc' +} + +task writePom { + project.afterEvaluate { + def outputFile = file("$buildDir/pom/${project.name}-${project.version}.pom") + outputs.file outputFile + + doLast { + pom { + project { + name 'Endpoints Framework Gradle Plugin' + description 'This Gradle plugin provides tasks and configurations to generate Google Cloud Endpoints Framework client code and discovery docs' + url 'https://github.com/GoogleCloudPlatform/endpoints-framework-gradle-plugin' + inceptionYear '2016' + + scm { + url 'https://github.com/GoogleCloudPlatform/endpoints-framework-gradle-plugin' + connection 'scm:https://github.com/GoogleCloudPlatform/endpoints-framework-gradle-plugin.git' + developerConnection 'scm:git://github.com/GoogleCloudPlatform/endpoints-framework-gradle-plugin.git' + } + + licenses { + license { + name 'The Apache Software License, Version 2.0' + url 'http://www.apache.org/licenses/LICENSE-2.0.txt' + distribution 'repo' + } + } + + developers { + developer { + id 'loosebazooka' + name 'Appu Goundan' + email 'appu@google.com' + } + } + } + }.writeTo(outputFile) + } + } +} + +task prepareRelease(type: Copy) { + from jar + from sourceJar + from javadocJar + from writePom + + into "${buildDir}/release-artifacts" + + dependsOn build + dependsOn cleanPrepareRelease +} + +// Release helper (git release commits and version updates) +apply plugin: 'net.researchgate.release' + +release { + tagTemplate = 'v$version' + git { + requireBranch = /^release_v\d+.*$/ //regex + } +}