From bd5ef745c6679a5bf1013bc96776926946463902 Mon Sep 17 00:00:00 2001 From: Diego Marquez Date: Thu, 29 Aug 2024 12:10:21 -0400 Subject: [PATCH] test: add downstream check for spring-cloud-gcp (#3092) Fixes https://togithub.com/googleapis/sdk-platform-java/issues/2534 The check takes 2 minutes --- .github/workflows/downstream.yaml | 17 ++++++ .kokoro/presubmit/common.sh | 31 ++++++++-- .../downstream-compatibility-spring.sh | 56 +++++++++++++++++++ .kokoro/presubmit/downstream-compatibility.sh | 9 +-- 4 files changed, 103 insertions(+), 10 deletions(-) create mode 100755 .kokoro/presubmit/downstream-compatibility-spring.sh diff --git a/.github/workflows/downstream.yaml b/.github/workflows/downstream.yaml index a5280df7d8..c6b3f64856 100644 --- a/.github/workflows/downstream.yaml +++ b/.github/workflows/downstream.yaml @@ -47,3 +47,20 @@ jobs: run: ./.kokoro/presubmit/common_test.sh - name: Perform downstream compatibility testing run: REPOS_UNDER_TEST="${{ matrix.repo }}" ./.kokoro/presubmit/downstream-compatibility.sh + downstream-compatibility-spring-generator: + runs-on: ubuntu-22.04 + strategy: + fail-fast: false + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-java@v3 + with: + java-version: 17 + distribution: temurin + - run: mvn -version + - name: Install xmllint + run: | + sudo apt-get update + sudo apt-get -y install libxml2-utils + - name: Perform downstream compatibility testing + run: ./.kokoro/presubmit/downstream-compatibility-spring.sh diff --git a/.kokoro/presubmit/common.sh b/.kokoro/presubmit/common.sh index c85cb6afef..c9fd49ed29 100644 --- a/.kokoro/presubmit/common.sh +++ b/.kokoro/presubmit/common.sh @@ -13,6 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +commonScriptDir=$(realpath "$(dirname "${BASH_SOURCE[0]}")") + # In the given directory ($1), # update the pom.xml's dependency on the given artifact ($2) to the given version ($3) # ex: update_dependency google-cloud-java/google-cloud-jar-parent google-cloud-shared-dependencies 1.2.3 @@ -70,16 +72,18 @@ function parse_pom_version { # ex: find_last_release_version java-bigtable # ex: find_last_release_version java-storage 2.22.x function find_last_release_version { + repo=$1 branch=${2-"main"} # Default to using main branch - curl -s -o "versions_$1.txt" "https://raw.githubusercontent.com/googleapis/$1/$branch/versions.txt" + org=${3-"googleapis"} + curl -s -o "versions_${repo}.txt" "https://raw.githubusercontent.com/${org}/${repo}/${branch}/versions.txt" # First check to see if there's an entry for the overall repo. Used for google-cloud-java. - primary_artifact=$(grep -E "^$1" "versions_$1.txt" | head -n 1) - if [ -z "$primary_artifact" ]; then + primary_artifact=$(grep -E "^${repo}" "versions_${repo}.txt" | head -n 1) + if [ -z "${primary_artifact}" ]; then # Otherwise, use the first google-cloud-* artifact's version. primary_artifact=$(grep -E "^google-cloud-" "versions_$1.txt" | head -n 1) fi - if [ -z "$primary_artifact" ]; then + if [ -z "${primary_artifact}" ]; then echo "Unable to identify primary artifact for $1" exit 1 fi @@ -87,3 +91,22 @@ function find_last_release_version { parts=($(echo "$primary_artifact" | tr ":" "\n")) echo "${parts[1]}" } + +# copies settings.xml from the root of sdk-platform-java into Maven's home +# folder +function setup_maven_mirror { + echo "Setup maven mirror" + mkdir -p "${HOME}/.m2" + cp "${commonScriptDir}/../../settings.xml" "${HOME}/.m2" +} + +function install_repo_modules { + target_projects="$1" + projects_arg="" + if [ -n "${target_projects}" ]; then + projects_arg="--projects ${target_projects}" + fi + echo "Installing this repo's modules to local maven." + mvn -q -B -ntp install ${projects_arg} \ + -Dcheckstyle.skip -Dfmt.skip -DskipTests -T 1C +} diff --git a/.kokoro/presubmit/downstream-compatibility-spring.sh b/.kokoro/presubmit/downstream-compatibility-spring.sh new file mode 100755 index 0000000000..2c0ae2b62c --- /dev/null +++ b/.kokoro/presubmit/downstream-compatibility-spring.sh @@ -0,0 +1,56 @@ +#!/bin/bash +# Copyright 2024 Google LLC +# +# 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 is only meant to test spring-cloud-gpc, specifically on its +# autoconfig generation workflow + +set -eox pipefail + +# Get the directory of the build script +scriptDir=$(realpath "$(dirname "${BASH_SOURCE[0]}")") +cd "${scriptDir}/../.." # cd to the root of this repo +source "$scriptDir/common.sh" + +install_repo_modules +GAPIC_GENERATOR_VERSION=$(parse_pom_version "gapic-generator-java-bom") +echo "Install complete. gapic-generator-java-bom = $GAPIC_GENERATOR_VERSION" + +pushd gapic-generator-java/target +# Download and configure spring-cloud-gcp for testing +last_release=$(find_last_release_version "spring-cloud-gcp" "main" "GoogleCloudPlatform") +git clone "https://github.com/GoogleCloudPlatform/spring-cloud-gcp.git" --depth=1 --branch "v$last_release" +update_all_poms_dependency "spring-cloud-gcp" "gapic-generator-java-bom" "${GAPIC_GENERATOR_VERSION}" + +# Install spring-cloud-gcp modules +pushd spring-cloud-gcp/spring-cloud-generator +../mvnw \ + -U \ + --batch-mode \ + --no-transfer-progress \ + --show-version \ + --threads 1.5C \ + --define maven.test.skip=true \ + --define maven.javadoc.skip=true \ + install + + +# Generate showcase autoconfig +./scripts/generate-showcase.sh +pushd showcase/showcase-spring-starter +mvn verify +popd # showcase/showcase-spring-starter + +popd # spring-cloud-gcp/spring-cloud-generator +popd # gapic-generator-java/target diff --git a/.kokoro/presubmit/downstream-compatibility.sh b/.kokoro/presubmit/downstream-compatibility.sh index 3098983aef..2e0b8c7c12 100755 --- a/.kokoro/presubmit/downstream-compatibility.sh +++ b/.kokoro/presubmit/downstream-compatibility.sh @@ -21,18 +21,15 @@ if [ -z "${REPOS_UNDER_TEST}" ]; then exit 1 fi + # Get the directory of the build script scriptDir=$(realpath "$(dirname "${BASH_SOURCE[0]}")") cd "${scriptDir}/../.." # cd to the root of this repo source "$scriptDir/common.sh" -echo "Setup maven mirror" -mkdir -p "${HOME}/.m2" -cp settings.xml "${HOME}/.m2" +setup_maven_mirror -echo "Installing this repo's modules to local maven." -mvn -q -B -ntp install --projects '!gapic-generator-java' \ - -Dcheckstyle.skip -Dfmt.skip -DskipTests -T 1C +install_repo_modules '!gapic-generator-java' SHARED_DEPS_VERSION=$(parse_pom_version java-shared-dependencies) echo "Install complete. java-shared-dependencies = $SHARED_DEPS_VERSION"