Skip to content

Commit

Permalink
Adds Kokoro build scripts. (GoogleCloudPlatform#69)
Browse files Browse the repository at this point in the history
* Adds Kokoro build scripts.

* Changes to use gradle-release plugin.
  • Loading branch information
coollog authored Oct 30, 2017
1 parent bf6ece2 commit 47a924c
Show file tree
Hide file tree
Showing 5 changed files with 215 additions and 2 deletions.
11 changes: 9 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ 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'
}
}

repositories {
mavenCentral()
}

apply from: 'scripts/publishing.gradle'
apply from: 'scripts/releasing.gradle'
apply from: 'scripts/google-java-format.gradle'
apply from: 'scripts/checkstyle.gradle'

Expand Down Expand Up @@ -52,6 +52,13 @@ jar {
}
}

test {
testLogging {
showStandardStreams = true
exceptionFormat = 'full'
}
}

task wrapper(type: Wrapper) {
gradleVersion = '4.0'
}
9 changes: 9 additions & 0 deletions kokoro/release_build.sh
Original file line number Diff line number Diff line change
@@ -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
67 changes: 67 additions & 0 deletions kokoro/release_publish.sh
Original file line number Diff line number Diff line change
@@ -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 <variable name>
# 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 '<loggedIn>true</loggedIn>'

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 <session ID> <file>
# 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.
35 changes: 35 additions & 0 deletions kokoro/release_sign.sh
Original file line number Diff line number Diff line change
@@ -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} *
95 changes: 95 additions & 0 deletions scripts/releasing.gradle
Original file line number Diff line number Diff line change
@@ -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 '[email protected]'
}
}
}
}.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
}
}

0 comments on commit 47a924c

Please sign in to comment.