Skip to content

Commit

Permalink
chore: Test script
Browse files Browse the repository at this point in the history
  • Loading branch information
lqiu96 committed Sep 10, 2024
1 parent cc3c43b commit 3dccf7e
Showing 1 changed file with 65 additions and 76 deletions.
141 changes: 65 additions & 76 deletions .kokoro/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,82 +15,80 @@

set -eo pipefail

function install_new_shared_deps() {
# Store the current Java version since the version may change when installing sdk-platform-java
current_java_home=$JAVA_HOME
# Store the current Java version since the version may change when installing sdk-platform-java
current_java_home=$JAVA_HOME

# Get the current proto runtime version used in this repo
CURRENT_PROTO_VERSION=$(mvn -ntp help:effective-pom |
sed -n "/<artifactId>protobuf-java<\/artifactId>/,/<\/dependency>/ {
/<version>/{
s/<version>\(.*\)<\/version>/\1/p
q
}
}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
echo "The current proto version is: ${CURRENT_PROTO_VERSION}"

# Find the latest proto runtime version available
LATEST_PROTO_VERSION="4.27.4"
echo "The latest proto version is: ${LATEST_PROTO_VERSION}"

# Only reinstall shared-deps again to test for a newer proto version
if [[ "${CURRENT_PROTO_VERSION}" != "${LATEST_PROTO_VERSION}" ]]; then
# testing-infra-docker has Java 11 installed in java8 docker container. Use this as sdk-platform-java
# needs Java 11+ to run with GraalVM. For GH actions, JAVA11_HOME does not exist and would skip this.
if [ ! -z "${JAVA11_HOME}" ]; then
export JAVA_HOME="${JAVA11_HOME}"
export PATH=${JAVA_HOME}/bin:$PATH
fi

# Get the current proto runtime version used in this repo
CURRENT_PROTO_VERSION=$(mvn -ntp help:effective-pom |
sed -n "/<artifactId>protobuf-java<\/artifactId>/,/<\/dependency>/ {
pushd /tmp
git clone https://github.com/googleapis/sdk-platform-java.git
pushd sdk-platform-java
pushd gapic-generator-java-pom-parent
sed -i "/<protobuf.version>.*<\/protobuf.version>/s/\(.*<protobuf.version>\).*\(<\/protobuf.version>\)/\1${LATEST_PROTO_VERSION}\2/" pom.xml
# sdk-platform-java
popd

pushd sdk-platform-java-config
# Get current Shared-Deps version in sdk-platform-java
SHARED_DEPS_VERSION=$(mvn -ntp help:effective-pom |
sed -n "/<artifactId>sdk-platform-java-config<\/artifactId>/,/<\/dependency>/ {
/<version>/{
s/<version>\(.*\)<\/version>/\1/p
q
}
}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
echo "The current proto version is: ${CURRENT_PROTO_VERSION}"

# Find the latest proto runtime version available
LATEST_PROTO_VERSION="4.27.4"
echo "The latest proto version is: ${LATEST_PROTO_VERSION}"
echo "Shared-Deps Version: ${SHARED_DEPS_VERSION}"
# sdk-platform-java
popd

# Only reinstall shared-deps again to test for a newer proto version
if [[ "${CURRENT_PROTO_VERSION}" != "${LATEST_PROTO_VERSION}" ]]; then
# testing-infra-docker has Java 11 installed in java8 docker container. Use this as sdk-platform-java
# needs Java 11+ to run with GraalVM. For GH actions, JAVA11_HOME does not exist and would skip this.
if [ ! -z "${JAVA11_HOME}" ]; then
export JAVA_HOME="${JAVA11_HOME}"
export PATH=${JAVA_HOME}/bin:$PATH
mvn clean install -q -ntp \
-DskipTests=true \
-Dclirr.skip=true \
-Denforcer.skip=true \
-T 1C
# /tmp
popd

# Back to the original directory of the repo
popd
# Find all the poms with a reference to shared-deps and update to the new local version
poms=($(find . -name pom.xml))
for pom in "${poms[@]}"; do
if grep -q "sdk-platform-java-config" "${pom}"; then
echo "Updating the pom: ${pom} to use shared-deps version: ${SHARED_DEPS_VERSION}"
sed -i "/<artifactId>sdk-platform-java-config<\/artifactId>/,/<\/parent>/ s/<version>.*<\/version>/<version>$SHARED_DEPS_VERSION<\/version>/" "${pom}"
# xmlstarlet ed --inplace -N x="http://maven.apache.org/POM/4.0.0" \
# -u "//x:project/x:parent[x:artifactId='sdk-platform-java-config']/x:version" \
# -v "${SHARED_DEPS_VERSION}" \
# "${pom}"
fi
done

pushd /tmp
git clone https://github.com/googleapis/sdk-platform-java.git
pushd sdk-platform-java
pushd gapic-generator-java-pom-parent
sed -i "/<protobuf.version>.*<\/protobuf.version>/s/\(.*<protobuf.version>\).*\(<\/protobuf.version>\)/\1${LATEST_PROTO_VERSION}\2/" pom.xml
# sdk-platform-java
popd

pushd sdk-platform-java-config
# Get current Shared-Deps version in sdk-platform-java
SHARED_DEPS_VERSION=$(mvn -ntp help:effective-pom |
sed -n "/<artifactId>sdk-platform-java-config<\/artifactId>/,/<\/dependency>/ {
/<version>/{
s/<version>\(.*\)<\/version>/\1/p
q
}
}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
echo "Shared-Deps Version: ${SHARED_DEPS_VERSION}"
# sdk-platform-java
popd

mvn clean install -q -ntp \
-DskipTests=true \
-Dclirr.skip=true \
-Denforcer.skip=true \
-T 1C
# /tmp
popd

# Back to the original directory of the repo
popd
# Find all the poms with a reference to shared-deps and update to the new local version
poms=($(find . -name pom.xml))
for pom in "${poms[@]}"; do
if grep -q "sdk-platform-java-config" "${pom}"; then
echo "Updating the pom: ${pom} to use shared-deps version: ${SHARED_DEPS_VERSION}"
sed -i "/<artifactId>sdk-platform-java-config<\/artifactId>/,/<\/parent>/ s/<version>.*<\/version>/<version>$SHARED_DEPS_VERSION<\/version>/" "${pom}"
# xmlstarlet ed --inplace -N x="http://maven.apache.org/POM/4.0.0" \
# -u "//x:project/x:parent[x:artifactId='sdk-platform-java-config']/x:version" \
# -v "${SHARED_DEPS_VERSION}" \
# "${pom}"
fi
done

# Reset back to the original Java version if changed
export JAVA_HOME="${current_java_home}"
export PATH=${JAVA_HOME}/bin:$PATH
fi
}
# Reset back to the original Java version if changed
export JAVA_HOME="${current_java_home}"
export PATH=${JAVA_HOME}/bin:$PATH
fi

# attempt to install 3 times with exponential backoff (starting with 10 seconds)
retry_with_backoff 3 10 \
Expand Down Expand Up @@ -124,23 +122,19 @@ set +e

case ${JOB_TYPE} in
test)
install_new_shared_deps
echo "SUREFIRE_JVM_OPT: ${SUREFIRE_JVM_OPT}"
mvn test -B -ntp -Dclirr.skip=true -Denforcer.skip=true ${SUREFIRE_JVM_OPT}
RETURN_CODE=$?
;;
lint)
install_new_shared_deps
mvn com.coveo:fmt-maven-plugin:check
RETURN_CODE=$?
;;
javadoc)
install_new_shared_deps
mvn javadoc:javadoc javadoc:test-javadoc
RETURN_CODE=$?
;;
integration)
install_new_shared_deps
mvn -B ${INTEGRATION_TEST_ARGS} \
-ntp \
-Penable-integration-tests \
Expand All @@ -152,19 +146,16 @@ integration)
RETURN_CODE=$?
;;
graalvm)
install_new_shared_deps
# Run Unit and Integration Tests with Native Image
mvn -B ${INTEGRATION_TEST_ARGS} -ntp -Pnative -Penable-integration-tests test
RETURN_CODE=$?
;;
graalvm17)
install_new_shared_deps
# Run Unit and Integration Tests with Native Image
mvn -B ${INTEGRATION_TEST_ARGS} -ntp -Pnative -Penable-integration-tests test
RETURN_CODE=$?
;;
samples)
install_new_shared_deps
SAMPLES_DIR=samples
# only run ITs in snapshot/ on presubmit PRs. run ITs in all 3 samples/ subdirectories otherwise.
if [[ ! -z ${KOKORO_GITHUB_PULL_REQUEST_NUMBER} ]]
Expand Down Expand Up @@ -195,7 +186,6 @@ samples)
fi
;;
presubmit-against-pubsublite-samples)
install_new_shared_deps
## cd to the directory one level above the root of the repo
cd ${scriptDir}/../..
git clone https://github.com/googleapis/java-pubsublite.git
Expand Down Expand Up @@ -231,7 +221,6 @@ presubmit-against-pubsublite-samples)
fi
;;
clirr)
install_new_shared_deps
mvn -B -Denforcer.skip=true clirr:check
RETURN_CODE=$?
;;
Expand Down

0 comments on commit 3dccf7e

Please sign in to comment.