Skip to content

Commit 684019f

Browse files
committed
cleanup downstream tests
1 parent b849b48 commit 684019f

File tree

6 files changed

+104
-39
lines changed

6 files changed

+104
-39
lines changed

.github/workflows/sdk-platform-java-downstream.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ jobs:
4747
sudo apt-get update
4848
sudo apt-get -y install libxml2-utils
4949
- name: Test helper scripts
50-
run: ./sdk-platform-java/.kokoro/presubmit/common_test.sh
50+
run: .kokoro/common_test.sh
5151
- name: Perform downstream compatibility testing
52-
run: REPOS_UNDER_TEST="${{ matrix.repo }}" ./sdk-platform-java/.kokoro/presubmit/downstream-compatibility.sh
52+
run: REPOS_UNDER_TEST="${{ matrix.repo }}" ./kokoro/downstream-compatibility.sh
5353
downstream-compatibility-spring-generator:
5454
needs: filter
5555
if: ${{ needs.filter.outputs.library == 'true' }}
@@ -68,4 +68,4 @@ jobs:
6868
sudo apt-get update
6969
sudo apt-get -y install libxml2-utils
7070
- name: Perform downstream compatibility testing
71-
run: ./sdk-platform-java/.kokoro/presubmit/downstream-compatibility-spring.sh
71+
run: .kokoro/downstream-compatibility-spring.sh

.kokoro/common.sh

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,3 +482,100 @@ function install_modules() {
482482
-T 1C
483483
fi
484484
}
485+
486+
487+
# In the given directory ($1),
488+
# update the pom.xml's dependency on the given artifact ($2) to the given version ($3)
489+
# ex: update_dependency google-cloud-java/google-cloud-jar-parent google-cloud-shared-dependencies 1.2.3
490+
function update_pom_dependency {
491+
pushd "$1" || exit 1
492+
xmllint --shell pom.xml &>/dev/null <<EOF
493+
setns x=http://maven.apache.org/POM/4.0.0
494+
cd .//x:artifactId[text()="$2"]
495+
cd ../x:version
496+
set $3
497+
save pom.xml
498+
EOF
499+
popd || exit 1
500+
}
501+
502+
# Find all pom.xml files that declare a specific version for the given artifact ($1)
503+
function find_all_poms_with_versioned_dependency {
504+
poms=($(find . -name pom.xml))
505+
for pom in "${poms[@]}"; do
506+
if xmllint --xpath "//*[local-name()='artifactId' and text()='$1']/following-sibling::*[local-name()='version']" "$pom" &>/dev/null; then
507+
found+=("$pom")
508+
fi
509+
done
510+
POMS=(${found[@]})
511+
unset found
512+
export POMS
513+
}
514+
515+
# In the given directory ($1),
516+
# find and update all pom.xmls' dependencies on the given artifact ($2) to the given version ($3)
517+
# ex: update_all_poms_dependency google-cloud-java google-cloud-shared-dependencies 1.2.3
518+
function update_all_poms_dependency {
519+
pushd "$1" || exit 1
520+
find_all_poms_with_versioned_dependency "$2"
521+
for pom in $POMS; do
522+
update_pom_dependency "$(dirname "$pom")" "$2" "$3"
523+
done
524+
git diff
525+
popd || exit 1
526+
}
527+
528+
# Parse the version of the pom.xml file in the given directory ($1)
529+
# ex: VERSION=$(parse_pom_version java-shared-dependencies)
530+
function parse_pom_version {
531+
# Namespace (xmlns) prevents xmllint from specifying tag names in XPath
532+
result=$(sed -e 's/xmlns=".*"//' "$1/pom.xml" | xmllint --xpath '/project/version/text()' -)
533+
534+
if [ -z "${result}" ]; then
535+
echo "Version is not found in $1"
536+
exit 1
537+
fi
538+
echo "$result"
539+
}
540+
541+
# ex: find_last_release_version java-bigtable
542+
# ex: find_last_release_version java-storage 2.22.x
543+
function find_last_release_version {
544+
repo=$1
545+
branch=${2-"main"} # Default to using main branch
546+
org=${3-"googleapis"}
547+
curl -s -o "versions_${repo}.txt" "https://raw.githubusercontent.com/${org}/${repo}/${branch}/versions.txt"
548+
549+
# First check to see if there's an entry for the overall repo. Used for google-cloud-java.
550+
primary_artifact=$(grep -E "^${repo}" "versions_${repo}.txt" | head -n 1)
551+
if [ -z "${primary_artifact}" ]; then
552+
# Otherwise, use the first google-cloud-* artifact's version.
553+
primary_artifact=$(grep -E "^google-cloud-" "versions_$1.txt" | head -n 1)
554+
fi
555+
if [ -z "${primary_artifact}" ]; then
556+
echo "Unable to identify primary artifact for $1"
557+
exit 1
558+
fi
559+
560+
parts=($(echo "$primary_artifact" | tr ":" "\n"))
561+
echo "${parts[1]}"
562+
}
563+
564+
# copies settings.xml from the root of sdk-platform-java into Maven's home
565+
# folder
566+
function setup_maven_mirror {
567+
echo "Setup maven mirror"
568+
mkdir -p "${HOME}/.m2"
569+
cp "${commonScriptDir}/../../settings.xml" "${HOME}/.m2"
570+
}
571+
572+
function install_repo_modules {
573+
target_projects="$1"
574+
projects_arg=""
575+
if [ -n "${target_projects}" ]; then
576+
projects_arg="--projects ${target_projects}"
577+
fi
578+
echo "Installing this repo's modules to local maven."
579+
mvn -q -B -ntp install ${projects_arg} \
580+
-Dcheckstyle.skip -Dfmt.skip -DskipTests -T 1C
581+
}

sdk-platform-java/.kokoro/presubmit/common_test.sh renamed to .kokoro/common_test.sh

File renamed without changes.

sdk-platform-java/.kokoro/presubmit/downstream-compatibility-spring.sh renamed to .kokoro/downstream-compatibility-spring.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ set -eox pipefail
2020

2121
# Get the directory of the build script
2222
scriptDir=$(realpath "$(dirname "${BASH_SOURCE[0]}")")
23-
cd "${scriptDir}/../.." # cd to the root of this repo
23+
cd "${scriptDir}/.." # cd to the root of this repo
2424
source "$scriptDir/common.sh"
2525

26-
install_repo_modules
26+
install_modules "sdk-platform-java"
27+
cd sdk-platform-java
2728
GAPIC_GENERATOR_VERSION=$(parse_pom_version "gapic-generator-java-bom")
2829
echo "Install complete. gapic-generator-java-bom = $GAPIC_GENERATOR_VERSION"
2930

sdk-platform-java/.kokoro/presubmit/downstream-compatibility.sh renamed to .kokoro/downstream-compatibility.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ fi
2424

2525
# Get the directory of the build script
2626
scriptDir=$(realpath "$(dirname "${BASH_SOURCE[0]}")")
27-
cd "${scriptDir}/../../.." # cd to the root of this repo
27+
cd "${scriptDir}/.." # cd to the root of this repo
2828
source "$scriptDir/common.sh"
29-
source ".kokoro/common.sh"
3029

3130
setup_maven_mirror
3231

sdk-platform-java/settings.xml

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)