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 108 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 0 additions & 12 deletions library_generation/README.md
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
@@ -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
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
76 changes: 68 additions & 8 deletions library_generation/utilities.sh
Expand Up @@ -63,16 +63,14 @@ find_additional_protos_in_yaml() {
# pulled from googleapis as a prerequisite.
# Search additional protos in .yaml files.
search_additional_protos() {
local additional_protos="google/cloud/common_resources.proto" # used by every library
local iam_policy
local locations
iam_policy=$(find_additional_protos_in_yaml "name: google.iam.v1.IAMPolicy")
if [ -n "${iam_policy}" ]; then
additional_protos="${additional_protos} google/iam/v1/iam_policy.proto"
additional_protos="google/cloud/common_resources.proto" # used by every library
iam_policy=$(find_additional_protos_in_yaml "name: '*google.iam.v1.IAMPolicy'*")
JoeWang1127 marked this conversation as resolved.
Show resolved Hide resolved
if [ -n "$iam_policy" ]; then
additional_protos="$additional_protos google/iam/v1/iam_policy.proto"
fi
locations=$(find_additional_protos_in_yaml "name: google.cloud.location.Locations")
locations=$(find_additional_protos_in_yaml "name: '*google.cloud.location.Locations'*")
if [ -n "${locations}" ]; then
additional_protos="${additional_protos} google/cloud/location/locations.proto"
additional_protos="$additional_protos google/cloud/location/locations.proto"
fi
echo "${additional_protos}"
}
Expand Down Expand Up @@ -216,3 +214,65 @@ download_fail() {
>&2 echo "Fail to download ${artifact} from ${repo} repository. Please install ${artifact} first if you want to download a SNAPSHOT."
exit 1
}

# Obtains a version from a bazel WORKSPACE file
#
# versions look like "_ggj_version="1.2.3"
# It will return 1.2.3 for such example
get_version_from_WORKSPACE() {
diegomarquezp marked this conversation as resolved.
Show resolved Hide resolved
version_key_word=$1
workspace=$2
version=$(\
cat "$workspace" |\
grep "$version_key_word" |\
head -n 1 |\
sed 's/\(.*\) = "\(.*\)"\(.*\)/\2/' |\
sed 's/[a-zA-Z-]*//'
)
echo "$version"
}

# Used to obtain configuration values from a bazel BUILD file
#
# inspects a $build_file for a certain $rule (e.g. java_gapic_library). If the
# first 15 lines after the declaration of the rule contain $pattern, then
# it will return $if_match if $pattern is found, otherwise $default
get_config_from_BUILD() {
build_file=$1
rule=$2
pattern=$3
default=$4
if_match=$5

result="$default"
if grep -A 15 "$rule" "$build_file" | grep -q "$pattern"; then
result="$if_match"
fi
echo "$result"

}

get_version_from_versions_txt() {
versions=$1
key=$2
version=$(cat "$versions" | grep "$key" | cut -d: -f3) # 3rd field is snapshot
echo $version
}


# Convenience function to clone only the necessary folders from a git repository
sparse_clone() {
repo_url=$1
paths=$2
commitish=$3
clone_dir=$(basename "${repo_url%.*}")
rm -rf "$clone_dir"
git clone -n --depth=1 --no-single-branch --filter=tree:0 "$repo_url"
cd "$clone_dir"
if [ ! -z $commitish ]; then
git checkout $commitish
fi
git sparse-checkout set --no-cone $paths
git checkout
cd ..
}
167 changes: 0 additions & 167 deletions showcase/BUILD.bazel

This file was deleted.