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_library.sh with postprocessing #1951

Merged
merged 203 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
203 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
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
4e525a6
fail fast if no file is found
JoeWang1127 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
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
5805e84
update description of `destination_path`
JoeWang1127 Aug 22, 2023
880c27b
update comments
JoeWang1127 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
4f5689a
add samples directory in readme
JoeWang1127 Aug 25, 2023
b38f907
remove prerequisite about `proto_path`
JoeWang1127 Aug 25, 2023
1648254
add explanation in prerequisite
JoeWang1127 Aug 25, 2023
b896cad
add example to generate showcase
JoeWang1127 Aug 25, 2023
f7cb5f7
add a comment
JoeWang1127 Aug 25, 2023
68beeb9
wip adaptations
diegomarquezp Aug 28, 2023
44dedad
add owlbot.py template
diegomarquezp Aug 28, 2023
17d8e55
run owlbot docker image
diegomarquezp Aug 29, 2023
4c63bfd
fix consolidate config
diegomarquezp Aug 30, 2023
4966605
move owlbot call to its own function
diegomarquezp Aug 30, 2023
c4a67e3
move postprocessing logic
diegomarquezp Aug 30, 2023
b60860d
prepare integration test for gh workflow
diegomarquezp Aug 30, 2023
808a281
fix local dev script
diegomarquezp Aug 30, 2023
fc7db26
Merge remote-tracking branch 'origin/main' into feat/generate-aiplatf…
diegomarquezp Aug 30, 2023
7af9688
post-merge fixes
diegomarquezp Aug 30, 2023
6d1b82e
fix test script and IT
diegomarquezp Aug 31, 2023
563f088
fix parent poms
diegomarquezp Aug 31, 2023
a37a630
start fixing samples problem
diegomarquezp Sep 5, 2023
8359fe8
fix samples folder transfer
diegomarquezp Sep 5, 2023
797c3c4
cleanup, prepare IT workflow
diegomarquezp Sep 5, 2023
d9ac0f3
cleanup ii, sparse clone monorepo
diegomarquezp Sep 5, 2023
beb60c0
delete preserve script
diegomarquezp Sep 5, 2023
589eb2a
clean unnecessary lines
diegomarquezp Sep 5, 2023
3425fa1
Merge branch 'main' into feat/generate-aiplatform-with-postprocessing
diegomarquezp Sep 5, 2023
16c9c79
infer owlbot sha
diegomarquezp Sep 5, 2023
e7b7a89
Merge remote-tracking branch 'refs/remotes/origin/feat/generate-aipla…
diegomarquezp Sep 5, 2023
1f92d42
add template file
diegomarquezp Sep 5, 2023
2a4552c
remove newline from owlbot template
diegomarquezp Sep 5, 2023
c5ad849
chore: newline correction
diegomarquezp Sep 5, 2023
18ee764
use stderr for error messages
diegomarquezp Sep 5, 2023
b71fa8a
fix script documentation
diegomarquezp Sep 5, 2023
7169e88
function comments
diegomarquezp Sep 5, 2023
8ac66d3
quoting variables
diegomarquezp Sep 5, 2023
759d175
format constant
diegomarquezp Sep 5, 2023
8f88198
fix sparse checkout of monorepo
diegomarquezp Sep 6, 2023
50ea3d6
include location to googleapis sparse clone
diegomarquezp Sep 8, 2023
45391fa
remove unnecessary parent pom setting
diegomarquezp Sep 8, 2023
a33e8f6
remove consolidate_config.sh
diegomarquezp Sep 8, 2023
b6959e0
exclude changelog and owlbot copy files from diff check
diegomarquezp Sep 8, 2023
a5563fe
Merge remote-tracking branch 'origin/main' into feat/generate-aiplatf…
diegomarquezp Sep 12, 2023
bbf4ad4
fixes after merge
diegomarquezp Sep 12, 2023
2661ae0
include .github in monorepo sparse clone
diegomarquezp Sep 13, 2023
dc90843
restore `set_parent_pom.sh`
diegomarquezp Sep 13, 2023
5ca4077
restore `consolidate_config.sh`
diegomarquezp Sep 13, 2023
dc20ccf
correct parameter resolution
diegomarquezp Sep 13, 2023
bd4032b
use separate variable for version
diegomarquezp Sep 13, 2023
645920b
postprocessing to use separate versions
diegomarquezp Sep 13, 2023
fd2add0
Merge remote-tracking branch 'origin/main' into feat/generate-aiplatf…
diegomarquezp Sep 14, 2023
eb630d6
Merge remote-tracking branch 'origin/main' into feat/generate-aiplatf…
diegomarquezp Sep 14, 2023
6c74dd1
remove old IT file
diegomarquezp Sep 14, 2023
f4aeec1
post-merge fixes
diegomarquezp Sep 14, 2023
51c0cce
enable post-processing by default
diegomarquezp Sep 18, 2023
15776eb
Merge remote-tracking branch 'origin/main' into feat/generate-aiplatf…
diegomarquezp Sep 18, 2023
4d47b5b
post-merge fixes
diegomarquezp Sep 18, 2023
bf59555
post-merge fixes
diegomarquezp Sep 18, 2023
8501e6a
Merge remote-tracking branch 'refs/remotes/origin/feat/generate-aipla…
diegomarquezp Sep 20, 2023
ff56f8f
post merge fixes
diegomarquezp Oct 2, 2023
0e235ff
add script to compare poms
diegomarquezp Oct 3, 2023
949e03a
Merge remote-tracking branch 'origin/main' into feat/generate-aiplatf…
diegomarquezp Oct 4, 2023
26724b9
post-merge fixes
diegomarquezp Oct 4, 2023
cb79e4e
post-merge fixes ii
diegomarquezp Oct 4, 2023
d4db01c
fix pom comparison
diegomarquezp Oct 5, 2023
965ae63
include pre-existing poms before running owlbot
diegomarquezp Oct 5, 2023
206d193
change owlbot-staging suffix folder to run owlbot.py
diegomarquezp Oct 5, 2023
43c3295
fix newline removal in owlbot.py
diegomarquezp Oct 5, 2023
4a7a766
split git diff command
diegomarquezp Oct 5, 2023
d61f635
enable tests for HW libraries
diegomarquezp Oct 11, 2023
4656c8c
generate all hw libs except bigtable
diegomarquezp Oct 11, 2023
89767f9
all libraries passing
diegomarquezp Oct 11, 2023
6957092
fix unit tests
diegomarquezp Oct 11, 2023
0c67ea2
repo metadata json logic cleanup
diegomarquezp Oct 11, 2023
b3169c3
remove new library scripts
diegomarquezp Oct 11, 2023
85e7ef9
fix googleapis-gen tests
diegomarquezp Oct 12, 2023
beef5fa
fix post-processing it
diegomarquezp Oct 12, 2023
a2ac324
magic empty commit
diegomarquezp Oct 12, 2023
457b140
Merge remote-tracking branch 'origin/main' into feat/generate-aiplatf…
diegomarquezp Oct 12, 2023
946ebc5
correct conflict string
diegomarquezp Oct 12, 2023
b3379b9
use os agnostic string replacement
diegomarquezp Oct 12, 2023
0c17333
comments and cleanup on postprocessing
diegomarquezp Oct 12, 2023
0127e7f
cleanup of IT
diegomarquezp Oct 12, 2023
4943488
temp: use custom gapic library name
diegomarquezp Oct 16, 2023
79d9d4b
use owl-bot-copy
diegomarquezp Oct 16, 2023
71b6e57
remove api_version logic
diegomarquezp Oct 17, 2023
b3ac7a6
remove custom_gapic_name in favor of owl-bot-copy
diegomarquezp Oct 17, 2023
68b975a
remove unnecessary new library flag
diegomarquezp Oct 17, 2023
84fdb5b
fix folder name test
diegomarquezp Oct 17, 2023
fb83971
remove unnecessary util function
diegomarquezp Oct 17, 2023
26cb59b
remove unnecessary utils script dir var
diegomarquezp Oct 17, 2023
fd25987
rename postprocessing folder, apply_current_versions comment
diegomarquezp Oct 17, 2023
36d440b
fix postprocessing comments
diegomarquezp Oct 17, 2023
a242fcd
correct popd folder name to its variable name
diegomarquezp Oct 17, 2023
2a04035
unnecessary sed command
diegomarquezp Oct 17, 2023
8cb7551
skip generation if more versions coming
diegomarquezp Oct 17, 2023
38e7573
Merge remote-tracking branch 'origin/main' into feat/generate-aiplatf…
diegomarquezp Oct 17, 2023
8b3a7e6
do not stage previous versions in owl-bot-staging
diegomarquezp Oct 18, 2023
a35f7b0
do not use custom repo metadatas
diegomarquezp Oct 19, 2023
1f15c84
reset workspace folder
diegomarquezp Oct 19, 2023
59ebdfb
remove unnecessary owlbot yaml copy
diegomarquezp Oct 19, 2023
e3fe861
modify readme
diegomarquezp Oct 19, 2023
5f5897c
expand README instructions
diegomarquezp Oct 19, 2023
25358e1
examples for both pre and post processing
diegomarquezp Oct 19, 2023
d03aad6
exclude new library owlbot.py template
diegomarquezp Oct 19, 2023
0f3ce9e
do not process HW libraries
diegomarquezp Oct 19, 2023
aef4f06
success message, folder navigation fix
diegomarquezp Oct 19, 2023
9477110
set git author
diegomarquezp Oct 19, 2023
bd3b673
add docker to workflow
diegomarquezp Oct 19, 2023
025305c
lint fix
diegomarquezp Oct 19, 2023
61bce33
custom docker step for macos
diegomarquezp Oct 19, 2023
5f5e001
do not postprocess showcase
diegomarquezp Oct 19, 2023
1a833e5
os-dependent pom comparison
diegomarquezp Oct 19, 2023
f0b5190
add python to workflow
diegomarquezp Oct 20, 2023
6ae705c
explicit python version
diegomarquezp Oct 20, 2023
0ffb4c5
add debugging output for compare_poms
diegomarquezp Oct 20, 2023
24b0fe2
correct xargs for macos
diegomarquezp Oct 20, 2023
08b9afb
remove debug checkpoints
diegomarquezp Oct 20, 2023
8deeebc
clean compare_poms.py
diegomarquezp Oct 20, 2023
01de512
concise else logic
diegomarquezp Oct 23, 2023
14fd3af
infer destination_path
diegomarquezp Oct 23, 2023
55a22b9
add generation times
diegomarquezp Oct 23, 2023
e10d1eb
remove unused transport and include_samples from postprocessing
diegomarquezp Oct 24, 2023
a97158a
use versions.txt at root of owlbot postprocessor fs
diegomarquezp Oct 24, 2023
c549cd5
modify success message
diegomarquezp Oct 24, 2023
e94cd56
remove unused version processing script
diegomarquezp Oct 24, 2023
b8226dc
remove owlbot_sha and repo_metadata args
diegomarquezp Oct 24, 2023
1c7e5c7
use built-in docker images
diegomarquezp Oct 24, 2023
9d12336
manual install of docker ii
diegomarquezp Oct 24, 2023
d01736a
manual install of docker iii
diegomarquezp Oct 24, 2023
f355551
manual install of docker iv
diegomarquezp Oct 24, 2023
6b9bb19
manual install of docker v
diegomarquezp Oct 24, 2023
7a9bd74
manual install of docker vi
diegomarquezp Oct 24, 2023
fa3f64d
manual install of docker vii
diegomarquezp Oct 24, 2023
a84eb2b
manual install of docker viii
diegomarquezp Oct 24, 2023
955ed0d
manual install of docker ix
diegomarquezp Oct 24, 2023
5886739
versions.txt as an argument
diegomarquezp Oct 24, 2023
bdee6d7
fix exit code in time tracking
diegomarquezp Oct 24, 2023
a5b991e
fix readme
diegomarquezp Oct 24, 2023
d418a9c
remove unused options
diegomarquezp Oct 24, 2023
e896c1c
fix macos docker install
diegomarquezp Oct 26, 2023
8862348
do not use cask to install docker
diegomarquezp Oct 26, 2023
7464c0e
test custom user id in docker run
diegomarquezp Oct 26, 2023
d1bc3f9
correct time tracking entry
diegomarquezp Oct 26, 2023
a2a4ef9
change postprocessing file structture
diegomarquezp Oct 30, 2023
fdcfb1e
move helper postprocess funcs to utilities.sh
diegomarquezp Oct 30, 2023
21e4e85
add unit tests for postprocess utils
diegomarquezp Oct 30, 2023
17436eb
remove repository_path
diegomarquezp Oct 30, 2023
086f95f
fix workspace creation logic
diegomarquezp Oct 30, 2023
3d216d2
fix readme
diegomarquezp Oct 31, 2023
338767e
transfer from workspace to destination path
diegomarquezp Oct 31, 2023
30a1ffc
include folder structure for p.p. libs in readme
diegomarquezp Oct 31, 2023
9228814
omit pre-processed folders
diegomarquezp Oct 31, 2023
a60d3b0
omit package-info.java
diegomarquezp Oct 31, 2023
fcfd510
fix documentation argument order
diegomarquezp Oct 31, 2023
45cb355
fix preparation of copy-code source folder
diegomarquezp Oct 31, 2023
7ab4545
add unit test for copy_directory_if_exists
diegomarquezp Oct 31, 2023
09128a4
fix wrong args to cp
diegomarquezp Oct 31, 2023
173bf3a
change test monorepo folder names
diegomarquezp Oct 31, 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
27 changes: 26 additions & 1 deletion .github/workflows/verify_library_generation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:
matrix:
java: [ 8 ]
os: [ ubuntu-22.04, macos-12 ]
post_processing: [ 'true', 'false' ]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
Expand All @@ -22,11 +23,35 @@ jobs:
java-version: ${{ matrix.java }}
distribution: temurin
cache: maven
- uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: install docker (ubuntu)
if: matrix.os == 'ubuntu-22.04'
run: |
set -x
# install docker
sudo apt install containerd -y
sudo apt install -y docker.io docker-compose

# launch docker
sudo systemctl start docker
- name: install docker (macos)
if: matrix.os == 'macos-12'
run: |
brew update --preinstall
brew install docker docker-compose qemu
brew upgrade qemu
colima start
docker run --user $(id -u):$(id -g) --rm hello-world
- name: Run integration tests
run: |
set -x
git config --global user.email "github-workflow@github.com"
git config --global user.name "Github Workflow"
library_generation/test/generate_library_integration_test.sh \
--googleapis_gen_url https://cloud-java-bot:${{ secrets.CLOUD_JAVA_BOT_GITHUB_TOKEN }}@github.com/googleapis/googleapis-gen.git
--googleapis_gen_url https://cloud-java-bot:${{ secrets.CLOUD_JAVA_BOT_GITHUB_TOKEN }}@github.com/googleapis/googleapis-gen.git \
--enable_postprocessing "${{ matrix.post_processing }}"
unit_tests:
strategy:
matrix:
Expand Down
68 changes: 65 additions & 3 deletions library_generation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ In order to generate a GAPIC library, you need to pull `google/` from [googleapi
and put it into `output` since protos in `google/` are likely referenced by
protos from which the library are generated.

In order to generate a post-processed GAPIC library, you need to pull the
original repository (i.e. google-cloud-java) and pass the monorepo as
`destination_path` (e.g. `google-cloud-java/java-asset`).
This repository will be the source of truth for pre-existing
pom.xml files, owlbot.py and .OwlBot.yaml files. See the option belows for
custom postprocessed generations (e.g. custom `versions.txt` file).

## Parameters to run `generate_library.sh`

You need to run the script with the following parameters.
Expand All @@ -40,7 +47,7 @@ Use `-d` or `--destination_path` to specify the value.

Note that you do not need to create `$destination_path` beforehand.

The directory structure of the generated library is
The directory structure of the generated library _withtout_ postprocessing is
```
$destination_path
|_gapic-*
Expand All @@ -65,7 +72,35 @@ $destination_path
```
You can't build the library as-is since it does not have `pom.xml` or `build.gradle`.
To use the library, copy the generated files to the corresponding directory
of a library repository, e.g., `google-cloud-java`.
of a library repository, e.g., `google-cloud-java` or use the
`enable_postprocessing` flag on top of a pre-existing generated library to
produce the necessary pom files.

For `asset/v1` the directory structure of the generated library _with_ postprocessing is
```

├── google-cloud-asset
│   └── src
│   ├── main
│   │   ├── java
│   │   └── resources
│   └── test
│   └── java
├── google-cloud-asset-bom
├── grpc-google-cloud-asset-v*
│   └── src
│   └── main
│   └── java
├── proto-google-cloud-asset-v*
│   └── src
│   └── main
│   ├── java
│   └── proto
└── samples
└── snippets
└── generated

```

### gapic_generator_version
You can find the released version of gapic-generator-java in [maven central](https://repo1.maven.org/maven2/com/google/api/gapic-generator-java/).
Expand Down Expand Up @@ -150,8 +185,33 @@ Use `--include_samples` to specify the value.
Choose the protoc binary type from https://github.com/protocolbuffers/protobuf/releases.
Default is "linux-x86_64".

## An example to generate a client library
### enable_postprocessing (optional)
Whether to enable the post-processing steps (usage of owlbot) in the generation
of this library
Default is "true".

### versions_file (optional)
It must point to a versions.txt file containing the versions the post-processed
poms will have. It is required when `enable_postprocessing` is `"true"`


## An example to generate a non post-processed client library
```bash
library_generation/generate_library.sh \
-p google/cloud/confidentialcomputing/v1 \
-d google-cloud-confidentialcomputing-v1-java \
--gapic_generator_version 2.24.0 \
--protobuf_version 23.2 \
--grpc_version 1.55.1 \
--gapic_additional_protos "google/cloud/common_resources.proto google/cloud/location/locations.proto" \
--transport grpc+rest \
--rest_numeric_enums true \
--enable_postprocessing false \
--include_samples true
```

## An example to generate a library with postprocessing
```bash
library_generation/generate_library.sh \
-p google/cloud/confidentialcomputing/v1 \
-d google-cloud-confidentialcomputing-v1-java \
Expand All @@ -161,5 +221,7 @@ library_generation/generate_library.sh \
--gapic_additional_protos "google/cloud/common_resources.proto google/cloud/location/locations.proto" \
--transport grpc+rest \
--rest_numeric_enums true \
--enable_postprocessing true \
--versions_file "path/to/versions.txt" \
--include_samples true
```
59 changes: 53 additions & 6 deletions library_generation/generate_library.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env bash

set -eo pipefail
set -x

# parse input parameters
while [[ $# -gt 0 ]]; do
Expand Down Expand Up @@ -61,10 +60,18 @@ case $key in
include_samples="$2"
shift
;;
--enable_postprocessing)
enable_postprocessing="$2"
shift
;;
--os_architecture)
os_architecture="$2"
shift
;;
--versions_file)
versions_file="$2"
shift
;;
*)
echo "Invalid option: [$1]"
exit 1
Expand All @@ -74,6 +81,7 @@ shift # past argument or value
done

script_dir=$(dirname "$(readlink -f "$0")")
# source utility functions
source "${script_dir}"/utilities.sh
output_folder="$(get_output_folder)"

Expand Down Expand Up @@ -117,17 +125,20 @@ if [ -z "${include_samples}" ]; then
include_samples="true"
fi

if [ -z "$enable_postprocessing" ]; then
enable_postprocessing="true"
fi

if [ -z "${os_architecture}" ]; then
os_architecture=$(detect_os_architecture)
fi


mkdir -p "${output_folder}/${destination_path}"
##################### Section 0 #####################
# prepare tooling
#####################################################
# the order of services entries in gapic_metadata.json is relevant to the
# order of proto file, sort the proto files with respect to their name to
# order of proto file, sort the proto files with respect to their bytes to
# get a fixed order.
folder_name=$(extract_folder_name "${destination_path}")
pushd "${output_folder}"
Expand All @@ -137,7 +148,7 @@ case "${proto_path}" in
find_depth="-maxdepth 1"
;;
esac
proto_files=$(find "${proto_path}" ${find_depth} -type f -name "*.proto" | sort)
proto_files=$(find "${proto_path}" ${find_depth} -type f -name "*.proto" | LC_COLLATE=C sort)
# include or exclude certain protos in grpc plugin and gapic generator java.
case "${proto_path}" in
"google/cloud")
Expand Down Expand Up @@ -280,5 +291,41 @@ popd # output_folder
#####################################################
pushd "${output_folder}/${destination_path}"
rm -rf java_gapic_srcjar java_gapic_srcjar_raw.srcjar.zip java_grpc.jar java_proto.jar temp-codegen.srcjar
popd
set +x
popd # destination path
##################### Section 5 #####################
# post-processing
#####################################################
if [ "${enable_postprocessing}" != "true" ];
then
echo "post processing is disabled"
exit 0
fi
if [ -z "${versions_file}" ];then
echo "no versions.txt argument provided. Please provide one in order to enable post-processing"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's OK to make it required for now since it's only for existing libraries. For new client libraries, I'm assuming we have to generate versions.txt first before calling this script? Is it generated by new client library script currently? cc @JoeWang1127

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@blakeli0 the version of a new library defaults to 0.0.1-SNAPSHOT.

example PR

The new library script applies current versions but this is for other referenced artifacts such as google-cloud-java (example)

I think we still need a versions file for referenced artifacts other than the library being generated when dealing with a new monorepo library

exit 1
fi
workspace="${output_folder}/workspace"
if [ -d "${workspace}" ]; then
rm -rdf "${workspace}"
fi

mkdir -p "${workspace}"

bash -x "${script_dir}/postprocess_library.sh" "${workspace}" \
"${script_dir}" \
"${destination_path}" \
"${proto_path}" \
"${versions_file}" \
"${output_folder}"

# for post-procesed libraries, remove pre-processed folders
pushd "${output_folder}/${destination_path}"
rm -rdf "proto-${folder_name}"
rm -rdf "grpc-${folder_name}"
rm -rdf "gapic-${folder_name}"
if [ "${include_samples}" == "false" ]; then
rm -rdf "samples"
fi
popd # output_folder
# move contents of the post-processed library into destination_path
cp -r ${workspace}/* "${output_folder}/${destination_path}"
101 changes: 101 additions & 0 deletions library_generation/postprocess_library.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#!/bin/bash
#
# Main functions to interact with owlbot post-processor and postprocessing
# scripts


# Runs the owlbot post-processor docker image. The resulting post-processed
# library gets stored in `${output_folder}/workspace`
# Arguments
# 1 - workspace: the location of the grpc,proto and gapic libraries to be
# processed
# 2 - scripts_root: location of the generation scripts
# 3 - destination_path: used to transfer the raw grpc, proto and gapic libraries
# 4 - proto_path: googleapis path of the library. This is used to prepare the
# folder structure to run `owlbot-cli copy-code`
# 5 - versions_file: path to file containing versions to be applied to the poms
# 6 - output_folder: main workspace of the generation process

workspace=$1
scripts_root=$2
destination_path=$3
proto_path=$4
versions_file=$5
output_folder=$6

source "${scripts_root}"/utilities.sh

repository_root=$(echo "${destination_path}" | cut -d/ -f1)
repo_metadata_json_path=$(get_repo_metadata_json "${destination_path}" "${output_folder}")
owlbot_sha=$(get_owlbot_sha "${output_folder}" "${repository_root}")

# read or infer owlbot sha

cp "${repo_metadata_json_path}" "${workspace}"/.repo-metadata.json

# call owl-bot-copy
owlbot_staging_folder="${workspace}/owl-bot-staging"
mkdir -p "${owlbot_staging_folder}"
owlbot_postprocessor_image="gcr.io/cloud-devrel-public-resources/owlbot-java@sha256:${owlbot_sha}"



# copy existing pom, owlbot and version files if the source of truth repo is present
# pre-processed folders are ommited
if [[ -d "${output_folder}/${destination_path}" ]]; then
rsync -avm \
--include='*/' \
--include='*.xml' \
--include='owlbot.py' \
--include='.OwlBot.yaml' \
--exclude='*' \
"${output_folder}/${destination_path}/" \
"${workspace}"
fi

echo 'Running owl-bot-copy'
pre_processed_libs_folder="${output_folder}/pre-processed"
# By default (thanks to generation templates), .OwlBot.yaml `deep-copy` section
# references a wildcard pattern matching a folder
# ending with `-java` at the leaf of proto_path.
mkdir -p "${pre_processed_libs_folder}/${proto_path}/generated-java"
folder_name=$(extract_folder_name "${destination_path}")
copy_directory_if_exists "${output_folder}/${destination_path}/proto-${folder_name}" \
"${pre_processed_libs_folder}/${proto_path}/generated-java/proto-google-cloud-${folder_name}"
copy_directory_if_exists "${output_folder}/${destination_path}/grpc-${folder_name}" \
"${pre_processed_libs_folder}/${proto_path}/generated-java/grpc-google-cloud-${folder_name}"
copy_directory_if_exists "${output_folder}/${destination_path}/gapic-${folder_name}" \
"${pre_processed_libs_folder}/${proto_path}/generated-java/gapic-google-cloud-${folder_name}"
copy_directory_if_exists "${output_folder}/${destination_path}/samples" \
"${pre_processed_libs_folder}/${proto_path}/generated-java/samples"
pushd "${pre_processed_libs_folder}"
# create an empty repository so owl-bot-copy can process this as a repo
# (cannot process non-git-repositories)
git init
git commit --allow-empty -m 'empty commit'
popd # pre_processed_libs_folder

docker run --rm \
--user $(id -u):$(id -g) \
-v "${workspace}:/repo" \
-v "${pre_processed_libs_folder}:/pre-processed-libraries" \
-w /repo \
--env HOME=/tmp \
gcr.io/cloud-devrel-public-resources/owlbot-cli:latest \
copy-code \
--source-repo-commit-hash=none \
--source-repo=/pre-processed-libraries \
--config-file=.OwlBot.yaml


echo 'running owl-bot post-processor'
versions_file_arg=""
if [ -f "${versions_file}" ];then
versions_file_arg="-v ${versions_file}:/versions.txt"
fi
# run the postprocessor
docker run --rm \
-v "${workspace}:/workspace" \
${versions_file_arg} \
--user $(id -u):$(id -g) \
"${owlbot_postprocessor_image}"
Loading
Loading