|
1 | 1 | #!/bin/bash |
2 | | -# Generates the showcase library using the docker image, which is built |
3 | | -# from the current state of the repo in order to test local changes. |
| 2 | +# Generates the showcase library using librarian. |
4 | 3 | set -ex |
5 | 4 |
|
6 | 5 | echo "******** Generating Showcase ********" |
7 | 6 |
|
8 | | -trap cleanup ERR |
9 | | - |
10 | 7 | readonly ROOT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )/../.." |
11 | | -pushd "${ROOT_DIR}" |
12 | | -source "${ROOT_DIR}/java-showcase/scripts/showcase_utilities.sh" |
13 | | - |
14 | | -cleanup() { |
15 | | - if [[ -z "${api_def_dir}" ]]; then |
16 | | - rm -rf "${api_def_dir}" |
17 | | - fi |
18 | | - if [[ -z "${showcase_def_dir}" ]]; then |
19 | | - rm -rf "${showcase_def_dir}" |
20 | | - fi |
21 | | -} |
22 | | - |
23 | | -while [[ $# -gt 0 ]]; do |
24 | | -key="$1" |
25 | | -case "${key}" in |
26 | | - --replace) |
27 | | - replace="$2" |
28 | | - shift |
29 | | - ;; |
30 | | - *) |
31 | | - echo "Invalid option: [$1]" |
32 | | - exit 1 |
33 | | - ;; |
34 | | -esac |
35 | | -shift |
36 | | -done |
37 | | - |
38 | | -if [ -z "${replace}" ]; then |
39 | | - replace="false" |
40 | | -fi |
41 | | - |
42 | | - |
43 | | -# download api definitions from googleapis repository |
44 | | -googleapis_commitish=$(grep googleapis_commitish generation_config.yaml | cut -d ":" -f 2 | xargs) |
45 | | -api_def_dir=$(mktemp -d) |
46 | | -git clone https://github.com/googleapis/googleapis.git "${api_def_dir}" |
47 | | - |
48 | | -pushd "${api_def_dir}" |
49 | | -git checkout "${googleapis_commitish}" |
50 | | -# for local setups, we avoid permission issues when the docker image |
51 | | -# performs version-dependent operations. |
52 | | -rm -rf ".git/" |
53 | | -popd |
54 | | - |
55 | | -append_showcase_to_api_defs "${api_def_dir}" |
56 | | - |
57 | | -if [[ -f "image-id" ]]; then |
58 | | - echo "image already exists:" |
59 | | - cat image-id |
60 | | -else |
61 | | - echo "building docker image" |
62 | | - DOCKER_BUILDKIT=1 docker build --file sdk-platform-java/.cloudbuild/library_generation/library_generation.Dockerfile --iidfile image-id . |
63 | | -fi |
64 | | - |
65 | | -if [[ "${replace}" == "true" ]]; then |
66 | | - generated_files_dir="${ROOT_DIR}" |
67 | | -else |
68 | | - export generated_files_dir=$(mktemp -d) |
69 | | - # here we store the generated library location for upstream scripts to use |
70 | | - # it. |
71 | | - echo "${generated_files_dir}/java-showcase" > "${ROOT_DIR}/generated-showcase-location" |
72 | | - # we prepare the temp folder with the minimal setup to perform an incremental |
73 | | - # generation. |
74 | | - pushd "${ROOT_DIR}" |
75 | | - cp -r generation_config.yaml java-showcase/ versions.txt "${generated_files_dir}" |
76 | | - popd #ROOT_DIR |
77 | | -fi |
| 8 | +# Export PYTHONPATH so that owlbot.py scripts run by Librarian |
| 9 | +# can resolve local synthtool under the hermetic build directory. |
| 10 | +export PYTHONPATH="${ROOT_DIR}/sdk-platform-java/hermetic_build/library_generation/owlbot" |
| 11 | +cd "${ROOT_DIR}" |
78 | 12 |
|
79 | | -pushd sdk-platform-java |
80 | | -GENERATOR_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout -pl gapic-generator-java) |
81 | | -popd |
| 13 | +readonly LIBRARIAN_VER=$(go run github.com/googleapis/librarian/cmd/librarian@latest config get version) |
| 14 | +readonly LIBRARIAN_CMD="go run github.com/googleapis/librarian/cmd/librarian@${LIBRARIAN_VER}" |
82 | 15 |
|
83 | | -echo "generating showcase" |
84 | | -workspace_name="/workspace" |
85 | | -docker run \ |
86 | | - --rm \ |
87 | | - -u "$(id -u):$(id -g)" \ |
88 | | - -v "${generated_files_dir}:${workspace_name}" \ |
89 | | - -v "${api_def_dir}:${workspace_name}/googleapis" \ |
90 | | - -e GENERATOR_VERSION="${GENERATOR_VERSION}" \ |
91 | | - "$(cat image-id)" \ |
92 | | - --generation-config-path="${workspace_name}/generation_config.yaml" \ |
93 | | - --library-names="showcase" \ |
94 | | - --api-definitions-path="${workspace_name}/googleapis" |
| 16 | +echo "generating showcase in place" |
| 17 | +$LIBRARIAN_CMD generate showcase |
95 | 18 |
|
96 | | -echo "generated showcase library in ${generated_files_dir}" |
| 19 | +echo "generated showcase library" |
0 commit comments