Skip to content

Commit 3857e3f

Browse files
feat: generate showcase using docker image (#3568)
Fixes #2470 ### Approach #### In `showcase/` * Revamp the generation and verification scripts used by `-Penable-golden-tests` and `-Pupdate` to build and use the Hermetic Build Docker image ### Effects * New `samples/` folder added in `showcase` * Reformatted all of grpc, proto and gapic libraries in `showcase/` --------- Co-authored-by: cloud-java-bot <[email protected]>
1 parent d92e715 commit 3857e3f

File tree

863 files changed

+48795
-25564
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

863 files changed

+48795
-25564
lines changed

.cloudbuild/library_generation/library_generation.Dockerfile

+8-8
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,6 @@ RUN source /src/library_generation/utils/utilities.sh \
9898
# similar to protoc, we indicate grpc is available in the container via env vars
9999
ENV DOCKER_GRPC_LOCATION="/grpc/protoc-gen-grpc-java.exe"
100100

101-
# Here we transfer gapic-generator-java from the previous stage.
102-
# Note that the destination is a well-known location that will be assumed at runtime
103-
# We hard-code the location string to avoid making it configurable (via ARG) as
104-
# well as to avoid it making it overridable at runtime (via ENV).
105-
COPY --from=ggj-build "/sdk-platform-java/gapic-generator-java.jar" "${HOME}/.library_generation/gapic-generator-java.jar"
106-
RUN chmod 755 "${HOME}/.library_generation/gapic-generator-java.jar"
107-
ENV GAPIC_GENERATOR_LOCATION="${HOME}/.library_generation/gapic-generator-java.jar"
108-
109101
RUN python -m pip install --upgrade pip
110102

111103
# install main scripts as a python package
@@ -125,6 +117,14 @@ RUN owl-bot copy-code --version
125117
RUN chmod o+rx $(which owl-bot)
126118
RUN apk del -r npm && apk cache clean
127119

120+
# Here we transfer gapic-generator-java from the previous stage.
121+
# Note that the destination is a well-known location that will be assumed at runtime
122+
# We hard-code the location string to avoid making it configurable (via ARG) as
123+
# well as to avoid it making it overridable at runtime (via ENV).
124+
COPY --from=ggj-build "/sdk-platform-java/gapic-generator-java.jar" "${HOME}/.library_generation/gapic-generator-java.jar"
125+
RUN chmod 755 "${HOME}/.library_generation/gapic-generator-java.jar"
126+
ENV GAPIC_GENERATOR_LOCATION="${HOME}/.library_generation/gapic-generator-java.jar"
127+
128128
# download the Java formatter
129129
ADD https://maven-central.storage-download.googleapis.com/maven2/com/google/googlejavaformat/google-java-format/${JAVA_FORMAT_VERSION}/google-java-format-${JAVA_FORMAT_VERSION}-all-deps.jar \
130130
"${HOME}"/.library_generation/google-java-format.jar

.github/scripts/action.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ inputs:
3030
image_tag:
3131
description: the tag of hermetic build image
3232
required: false
33+
showcase_mode:
34+
description: true if we need to download the showcase api definitions
35+
required: false
3336
token:
3437
description: Personal Access Token
3538
required: true
@@ -72,9 +75,11 @@ runs:
7275
bash hermetic_library_generation.sh \
7376
--target_branch "${BASE_REF}" \
7477
--current_branch "${HEAD_REF}" \
78+
--showcase_mode "${SHOWCASE_MODE}" \
7579
--image_tag "${IMAGE_TAG}"
7680
env:
7781
BASE_REF: ${{ inputs.base_ref }}
7882
HEAD_REF: ${{ inputs.head_ref }}
7983
IMAGE_TAG: ${{ inputs.image_tag }}
84+
SHOWCASE_MODE: ${{ inputs.showcase_mode }}
8085
GH_TOKEN: ${{ inputs.token }}

.github/scripts/hermetic_library_generation.sh

+17-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
set -e
2+
set -ex
33
# This script should be run at the root of the repository.
44
# This script is used to, when a pull request changes the generation
55
# configuration (generation_config.yaml by default) or Dockerfile:
@@ -25,6 +25,8 @@ set -e
2525
# 3. [optional] image_tag, the tag of gcr.io/cloud-devrel-public-resources/java-library-generation.
2626
# 4. [optional] generation_config, the path to the generation configuration,
2727
# the default value is generation_config.yaml in the repository root.
28+
# 5. [optional] showcase_mode, true if we wish to download the showcase api
29+
# definitions, which are necessary for generating the showcase library.
2830
while [[ $# -gt 0 ]]; do
2931
key="$1"
3032
case "${key}" in
@@ -44,6 +46,10 @@ case "${key}" in
4446
generation_config="$2"
4547
shift
4648
;;
49+
--showcase_mode)
50+
showcase_mode="$2"
51+
shift
52+
;;
4753
*)
4854
echo "Invalid option: [$1]"
4955
exit 1
@@ -62,6 +68,10 @@ if [ -z "${current_branch}" ]; then
6268
exit 1
6369
fi
6470

71+
if [ -z "${download_showcase}" ]; then
72+
download_showcase="false"
73+
fi
74+
6575
if [ -z "${generation_config}" ]; then
6676
generation_config=generation_config.yaml
6777
echo "Use default generation config: ${generation_config}"
@@ -89,6 +99,12 @@ pushd "${api_def_dir}"
8999
git checkout "${googleapis_commitish}"
90100
popd
91101

102+
# we also setup showcase
103+
if [[ "${showcase_mode}" == "true" ]]; then
104+
source java-showcase/scripts/showcase_utilities.sh
105+
append_showcase_to_api_defs "${api_def_dir}"
106+
fi
107+
92108
# get changed library list.
93109
changed_libraries=$(python hermetic_build/common/cli/get_changed_libraries.py create \
94110
--baseline-generation-config-path="${baseline_generation_config}" \
@@ -98,7 +114,6 @@ echo "Changed libraries are: ${changed_libraries:-"No changed library"}."
98114
# run hermetic code generation docker image.
99115
docker run \
100116
--rm \
101-
--quiet \
102117
-u "$(id -u):$(id -g)" \
103118
-v "$(pwd):${workspace_name}" \
104119
-v "${api_def_dir}:${workspace_name}/googleapis" \

.github/snippet-bot.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ alwaysCreateStatusCheck: false
33
ignoreFiles:
44
- src/test/**
55
- test/**
6-
- showcase/**
6+
- java-showcase/**
77
- library_generation/owlbot/templates/java_library/samples/install-without-bom/pom.xml
88
- library_generation/owlbot/synthtool/gcp/snippets.py

.github/workflows/ci.yaml

+9-8
Original file line numberDiff line numberDiff line change
@@ -229,18 +229,18 @@ jobs:
229229
run: |
230230
mvn install -B -ntp -DskipTests -Dclirr.skip -Dcheckstyle.skip
231231
- name: Java Linter
232-
working-directory: showcase
232+
working-directory: java-showcase
233233
run: |
234234
mvn -B -ntp fmt:check
235235
- name: Showcase golden tests
236-
working-directory: showcase
236+
working-directory: java-showcase
237237
run: |
238238
mvn test \
239239
-P enable-golden-tests \
240240
--batch-mode \
241241
--no-transfer-progress
242242
- name: Parse showcase version
243-
working-directory: showcase/gapic-showcase
243+
working-directory: java-showcase/gapic-showcase
244244
run: echo "SHOWCASE_VERSION=$(mvn help:evaluate -Dexpression=gapic-showcase.version -q -DforceStdout)" >> "$GITHUB_ENV"
245245
- name: Install showcase server
246246
run: |
@@ -252,15 +252,15 @@ jobs:
252252
./gapic-showcase run &
253253
cd -
254254
- name: Showcase integration tests
255-
working-directory: showcase
255+
working-directory: java-showcase
256256
run: |
257257
mvn verify \
258258
-P enable-integration-tests \
259259
--batch-mode \
260260
--no-transfer-progress
261261
# The `slf4j2_logback` profile brings logging dependency and compiles logging tests, require env var to be set
262262
- name: Showcase integration tests - Logging SLF4J 2.x
263-
working-directory: showcase
263+
working-directory: java-showcase
264264
run: |
265265
mvn clean verify -P '!showcase,enable-integration-tests,loggingTestBase,slf4j2_logback' \
266266
--batch-mode \
@@ -270,7 +270,7 @@ jobs:
270270
GOOGLE_SDK_JAVA_LOGGING: true
271271
# The `slf4j1_logback` profile brings logging dependency and compiles logging tests, require env var to be set
272272
- name: Showcase integration tests - Logging SLF4J 1.x
273-
working-directory: showcase
273+
working-directory: java-showcase
274274
run: |
275275
mvn clean verify -P '!showcase,enable-integration-tests,loggingTestBase,slf4j1_logback' \
276276
--batch-mode \
@@ -281,7 +281,7 @@ jobs:
281281
# The `disabledLogging` profile tests logging disabled when logging dependency present,
282282
# do not set env var for this step
283283
- name: Showcase integration tests - Logging disabed
284-
working-directory: showcase
284+
working-directory: java-showcase
285285
run: |
286286
mvn clean verify -P '!showcase,enable-integration-tests,loggingTestBase,disabledLogging' \
287287
--batch-mode \
@@ -303,6 +303,7 @@ jobs:
303303
- name: Install sdk-platform-java and showcase to local maven repository
304304
run: |
305305
mvn install -B -ntp -T 1C -DskipTests
306+
# change to `cd java-showcase` once https://github.com/googleapis/sdk-platform-java/pull/3568/ is merged
306307
cd showcase
307308
mvn install -B -ntp -T 1C -DskipTests
308309
SHOWCASE_CLIENT_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
@@ -313,7 +314,7 @@ jobs:
313314
run: mvn install -B -ntp -T 1C -DskipTests
314315
# Showcase golden test ensures that src changes are already reflected in the PR.
315316
- name: Clirr check
316-
working-directory: showcase
317+
working-directory: java-showcase
317318
run: |
318319
mvn versions:set -B -ntp -DnewVersion=local
319320
mvn clirr:check -B -ntp -Dclirr.skip=false -DcomparisonVersion=$SHOWCASE_CLIENT_VERSION

.github/workflows/hermetic_library_generation.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,4 @@ jobs:
6262
head_ref: ${{ github.head_ref }}
6363
image_tag: ${{ env.GENERATOR_VERSION }}
6464
token: ${{ secrets.CLOUD_JAVA_BOT_TOKEN }}
65+
showcase_mode: true

.github/workflows/sonar.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ jobs:
3333
- name: Install modules to local maven
3434
run: |
3535
mvn install -T 1C -DskipTests -ntp -B
36-
cd showcase
36+
cd java-showcase
3737
mvn install -T 1C -DskipTests -ntp -B
3838
- name: Parse showcase version
39-
working-directory: showcase/gapic-showcase
39+
working-directory: java-showcase/gapic-showcase
4040
run: echo "SHOWCASE_VERSION=$(mvn help:evaluate -Dexpression=gapic-showcase.version -q -DforceStdout)" >> "$GITHUB_ENV"
4141
- name: Install showcase server
4242
run: |

.kokoro/presubmit/common_test.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ cd target
2222
function test_find_all_poms_with_versioned_dependency {
2323
mkdir -p test_find_all_poms_with_dependency
2424
pushd test_find_all_poms_with_dependency
25-
cp ../../showcase/gapic-showcase/pom.xml pom.xml
25+
cp ../../java-showcase/gapic-showcase/pom.xml pom.xml
2626

2727
find_all_poms_with_versioned_dependency 'truth'
2828
if [ "${#POMS[@]}" != 1 ]; then
@@ -45,7 +45,7 @@ function test_find_all_poms_with_versioned_dependency {
4545
function test_update_pom_dependency {
4646
mkdir -p test_update_pom_dependency
4747
pushd test_update_pom_dependency
48-
cp ../../showcase/gapic-showcase/pom.xml pom.xml
48+
cp ../../java-showcase/gapic-showcase/pom.xml pom.xml
4949

5050
update_pom_dependency . truth "99.88.77"
5151

@@ -66,7 +66,7 @@ EOF
6666
function test_parse_pom_version {
6767
mkdir -p test_parse_pom_version
6868
pushd test_parse_pom_version
69-
cp ../../showcase/gapic-showcase/pom.xml pom.xml
69+
cp ../../java-showcase/gapic-showcase/pom.xml pom.xml
7070

7171
VERSION=$(parse_pom_version .)
7272
if [ "$VERSION" != "0.0.1-SNAPSHOT" ]; then

.kokoro/presubmit/showcase-native.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ mvn install --projects '!gapic-generator-java' \
3838
SHARED_DEPS_VERSION=$(parse_pom_version java-shared-dependencies)
3939

4040
# Run showcase integration tests in GraalVM
41-
pushd showcase/gapic-showcase
41+
pushd java-showcase/gapic-showcase
4242
SHOWCASE_VERSION=$(mvn help:evaluate -Dexpression=gapic-showcase.version -q -DforceStdout)
4343
popd
4444
# Start showcase server
@@ -52,7 +52,7 @@ tar -xf showcase-*
5252
popd
5353

5454
# Run showcase tests with `native` profile
55-
pushd showcase
55+
pushd java-showcase
5656
mvn test -Pnative,-showcase \
5757
-Denforcer.skip=true \
5858
-Dcheckstyle.skip \

generation_config.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@ googleapis_commitish: fbbbf5023815f9a662c85aa8af8f3b72467fcb6f
33
# java-{library.library_name} or java-{library.api-shortname} when
44
# library.library_name is not defined.
55
libraries:
6+
- api_shortname: showcase
7+
excluded_poms: gapic-showcase-bom
8+
name_pretty: Showcase
9+
api_description: Showcase module
10+
product_documentation: https://cloud.google.com/dummy
11+
distribution_name: com.google.cloud:gapic-showcase
12+
library_type: OTHER
13+
GAPICs:
14+
- proto_path: schema/google/showcase/v1beta1
615
- api_shortname: common-protos
716
name_pretty: Common Protos
817
product_documentation: https://github.com/googleapis/api-common-protos
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
java_gapic_library(
2+
deps = [
3+
"//google/cloud/location:location_java_proto",
4+
"//google/iam/v1:iam_java_proto"
5+
],
6+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
proto_library_with_info(
2+
# this comment should not indicate an end of a pattern match )
3+
deps = [
4+
"//google/cloud/location:location_proto",
5+
]
6+
)
7+
8+
java_gapic_library(
9+
# this comment should not indicate an end of a pattern match )
10+
deps = [
11+
"//google/iam/v1:iam_java_proto"
12+
],
13+
)

java-showcase/.OwlBot-hermetic.yaml

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Copyright 2024 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
16+
deep-remove-regex:
17+
- "/grpc-gapic-showcase-v1beta1/src"
18+
- "/proto-gapic-showcase-v1beta1/src"
19+
- "/gapic-showcase/src"
20+
- "/samples/snippets/generated"
21+
22+
deep-preserve-regex:
23+
- "/gapic-showcase/src/test"
24+
25+
deep-copy-regex:
26+
- source: "/schema/google/showcase/(v.*)/.*-java/proto-.*/src"
27+
dest: "/owl-bot-staging/showcase/$1/proto-gapic-showcase-$1/src"
28+
- source: "/schema/google/showcase/(v.*)/.*-java/grpc-.*/src"
29+
dest: "/owl-bot-staging/showcase/$1/grpc-gapic-showcase-$1/src"
30+
- source: "/schema/google/showcase/(v.*)/.*-java/gapic-.*/src"
31+
dest: "/owl-bot-staging/showcase/$1/gapic-showcase/src"
32+
- source: "/schema/google/showcase/(v.*)/.*-java/samples/snippets/generated"
33+
dest: "/owl-bot-staging/showcase/$1/samples/snippets/generated"
34+
35+
api-name: showcase

java-showcase/.repo-metadata.json

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"api_shortname": "showcase",
3+
"name_pretty": "Showcase",
4+
"product_documentation": "https://cloud.google.com/dummy",
5+
"api_description": "Showcase module",
6+
"client_documentation": "https://cloud.google.com/java/docs/reference/gapic-showcase/latest/overview",
7+
"release_level": "preview",
8+
"transport": "both",
9+
"language": "java",
10+
"repo": "googleapis/sdk-platform-java",
11+
"repo_short": "java-showcase",
12+
"distribution_name": "com.google.cloud:gapic-showcase",
13+
"library_type": "OTHER",
14+
"requires_billing": true,
15+
"excluded_poms": "gapic-showcase-bom"
16+
}

showcase/README.md renamed to java-showcase/README.md

+13-9
Original file line numberDiff line numberDiff line change
@@ -64,28 +64,32 @@ gapic-showcase run
6464
## Running the Integration Tests
6565

6666
Open a new terminal window in the root project directory.
67+
This step does not require Docker.
6768

6869
```shell
6970
cd showcase
70-
mvn verify -P enable-integration-tests -P enable-golden-tests
71+
mvn verify -P enable-integration-tests
7172
```
7273

73-
Note:
74+
## Running the Golden tests
75+
76+
**NOTE** This requires Docker to be installed in your machine.
77+
Open a new terminal window in the root project directory.
78+
79+
```shell
80+
cd java-showcase
81+
mvn verify -P enable-golden-tests
82+
```
7483

75-
* `-P enable-golden-tests` is optional. These tests do not require a local server.
7684

7785
## Update the Golden Showcase Files
7886

87+
**NOTE** This requires Docker to be installed in your machine.
7988
Open a new terminal window in the root project directory.
80-
Note that the underlying scripts will modify your `$HOME` folder by creating a
81-
`.library_generation` folder.
82-
This is the well-known location of the artifacts the generation scripts use.
83-
For more details see the
84-
[development guide](https://github.com/googleapis/sdk-platform-java/blob/main/hermetic_build/DEVELOPMENT.md#the-hermetic-builds-well-known-folder)
8589

8690
```shell
8791
# In repository's root directory
8892
mvn clean install -DskipTests
89-
cd showcase
93+
cd java-showcase
9094
mvn compile -P update
9195
```

0 commit comments

Comments
 (0)