diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 89a3a9175a..a0b0f563cd 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -270,7 +270,7 @@ jobs: mvn clirr:check -B -ntp -Dclirr.skip=false -DcomparisonVersion=$SHOWCASE_CLIENT_VERSION gapic-generator-java-bom: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v3 - uses: actions/setup-java@v3 @@ -285,3 +285,39 @@ jobs: uses: googleapis/java-cloud-bom/tests/validate-bom@v26.13.0 with: bom-path: gapic-generator-java-bom/pom.xml + + downstream-compatibility: + runs-on: ubuntu-22.04 + strategy: + fail-fast: false + matrix: + repo: + - google-cloud-java + - java-bigtable + - java-bigquery + - java-bigquerystorage + - java-datastore + - java-firestore + - java-logging + - java-logging-logback + - java-pubsub + - java-pubsublite + - java-spanner-jdbc + - java-spanner + - java-storage + - java-storage-nio + 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: Test helper scripts + run: ./.kokoro/presubmit/common_test.sh + - name: Perform downstream compatibility testing + run: REPOS_UNDER_TEST="${{ matrix.repo }}" ./.kokoro/presubmit/downstream-compatibility.sh diff --git a/.kokoro/presubmit/common.sh b/.kokoro/presubmit/common.sh new file mode 100644 index 0000000000..c85cb6afef --- /dev/null +++ b/.kokoro/presubmit/common.sh @@ -0,0 +1,89 @@ +#!/bin/bash +# Copyright 2023 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. + +# 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 +function update_pom_dependency { + pushd "$1" || exit 1 + xmllint --shell pom.xml &>/dev/null </dev/null; then + found+=("$pom") + fi + done + POMS=(${found[@]}) + unset found + export POMS +} + +# In the given directory ($1), +# find and update all pom.xmls' dependencies on the given artifact ($2) to the given version ($3) +# ex: update_all_poms_dependency google-cloud-java google-cloud-shared-dependencies 1.2.3 +function update_all_poms_dependency { + pushd "$1" || exit 1 + find_all_poms_with_versioned_dependency "$2" + for pom in $POMS; do + update_pom_dependency "$(dirname "$pom")" "$2" "$3" + done + git diff + popd || exit 1 +} + +# Parse the version of the pom.xml file in the given directory ($1) +# ex: VERSION=$(parse_pom_version java-shared-dependencies) +function parse_pom_version { + # Namespace (xmlns) prevents xmllint from specifying tag names in XPath + result=$(sed -e 's/xmlns=".*"//' "$1/pom.xml" | xmllint --xpath '/project/version/text()' -) + + if [ -z "${result}" ]; then + echo "Version is not found in $1" + exit 1 + fi + echo "$result" +} + +# ex: find_last_release_version java-bigtable +# ex: find_last_release_version java-storage 2.22.x +function find_last_release_version { + branch=${2-"main"} # Default to using main branch + curl -s -o "versions_$1.txt" "https://raw.githubusercontent.com/googleapis/$1/$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 + # 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 + echo "Unable to identify primary artifact for $1" + exit 1 + fi + + parts=($(echo "$primary_artifact" | tr ":" "\n")) + echo "${parts[1]}" +} diff --git a/.kokoro/presubmit/common_test.sh b/.kokoro/presubmit/common_test.sh new file mode 100755 index 0000000000..6e7b8e130d --- /dev/null +++ b/.kokoro/presubmit/common_test.sh @@ -0,0 +1,80 @@ +#!/bin/bash +# Copyright 2023 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. + +scriptDir=$(realpath "$(dirname "${BASH_SOURCE[0]}")") +cd "${scriptDir}/../.." # cd to the root of this repo +source "$scriptDir/common.sh" +mkdir -p target +cd target + +function test_find_all_poms_with_versioned_dependency { + mkdir -p test_find_all_poms_with_dependency + pushd test_find_all_poms_with_dependency + cp ../../showcase/gapic-showcase/pom.xml pom.xml + + find_all_poms_with_versioned_dependency 'truth' + if [ "${#POMS[@]}" != 1 ]; then + echo 'find_all_poms_with_versioned_dependency did not find the expected pom' + exit 1 + elif [ "${POMS[0]}" != './pom.xml' ]; then + echo "find_all_poms_with_versioned_dependency found ${POMS[0]} instead of expected ./pom.xml" + exit 1 + fi + + find_all_poms_with_versioned_dependency 'gax-grpc' # Versioned by shared-deps + if [ "${#POMS[@]}" != 0 ]; then + echo 'find_all_poms_with_versioned_dependency found unexpected pom' + exit 1 + fi + + popd +} + +function test_update_pom_dependency { + mkdir -p test_update_pom_dependency + pushd test_update_pom_dependency + cp ../../showcase/gapic-showcase/pom.xml pom.xml + + update_pom_dependency . truth "99.88.77" + + xmllint --shell pom.xml &>/dev/null </dev/null; then + echo "update_pom_dependency failed to change version to expected value." + exit 1 + fi + rm found-version.txt + popd +} + +function test_parse_pom_version { + mkdir -p test_parse_pom_version + pushd test_parse_pom_version + cp ../../showcase/gapic-showcase/pom.xml pom.xml + + VERSION=$(parse_pom_version .) + if [ "$VERSION" != "0.0.1-SNAPSHOT" ]; then + echo "parse_pom_version failed to read expected version of gapic-showcase." + fi + popd +} + +test_find_all_poms_with_versioned_dependency +test_update_pom_dependency +test_parse_pom_version diff --git a/.kokoro/presubmit/downstream-build.sh b/.kokoro/presubmit/downstream-build.sh index 3c024c8592..b69c578775 100755 --- a/.kokoro/presubmit/downstream-build.sh +++ b/.kokoro/presubmit/downstream-build.sh @@ -15,15 +15,20 @@ set -eo pipefail -## Get the directory of the build script -scriptDir=$(realpath "$(dirname "${BASH_SOURCE[0]}")") -## cd to the parent directory, i.e. the root of the git repo -cd "${scriptDir}/../.." - if [ -z "${MODULES_UNDER_TEST}" ]; then echo "MODULES_UNDER_TEST must be set to run downstream-build.sh" exit 1 fi +# Use default value for REPOS_UNDER_TEST if unset. If set to empty string, maintain empty string. +# +# java-storage is currently the only downstream repo that doesn't require cloud resources for its +# GraalVM integration tests. +REPOS_UNDER_TEST=${REPOS_UNDER_TEST-"java-storage"} + +## Get the directory of the build script +scriptDir=$(realpath "$(dirname "${BASH_SOURCE[0]}")") +cd "${scriptDir}/../.." # git repo root +source "$scriptDir/common.sh" # Use GCP Maven Mirror mkdir -p "${HOME}/.m2" @@ -34,38 +39,12 @@ cp settings.xml "${HOME}/.m2" mvn -B -ntp install --projects '!gapic-generator-java' \ -Dcheckstyle.skip -Dfmt.skip -DskipTests -# Read the shared dependencies version -# Namespace (xmlns) prevents xmllint from specifying tag names in XPath -SHARED_DEPS_VERSION=$(sed -e 's/xmlns=".*"//' java-shared-dependencies/pom.xml | xmllint --xpath '/project/version/text()' -) - -if [ -z "${SHARED_DEPS_VERSION}" ]; then - echo "Shared dependencies version is not found in pom.xml" - exit 1 -fi - -### Round 2 -# Update the shared-dependencies version in google-cloud-jar-parent -git clone "https://github.com/googleapis/google-cloud-java.git" --depth=1 -pushd google-cloud-java/google-cloud-jar-parent -xmllint --shell pom.xml <