Skip to content

Commit 7218d80

Browse files
feat: generate showcase without post-processing (#1935)
* feat: add * generate gapic and proto folder * refactor utilities * add an action to verify * checkout googleapis-gen * setup repo name * add commit hash of googleapis-gen * change secret * change token * change to git clone * change user name * add input list * include resources folder in main * remove grpc version in `*ServiceGrpc.java` * change destination path * compare generation result with googleapis-gen * fix type in diff command * checkout repo using checkout action * checkout repos as nested repo * sparse checkout googleapis * Revert "sparse checkout googleapis" This reverts commit 3d612f8. * change library * change step name * add a readme * make grpc version optional * make protobuf version optional * checkout master branch, rather than a commit hash * allow snapshot version of generator * download snapshot of generator parent pom * update README * chore: add test script for showcase this produces various differences in the output. Mainly additional protos not being detected, a mismatch between proto-gapic-showcase-v1beta1/src/proto (arbitrary path) * chore: fix additional protos logic * download generator and grpc using mvn * change error message * add maven central mirror * add comments in utilities * add comments * add an integration test * chore: modify showcase source proto folder structure * fail fast if no file is found * chore: add showcase integration test * chore: add action to test on showase * chore: add diff check for showcase IT * do not delete google/ * chore: change file mod in protos * chore: fix diff comparison * chore: remove unwanted binary * get protobuf version from WORKSPACE * add instructions on download `google/` from googleapis * add comments * chore: final adjustments for showcase testing * chore: allow workflow dispatch on workflow * chore: correct yaml definition * chore: correct yaml definition ii * chore: fix util import * update description of `destination_path` * chore: correct version parsing * chore: correct showcase version * chore: try java 11 * update comments * chore: infer grpc_version from parent pom * download dependencies using `curl` * increase download time * remove comment * generate components for showcase * use script in maven profile * correct compilation components * explicit output folder path check * use poms to resolve versions * migrate showcase scripts to showcase folder * remove bazel-based update script * finalize migration for generation * fix generation * change verification profile for gapic-showcase * remove unused functions in verify.sh * remove unused CI component * remove showcase from readme * remove unused logic * script comments and cleanup * improve comment in generate_component * remove unused bazel files * remove .gitignore in favor of cleanup * bash format * transfer profiles to showcase parent * fix parent pom script call * fix wildcard for source replacement * fix proto golden test, add util script * install xmllint * sudo for installing xmlint * correct xmllint package * Update library_generation/utilities.sh Co-authored-by: Joe Wang <[email protected]> * restore gh action * move convenience functions to utilities file * remove duplicate file\ * fix proto path * use `sed` and `cut` to extract showcase version * add unit tests for new functions * add test for versions --------- Co-authored-by: JoeWang1127 <[email protected]> Co-authored-by: Joe Wang <[email protected]>
1 parent 41f6ef6 commit 7218d80

File tree

24 files changed

+467
-377
lines changed

24 files changed

+467
-377
lines changed

library_generation/README.md

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,3 @@ library_generation/generate_library.sh \
125125
--include_samples true
126126
```
127127

128-
## An example to generate showcase client
129-
```
130-
library_generation/generate_library.sh \
131-
-p schema/google/showcase/v1beta1 \ # google/ should be in library_generation/.
132-
-d output \
133-
--gapic_generator_version 2.24.0 \
134-
--protobuf_version 23.2 \
135-
--grpc_version 1.55.1 \
136-
--transport grpc+rest \
137-
--rest_numeric_enums false \
138-
--include_samples false
139-
```

library_generation/generate_library.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env bash
22

33
set -eo pipefail
4+
set -x
45

56
# parse input parameters
67
while [[ $# -gt 0 ]]; do
@@ -157,3 +158,4 @@ done
157158
#####################################################
158159
cd "${destination_path}"
159160
rm -rf java_gapic_srcjar java_gapic_srcjar_raw.srcjar.zip java_grpc.jar java_proto.jar temp-codegen.srcjar
161+
set +x

library_generation/test/generate_library_integration_test.sh

Lines changed: 21 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -42,34 +42,13 @@ esac
4242
shift # past argument or value
4343
done
4444

45-
get_version_from_WORKSPACE() {
46-
local version_key_word=$1
47-
local workspace=$2
48-
local delimiter=$3
49-
local version
50-
version="$(grep -m 1 "${version_key_word}" "${workspace}" | sed 's/\"\(.*\)\".*/\1/' | cut -d "${delimiter}" -f2 | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')"
51-
echo "${version}"
52-
}
53-
54-
sparse_clone() {
55-
local repo_url=$1
56-
local paths=$2
57-
local clone_dir
58-
clone_dir=$(basename "${repo_url%.*}")
59-
rm -rf "${clone_dir}"
60-
git clone -n --depth=1 --filter=tree:0 "${repo_url}"
61-
cd "${clone_dir}"
62-
git sparse-checkout set --no-cone ${paths}
63-
git checkout
64-
cd ..
65-
}
66-
6745
script_dir=$(dirname "$(readlink -f "$0")")
46+
source "${script_dir}/../utilities.sh"
6847
library_generation_dir="${script_dir}"/..
6948
cd "${library_generation_dir}"
7049
# checkout the master branch of googleapis/google (proto files) and WORKSPACE
7150
echo "Checking out googlapis repository..."
72-
sparse_clone https://github.com/googleapis/googleapis.git "${proto_path} WORKSPACE google/api google/rpc google/cloud/common_resources.proto"
51+
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"
7352
cd googleapis
7453
# parse version of gapic-generator-java, protobuf and grpc from WORKSPACE
7554
gapic_generator_version=$(get_version_from_WORKSPACE "_gapic_generator_java_version" WORKSPACE "=")
@@ -79,18 +58,25 @@ echo "The version of protobuf is ${protobuf_version}"
7958
grpc_version=$(get_version_from_WORKSPACE "_grpc_version" WORKSPACE "=")
8059
echo "The version of protoc-gen-grpc-java plugin is ${gapic_generator_version}."
8160
# parse GAPIC options from proto_path/BUILD.bazel
82-
transport="grpc"
83-
if grep -A 15 "java_gapic_library(" "${proto_path}/BUILD.bazel" | grep -q "grpc+rest"; then
84-
transport="grpc+rest"
85-
fi
86-
rest_numeric_enums="true"
87-
if grep -A 15 "java_gapic_library(" "${proto_path}/BUILD.bazel" | grep -q "rest_numeric_enums = False"; then
88-
rest_numeric_enums="false"
89-
fi
90-
include_samples="false"
91-
if grep -A 15 "java_gapic_assembly_gradle_pkg(" "${proto_path}/BUILD.bazel" | grep -q "include_samples = True"; then
92-
include_samples="true"
93-
fi
61+
proto_build_file_path="${proto_path}/BUILD.bazel"
62+
transport=$(get_config_from_BUILD \
63+
"${proto_build_file_path}" \
64+
"java_gapic_library(" \
65+
"grpc+rest" \
66+
"grpc"
67+
)
68+
rest_numeric_enums=$(get_config_from_BUILD \
69+
"${proto_build_file_path}" \
70+
"java_gapic_library(" \
71+
"rest_numeric_enums = False" \
72+
"true"
73+
)
74+
include_samples=$(get_config_from_BUILD \
75+
"${proto_build_file_path}" \
76+
"java_gapic_assembly_gradle_pkg(" \
77+
"include_samples = True" \
78+
"false"
79+
)
9480
echo "GAPIC options are transport=${transport}, rest_numeric_enums=${rest_numeric_enums}, include_samples=${include_samples}."
9581
os_architecture="linux-x86_64"
9682
if [[ "$os_type" == *"macos"* ]]; then

library_generation/test/generate_library_unit_tests.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,48 @@ download_grpc_plugin_failed_with_invalid_arch_test() {
219219
__assertEquals 1 $((res))
220220
}
221221

222+
get_config_from_valid_BUILD_test() {
223+
build_file="${script_dir}/resources/misc/TESTBUILD.bazel"
224+
rule="java_gapic_library("
225+
# the pattern we expect to find in the BUILD file
226+
pattern_should_match="name"
227+
# the pattern that we should not find in the BUILD file
228+
pattern_should_not_match="should-not-match"
229+
# default value if the pattern was not found
230+
if_matched_return="got-a-match"
231+
if_not_matched_return="no-match"
232+
pattern_matched_result=$(get_config_from_BUILD \
233+
"${build_file}" \
234+
"${rule}" \
235+
"${pattern_should_match}" \
236+
"${if_not_matched_return}" \
237+
"${if_matched_return}"
238+
)
239+
__assertEquals "${pattern_matched_result}" "${if_matched_return}"
240+
pattern_not_matched_result=$(get_config_from_BUILD \
241+
"${build_file}" \
242+
"${rule}" \
243+
"${pattern_should_not_match}" \
244+
"${if_not_matched_return}" \
245+
"${if_matched_return}"
246+
)
247+
__assertEquals "${pattern_not_matched_result}" "${if_not_matched_return}"
248+
}
249+
250+
get_version_from_valid_WORKSPACE_test() {
251+
workspace_file="${script_dir}/resources/misc/TESTWORKSPACE"
252+
obtained_ggj_version=$(get_version_from_WORKSPACE "_gapic_generator_java_version" "${workspace_file}")
253+
__assertEquals '2.25.1-SNAPSHOT' "${obtained_ggj_version}"
254+
}
255+
256+
get_version_from_valid_versions_txt_test() {
257+
versions_file="${script_dir}/resources/misc/testversions.txt"
258+
obtained_ggj_version=$(get_version_from_versions_txt "${versions_file}" "gapic-generator-java")
259+
__assertEquals '2.25.1-SNAPSHOT' "${obtained_ggj_version}"
260+
obtained_gax_version=$(get_version_from_versions_txt "${versions_file}" "gax")
261+
__assertEquals '2.33.1-SNAPSHOT' "${obtained_gax_version}"
262+
}
263+
222264
# Execute tests.
223265
# One line per test.
224266
test_list=(
@@ -244,6 +286,9 @@ test_list=(
244286
download_grpc_plugin_succeed_with_valid_version_macos_test
245287
download_grpc_plugin_failed_with_invalid_version_linux_test
246288
download_grpc_plugin_failed_with_invalid_arch_test
289+
get_config_from_valid_BUILD_test
290+
get_version_from_valid_WORKSPACE_test
291+
get_version_from_valid_versions_txt_test
247292
)
248293

249294
for ut in "${test_list[@]}"; do

showcase/BUILD.bazel renamed to library_generation/test/resources/misc/TESTBUILD.bazel

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
# Note: The commented section is the framework for gapic-showcase-extended
2-
# See gapic-showcase-extended folder for more info
1+
# Test BUILD file, copied from sdk-platform-java/showcase/BUILD.bazel
32

43
load(
54
"//rules_java_gapic:java_gapic.bzl",
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
# test workspace file obtained from sdk-platform-java
2+
3+
workspace(name = "gapic_generator_java")
4+
5+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
6+
7+
# gax-java and its transitive dependencies must be imported before
8+
# gapic-generator-java dependencies to match the order in googleapis repository,
9+
# which in its turn, prioritizes actual generated clients runtime dependencies
10+
# over the generator dependencies.
11+
local_repository(
12+
name = "com_google_api_gax_java",
13+
path = "gax-java",
14+
)
15+
16+
load("@com_google_api_gax_java//:repository_rules.bzl", "com_google_api_gax_java_properties")
17+
18+
com_google_api_gax_java_properties(
19+
name = "com_google_api_gax_java_properties",
20+
file = "@com_google_api_gax_java//:dependencies.properties",
21+
)
22+
23+
load("@com_google_api_gax_java//:repositories.bzl", "com_google_api_gax_java_repositories")
24+
25+
com_google_api_gax_java_repositories()
26+
27+
_googleapis_commit = "7438480b2a1bc6371d748e974f7a3647f90c4e8d"
28+
29+
http_archive(
30+
name = "com_google_googleapis",
31+
strip_prefix = "googleapis-%s" % _googleapis_commit,
32+
urls = [
33+
"https://github.com/googleapis/googleapis/archive/%s.zip" % _googleapis_commit,
34+
],
35+
)
36+
37+
# protobuf
38+
RULES_JVM_EXTERNAL_TAG = "4.5"
39+
40+
RULES_JVM_EXTERNAL_SHA = "b17d7388feb9bfa7f2fa09031b32707df529f26c91ab9e5d909eb1676badd9a6"
41+
42+
http_archive(
43+
name = "rules_jvm_external",
44+
sha256 = RULES_JVM_EXTERNAL_SHA,
45+
strip_prefix = "rules_jvm_external-%s" % RULES_JVM_EXTERNAL_TAG,
46+
url = "https://github.com/bazelbuild/rules_jvm_external/archive/%s.zip" % RULES_JVM_EXTERNAL_TAG,
47+
)
48+
49+
load("@rules_jvm_external//:repositories.bzl", "rules_jvm_external_deps")
50+
51+
rules_jvm_external_deps()
52+
53+
load("@rules_jvm_external//:setup.bzl", "rules_jvm_external_setup")
54+
55+
rules_jvm_external_setup()
56+
57+
load("@com_google_protobuf//:protobuf_deps.bzl", "PROTOBUF_MAVEN_ARTIFACTS", "protobuf_deps")
58+
load("@rules_jvm_external//:defs.bzl", "maven_install")
59+
60+
maven_install(
61+
artifacts = PROTOBUF_MAVEN_ARTIFACTS,
62+
repositories = ["https://repo.maven.apache.org/maven2/"],
63+
)
64+
65+
_gapic_generator_java_version = "2.25.1-SNAPSHOT" # {x-version-update:gapic-generator-java:current}
66+
67+
maven_install(
68+
artifacts = [
69+
"com.google.api:gapic-generator-java:" + _gapic_generator_java_version,
70+
],
71+
fail_on_missing_checksum = False,
72+
repositories = [
73+
"m2Local",
74+
"https://repo.maven.apache.org/maven2/",
75+
],
76+
)
77+
78+
protobuf_deps()
79+
80+
# Bazel rules.
81+
_rules_gapic_version = "0.5.5"
82+
83+
http_archive(
84+
name = "rules_gapic",
85+
strip_prefix = "rules_gapic-%s" % _rules_gapic_version,
86+
urls = ["https://github.com/googleapis/rules_gapic/archive/v%s.tar.gz" % _rules_gapic_version],
87+
)
88+
89+
# Java dependencies.
90+
load("@com_google_googleapis//:repository_rules.bzl", "switched_rules_by_language")
91+
92+
switched_rules_by_language(
93+
name = "com_google_googleapis_imports",
94+
gapic = True,
95+
grpc = True,
96+
java = True,
97+
)
98+
99+
load("@io_grpc_grpc_java//:repositories.bzl", "grpc_java_repositories")
100+
101+
grpc_java_repositories()
102+
103+
_disco_to_proto3_converter_commit = "ce8d8732120cdfb5bf4847c3238b5be8acde87e3"
104+
105+
http_archive(
106+
name = "com_google_disco_to_proto3_converter",
107+
strip_prefix = "disco-to-proto3-converter-%s" % _disco_to_proto3_converter_commit,
108+
urls = ["https://github.com/googleapis/disco-to-proto3-converter/archive/%s.zip" % _disco_to_proto3_converter_commit],
109+
)
110+
111+
# Showcase
112+
_showcase_version = "0.28.2"
113+
114+
http_archive(
115+
name = "com_google_gapic_showcase",
116+
strip_prefix = "gapic-showcase-%s" % _showcase_version,
117+
urls = [
118+
"https://github.com/googleapis/gapic-showcase/archive/refs/tags/v%s.zip" % _showcase_version,
119+
],
120+
)
121+
122+
http_archive(
123+
name = "rules_pkg",
124+
sha256 = "8a298e832762eda1830597d64fe7db58178aa84cd5926d76d5b744d6558941c2",
125+
urls = [
126+
"https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.7.0/rules_pkg-0.7.0.tar.gz",
127+
"https://github.com/bazelbuild/rules_pkg/releases/download/0.7.0/rules_pkg-0.7.0.tar.gz",
128+
],
129+
)
130+
131+
load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies")
132+
133+
rules_pkg_dependencies()
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# test versions.txt obtained from sdk-platform-java
2+
3+
gapic-generator-java:2.25.0:2.25.1-SNAPSHOT
4+
api-common:2.16.0:2.16.1-SNAPSHOT
5+
gax:2.33.0:2.33.1-SNAPSHOT
6+
gax-grpc:2.34.0:2.33.1-SNAPSHOT
7+
gax-httpjson:0.118.0:0.118.1-SNAPSHOT
8+
proto-google-common-protos:2.24.0:2.24.1-SNAPSHOT
9+
grpc-google-common-protos:2.24.0:2.24.1-SNAPSHOT

0 commit comments

Comments
 (0)