Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: generate showcase without post-processing #1935

Merged
merged 110 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
110 commits
Select commit Hold shift + click to select a range
53abd0e
feat: add
JoeWang1127 Aug 10, 2023
434cbfc
generate gapic and proto folder
JoeWang1127 Aug 11, 2023
5825bcc
refactor utilities
JoeWang1127 Aug 11, 2023
c39cbea
add an action to verify
JoeWang1127 Aug 11, 2023
10a1c6d
checkout googleapis-gen
JoeWang1127 Aug 11, 2023
cca6770
setup repo name
JoeWang1127 Aug 11, 2023
89bbedc
add commit hash of googleapis-gen
JoeWang1127 Aug 11, 2023
3e85e33
change secret
JoeWang1127 Aug 11, 2023
fdf9260
change token
JoeWang1127 Aug 11, 2023
f3b60a6
change to git clone
JoeWang1127 Aug 11, 2023
1b4746d
change user name
JoeWang1127 Aug 11, 2023
2856709
add input list
JoeWang1127 Aug 11, 2023
81cbdc2
include resources folder in main
JoeWang1127 Aug 13, 2023
d733c5a
remove grpc version in `*ServiceGrpc.java`
JoeWang1127 Aug 13, 2023
92660ff
change destination path
JoeWang1127 Aug 14, 2023
07f3ea6
compare generation result with googleapis-gen
JoeWang1127 Aug 14, 2023
49542f7
fix type in diff command
JoeWang1127 Aug 14, 2023
d7b3752
checkout repo using checkout action
JoeWang1127 Aug 14, 2023
0c8aa78
checkout repos as nested repo
JoeWang1127 Aug 14, 2023
3d612f8
sparse checkout googleapis
JoeWang1127 Aug 15, 2023
280a571
Revert "sparse checkout googleapis"
JoeWang1127 Aug 15, 2023
d375848
change library
JoeWang1127 Aug 15, 2023
734e1eb
change step name
JoeWang1127 Aug 15, 2023
9a5a7cd
add a readme
JoeWang1127 Aug 16, 2023
35ad197
make grpc version optional
JoeWang1127 Aug 16, 2023
8477b74
make protobuf version optional
JoeWang1127 Aug 16, 2023
5eb0223
checkout master branch, rather than a commit hash
JoeWang1127 Aug 17, 2023
b12f99e
allow snapshot version of generator
JoeWang1127 Aug 18, 2023
e893df3
download snapshot of generator parent pom
JoeWang1127 Aug 18, 2023
a7d8a55
update README
JoeWang1127 Aug 18, 2023
f02a037
chore: add test script for showcase
diegomarquezp Aug 18, 2023
21a6cd2
chore: fix additional protos logic
diegomarquezp Aug 18, 2023
2a9f8a8
download generator and grpc using mvn
JoeWang1127 Aug 18, 2023
51beff7
change error message
JoeWang1127 Aug 18, 2023
f7e4b72
add maven central mirror
JoeWang1127 Aug 18, 2023
32463da
add comments in utilities
JoeWang1127 Aug 19, 2023
b58a802
add comments
JoeWang1127 Aug 19, 2023
d7dcdca
add an integration test
JoeWang1127 Aug 20, 2023
e900a42
chore: modify showcase source proto folder structure
diegomarquezp Aug 20, 2023
4e1707d
Merge remote-tracking branch 'origin/feat/generate-aiplatform-without…
diegomarquezp Aug 20, 2023
4e525a6
fail fast if no file is found
JoeWang1127 Aug 21, 2023
fb3fe22
chore: add showcase integration test
diegomarquezp Aug 21, 2023
3738945
chore: add action to test on showase
diegomarquezp Aug 21, 2023
eef963f
Merge remote-tracking branch 'origin/main' into feat/generate-showcas…
diegomarquezp Aug 21, 2023
3b6dfeb
chore: add diff check for showcase IT
diegomarquezp Aug 21, 2023
64ee89e
do not delete google/
JoeWang1127 Aug 21, 2023
56e418a
Merge branch 'main' into feat/generate-aiplatform-without-postprocessing
JoeWang1127 Aug 21, 2023
5fd6aac
chore: change file mod in protos
diegomarquezp Aug 21, 2023
5a94a72
chore: fix diff comparison
diegomarquezp Aug 21, 2023
06d0351
Merge remote-tracking branch 'origin/feat/generate-aiplatform-without…
diegomarquezp Aug 21, 2023
ad59c57
chore: remove unwanted binary
diegomarquezp Aug 21, 2023
a056ae1
get protobuf version from WORKSPACE
JoeWang1127 Aug 21, 2023
7ef8278
add instructions on download `google/` from googleapis
JoeWang1127 Aug 21, 2023
4f0ef4a
add comments
JoeWang1127 Aug 21, 2023
7adf70d
chore: final adjustments for showcase testing
diegomarquezp Aug 22, 2023
0d305d2
chore: allow workflow dispatch on workflow
diegomarquezp Aug 22, 2023
3d62a2b
chore: correct yaml definition
diegomarquezp Aug 22, 2023
5b59674
chore: correct yaml definition ii
diegomarquezp Aug 22, 2023
3cf0df2
Merge remote-tracking branch 'origin/feat/generate-aiplatform-without…
diegomarquezp Aug 22, 2023
f8816a4
chore: fix util import
diegomarquezp Aug 22, 2023
5805e84
update description of `destination_path`
JoeWang1127 Aug 22, 2023
6aa42fb
chore: correct version parsing
diegomarquezp Aug 22, 2023
20554ee
chore: correct showcase version
diegomarquezp Aug 22, 2023
aa12966
chore: try java 11
diegomarquezp Aug 22, 2023
880c27b
update comments
JoeWang1127 Aug 22, 2023
1e6269b
chore: infer grpc_version from parent pom
diegomarquezp Aug 22, 2023
a5fe171
download dependencies using `curl`
JoeWang1127 Aug 22, 2023
f6c5784
increase download time
JoeWang1127 Aug 22, 2023
5d16f16
remove comment
JoeWang1127 Aug 22, 2023
3275765
Merge branch 'feat/generate-aiplatform-without-postprocessing' into f…
diegomarquezp Aug 23, 2023
6ce6170
Merge remote-tracking branch 'origin/main' into feat/generate-showcas…
diegomarquezp Aug 28, 2023
ea813ee
Merge remote-tracking branch 'origin/main' into feat/generate-showcas…
diegomarquezp Aug 31, 2023
f9839dc
generate components for showcase
diegomarquezp Aug 31, 2023
c4216f5
use script in maven profile
diegomarquezp Sep 1, 2023
836a185
correct compilation components
diegomarquezp Sep 1, 2023
ede73ff
explicit output folder path check
diegomarquezp Sep 1, 2023
4b50140
use poms to resolve versions
diegomarquezp Sep 1, 2023
c032b04
migrate showcase scripts to showcase folder
diegomarquezp Sep 1, 2023
3fd56df
remove bazel-based update script
diegomarquezp Sep 1, 2023
0350a7c
finalize migration for generation
diegomarquezp Sep 1, 2023
4793981
fix generation
diegomarquezp Sep 1, 2023
e7986c0
change verification profile for gapic-showcase
diegomarquezp Sep 1, 2023
10aeec1
remove unused functions in verify.sh
diegomarquezp Sep 1, 2023
1286a93
remove unused CI component
diegomarquezp Sep 1, 2023
cd97149
remove showcase from readme
diegomarquezp Sep 5, 2023
005567f
remove unused logic
diegomarquezp Sep 5, 2023
d5725bc
script comments and cleanup
diegomarquezp Sep 5, 2023
a979c65
improve comment in generate_component
diegomarquezp Sep 5, 2023
d59b87f
remove unused bazel files
diegomarquezp Sep 5, 2023
962bb7a
Merge branch 'main' into feat/generate-showcase-without-postprocessing
diegomarquezp Sep 5, 2023
e2a8c0f
remove .gitignore in favor of cleanup
diegomarquezp Sep 6, 2023
44f561d
bash format
diegomarquezp Sep 6, 2023
c4d07e1
transfer profiles to showcase parent
diegomarquezp Sep 6, 2023
f384ca9
fix parent pom script call
diegomarquezp Sep 6, 2023
9572011
fix wildcard for source replacement
diegomarquezp Sep 6, 2023
99ce5bb
fix proto golden test, add util script
diegomarquezp Sep 6, 2023
f8f9c0c
install xmllint
diegomarquezp Sep 6, 2023
2a0d8d4
Merge remote-tracking branch 'origin/main' into feat/generate-showcas…
diegomarquezp Sep 6, 2023
be0557c
sudo for installing xmlint
diegomarquezp Sep 6, 2023
4865532
correct xmllint package
diegomarquezp Sep 6, 2023
92a391c
Merge remote-tracking branch 'origin/main' into feat/generate-showcas…
diegomarquezp Sep 8, 2023
ce71fb7
Update library_generation/utilities.sh
diegomarquezp Sep 11, 2023
4c571a4
Merge remote-tracking branch 'origin/feat/generate-showcase-without-p…
diegomarquezp Sep 11, 2023
af35671
restore gh action
diegomarquezp Sep 11, 2023
ccd7aa8
move convenience functions to utilities file
diegomarquezp Sep 11, 2023
617eddd
remove duplicate file\
diegomarquezp Sep 11, 2023
9b44c77
fix proto path
diegomarquezp Sep 11, 2023
d9ee812
use `sed` and `cut` to extract showcase version
diegomarquezp Sep 11, 2023
ead36c6
add unit tests for new functions
diegomarquezp Sep 12, 2023
09f94ee
add test for versions
diegomarquezp Sep 12, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions library_generation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,3 @@ library_generation/generate_library.sh \
--include_samples true
```

## An example to generate showcase client
JoeWang1127 marked this conversation as resolved.
Show resolved Hide resolved
```
library_generation/generate_library.sh \
-p schema/google/showcase/v1beta1 \ # google/ should be in library_generation/.
-d output \
--gapic_generator_version 2.24.0 \
--protobuf_version 23.2 \
--grpc_version 1.55.1 \
--transport grpc+rest \
--rest_numeric_enums false \
--include_samples false
```
2 changes: 2 additions & 0 deletions library_generation/generate_library.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env bash

set -eo pipefail
set -x

# parse input parameters
while [[ $# -gt 0 ]]; do
Expand Down Expand Up @@ -157,3 +158,4 @@ done
#####################################################
cd "${destination_path}"
rm -rf java_gapic_srcjar java_gapic_srcjar_raw.srcjar.zip java_grpc.jar java_proto.jar temp-codegen.srcjar
set +x
56 changes: 21 additions & 35 deletions library_generation/test/generate_library_integration_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,34 +42,13 @@ esac
shift # past argument or value
done

get_version_from_WORKSPACE() {
local version_key_word=$1
local workspace=$2
local delimiter=$3
local version
version="$(grep -m 1 "${version_key_word}" "${workspace}" | sed 's/\"\(.*\)\".*/\1/' | cut -d "${delimiter}" -f2 | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')"
echo "${version}"
}

sparse_clone() {
local repo_url=$1
local paths=$2
local clone_dir
clone_dir=$(basename "${repo_url%.*}")
rm -rf "${clone_dir}"
git clone -n --depth=1 --filter=tree:0 "${repo_url}"
cd "${clone_dir}"
git sparse-checkout set --no-cone ${paths}
git checkout
cd ..
}

script_dir=$(dirname "$(readlink -f "$0")")
source "${script_dir}/../utilities.sh"
library_generation_dir="${script_dir}"/..
cd "${library_generation_dir}"
# checkout the master branch of googleapis/google (proto files) and WORKSPACE
echo "Checking out googlapis repository..."
sparse_clone https://github.com/googleapis/googleapis.git "${proto_path} WORKSPACE google/api google/rpc google/cloud/common_resources.proto"
sparse_clone https://github.com/googleapis/googleapis.git "${proto_path} WORKSPACE google/api google/rpc google/cloud/common_resources.proto google/iam/v1 google/type google/longrunning"
cd googleapis
# parse version of gapic-generator-java, protobuf and grpc from WORKSPACE
gapic_generator_version=$(get_version_from_WORKSPACE "_gapic_generator_java_version" WORKSPACE "=")
Expand All @@ -79,18 +58,25 @@ echo "The version of protobuf is ${protobuf_version}"
grpc_version=$(get_version_from_WORKSPACE "_grpc_version" WORKSPACE "=")
echo "The version of protoc-gen-grpc-java plugin is ${gapic_generator_version}."
# parse GAPIC options from proto_path/BUILD.bazel
transport="grpc"
if grep -A 15 "java_gapic_library(" "${proto_path}/BUILD.bazel" | grep -q "grpc+rest"; then
transport="grpc+rest"
fi
rest_numeric_enums="true"
if grep -A 15 "java_gapic_library(" "${proto_path}/BUILD.bazel" | grep -q "rest_numeric_enums = False"; then
rest_numeric_enums="false"
fi
include_samples="false"
if grep -A 15 "java_gapic_assembly_gradle_pkg(" "${proto_path}/BUILD.bazel" | grep -q "include_samples = True"; then
include_samples="true"
fi
proto_build_file_path="${proto_path}/BUILD.bazel"
transport=$(get_config_from_BUILD \
"${proto_build_file_path}" \
"java_gapic_library(" \
"grpc+rest" \
"grpc"
)
rest_numeric_enums=$(get_config_from_BUILD \
"${proto_build_file_path}" \
"java_gapic_library(" \
"rest_numeric_enums = False" \
"true"
)
include_samples=$(get_config_from_BUILD \
"${proto_build_file_path}" \
"java_gapic_assembly_gradle_pkg(" \
"include_samples = True" \
"false"
)
echo "GAPIC options are transport=${transport}, rest_numeric_enums=${rest_numeric_enums}, include_samples=${include_samples}."
os_architecture="linux-x86_64"
if [[ "$os_type" == *"macos"* ]]; then
Expand Down
45 changes: 45 additions & 0 deletions library_generation/test/generate_library_unit_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,48 @@ download_grpc_plugin_failed_with_invalid_arch_test() {
__assertEquals 1 $((res))
}

get_config_from_valid_BUILD_test() {
build_file="${script_dir}/resources/misc/TESTBUILD.bazel"
rule="java_gapic_library("
# the pattern we expect to find in the BUILD file
pattern_should_match="name"
# the pattern that we should not find in the BUILD file
pattern_should_not_match="should-not-match"
# default value if the pattern was not found
if_matched_return="got-a-match"
if_not_matched_return="no-match"
pattern_matched_result=$(get_config_from_BUILD \
"${build_file}" \
"${rule}" \
"${pattern_should_match}" \
"${if_not_matched_return}" \
"${if_matched_return}"
)
__assertEquals "${pattern_matched_result}" "${if_matched_return}"
pattern_not_matched_result=$(get_config_from_BUILD \
"${build_file}" \
"${rule}" \
"${pattern_should_not_match}" \
"${if_not_matched_return}" \
"${if_matched_return}"
)
__assertEquals "${pattern_not_matched_result}" "${if_not_matched_return}"
}

get_version_from_valid_WORKSPACE_test() {
workspace_file="${script_dir}/resources/misc/TESTWORKSPACE"
obtained_ggj_version=$(get_version_from_WORKSPACE "_gapic_generator_java_version" "${workspace_file}")
__assertEquals '2.25.1-SNAPSHOT' "${obtained_ggj_version}"
}

get_version_from_valid_versions_txt_test() {
versions_file="${script_dir}/resources/misc/testversions.txt"
obtained_ggj_version=$(get_version_from_versions_txt "${versions_file}" "gapic-generator-java")
__assertEquals '2.25.1-SNAPSHOT' "${obtained_ggj_version}"
obtained_gax_version=$(get_version_from_versions_txt "${versions_file}" "gax")
__assertEquals '2.33.1-SNAPSHOT' "${obtained_gax_version}"
}

# Execute tests.
# One line per test.
test_list=(
Expand All @@ -244,6 +286,9 @@ test_list=(
download_grpc_plugin_succeed_with_valid_version_macos_test
download_grpc_plugin_failed_with_invalid_version_linux_test
download_grpc_plugin_failed_with_invalid_arch_test
get_config_from_valid_BUILD_test
get_version_from_valid_WORKSPACE_test
get_version_from_valid_versions_txt_test
)

for ut in "${test_list[@]}"; do
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Note: The commented section is the framework for gapic-showcase-extended
# See gapic-showcase-extended folder for more info
# Test BUILD file, copied from sdk-platform-java/showcase/BUILD.bazel

load(
"//rules_java_gapic:java_gapic.bzl",
Expand Down
133 changes: 133 additions & 0 deletions library_generation/test/resources/misc/TESTWORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
# test workspace file obtained from sdk-platform-java

workspace(name = "gapic_generator_java")

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

# gax-java and its transitive dependencies must be imported before
# gapic-generator-java dependencies to match the order in googleapis repository,
# which in its turn, prioritizes actual generated clients runtime dependencies
# over the generator dependencies.
local_repository(
name = "com_google_api_gax_java",
path = "gax-java",
)

load("@com_google_api_gax_java//:repository_rules.bzl", "com_google_api_gax_java_properties")

com_google_api_gax_java_properties(
name = "com_google_api_gax_java_properties",
file = "@com_google_api_gax_java//:dependencies.properties",
)

load("@com_google_api_gax_java//:repositories.bzl", "com_google_api_gax_java_repositories")

com_google_api_gax_java_repositories()

_googleapis_commit = "7438480b2a1bc6371d748e974f7a3647f90c4e8d"

http_archive(
name = "com_google_googleapis",
strip_prefix = "googleapis-%s" % _googleapis_commit,
urls = [
"https://github.com/googleapis/googleapis/archive/%s.zip" % _googleapis_commit,
],
)

# protobuf
RULES_JVM_EXTERNAL_TAG = "4.5"

RULES_JVM_EXTERNAL_SHA = "b17d7388feb9bfa7f2fa09031b32707df529f26c91ab9e5d909eb1676badd9a6"

http_archive(
name = "rules_jvm_external",
sha256 = RULES_JVM_EXTERNAL_SHA,
strip_prefix = "rules_jvm_external-%s" % RULES_JVM_EXTERNAL_TAG,
url = "https://github.com/bazelbuild/rules_jvm_external/archive/%s.zip" % RULES_JVM_EXTERNAL_TAG,
)

load("@rules_jvm_external//:repositories.bzl", "rules_jvm_external_deps")

rules_jvm_external_deps()

load("@rules_jvm_external//:setup.bzl", "rules_jvm_external_setup")

rules_jvm_external_setup()

load("@com_google_protobuf//:protobuf_deps.bzl", "PROTOBUF_MAVEN_ARTIFACTS", "protobuf_deps")
load("@rules_jvm_external//:defs.bzl", "maven_install")

maven_install(
artifacts = PROTOBUF_MAVEN_ARTIFACTS,
repositories = ["https://repo.maven.apache.org/maven2/"],
)

_gapic_generator_java_version = "2.25.1-SNAPSHOT" # {x-version-update:gapic-generator-java:current}

maven_install(
artifacts = [
"com.google.api:gapic-generator-java:" + _gapic_generator_java_version,
],
fail_on_missing_checksum = False,
repositories = [
"m2Local",
"https://repo.maven.apache.org/maven2/",
],
)

protobuf_deps()

# Bazel rules.
_rules_gapic_version = "0.5.5"

http_archive(
name = "rules_gapic",
strip_prefix = "rules_gapic-%s" % _rules_gapic_version,
urls = ["https://github.com/googleapis/rules_gapic/archive/v%s.tar.gz" % _rules_gapic_version],
)

# Java dependencies.
load("@com_google_googleapis//:repository_rules.bzl", "switched_rules_by_language")

switched_rules_by_language(
name = "com_google_googleapis_imports",
gapic = True,
grpc = True,
java = True,
)

load("@io_grpc_grpc_java//:repositories.bzl", "grpc_java_repositories")

grpc_java_repositories()

_disco_to_proto3_converter_commit = "ce8d8732120cdfb5bf4847c3238b5be8acde87e3"

http_archive(
name = "com_google_disco_to_proto3_converter",
strip_prefix = "disco-to-proto3-converter-%s" % _disco_to_proto3_converter_commit,
urls = ["https://github.com/googleapis/disco-to-proto3-converter/archive/%s.zip" % _disco_to_proto3_converter_commit],
)

# Showcase
_showcase_version = "0.28.2"

http_archive(
name = "com_google_gapic_showcase",
strip_prefix = "gapic-showcase-%s" % _showcase_version,
urls = [
"https://github.com/googleapis/gapic-showcase/archive/refs/tags/v%s.zip" % _showcase_version,
],
)

http_archive(
name = "rules_pkg",
sha256 = "8a298e832762eda1830597d64fe7db58178aa84cd5926d76d5b744d6558941c2",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.7.0/rules_pkg-0.7.0.tar.gz",
"https://github.com/bazelbuild/rules_pkg/releases/download/0.7.0/rules_pkg-0.7.0.tar.gz",
],
)

load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies")

rules_pkg_dependencies()
9 changes: 9 additions & 0 deletions library_generation/test/resources/misc/testversions.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# test versions.txt obtained from sdk-platform-java

gapic-generator-java:2.25.0:2.25.1-SNAPSHOT
api-common:2.16.0:2.16.1-SNAPSHOT
gax:2.33.0:2.33.1-SNAPSHOT
gax-grpc:2.34.0:2.33.1-SNAPSHOT
gax-httpjson:0.118.0:0.118.1-SNAPSHOT
proto-google-common-protos:2.24.0:2.24.1-SNAPSHOT
grpc-google-common-protos:2.24.0:2.24.1-SNAPSHOT
Loading