Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
8cf7df0
chore: add new-client for hermetic build
diegomarquezp Mar 5, 2024
74a3873
enable yaml insertion
diegomarquezp Mar 6, 2024
94119ae
normalize yaml format
diegomarquezp Mar 6, 2024
7b19853
add requirements file
diegomarquezp Mar 6, 2024
b8787c5
add gh action
diegomarquezp Mar 6, 2024
1bfd884
add pull_request event for testing
diegomarquezp Mar 6, 2024
d13364e
add requirements.txt
diegomarquezp Mar 6, 2024
affb741
use requirements with hashes
diegomarquezp Mar 6, 2024
72d54dc
add requirement hashes
diegomarquezp Mar 6, 2024
6483d7c
fix requirements.in
diegomarquezp Mar 6, 2024
309e4e0
remove testing event
diegomarquezp Mar 6, 2024
e62f1e6
fix requirement hashes
diegomarquezp Mar 6, 2024
6a5172d
fix generation script call
diegomarquezp Mar 6, 2024
ca356c1
remove usage of googleapis-gen-url
diegomarquezp Mar 6, 2024
db13151
fix gapic entry generation
diegomarquezp Mar 6, 2024
1a32e29
add debug print statement
diegomarquezp Mar 6, 2024
9f8e6f1
remove mistakenly added chat library
diegomarquezp Mar 6, 2024
46620a3
suppress debug output
diegomarquezp Mar 6, 2024
124b4fd
fix pr message, fix pr label
diegomarquezp Mar 7, 2024
c0a1b54
fix pr description message
diegomarquezp Mar 7, 2024
c7429c0
improve pr descriptoin
diegomarquezp Mar 7, 2024
142fc18
fix comment
diegomarquezp Mar 7, 2024
aef76f2
add readme
diegomarquezp Mar 7, 2024
eeabd19
add advanced options
diegomarquezp Mar 7, 2024
5ef7f96
fix syntax
diegomarquezp Mar 7, 2024
918875a
clarify type of workflow
diegomarquezp Mar 7, 2024
f71f2b4
fix advanced options
diegomarquezp Mar 7, 2024
78fda36
checkout latest fix in main branch
diegomarquezp Mar 7, 2024
330f888
Merge remote-tracking branch 'origin/main' into new-library-hermetic-…
diegomarquezp Mar 7, 2024
b964c4a
remove transport form workflow options
diegomarquezp Mar 7, 2024
910e026
change destination_name to library_name, remove cloud_api
diegomarquezp Mar 7, 2024
fedd456
remove library existence check
diegomarquezp Mar 7, 2024
d4a4909
change product_docs to product_documentation
diegomarquezp Mar 7, 2024
d623ed5
Revert "change product_docs to product_documentation"
diegomarquezp Mar 7, 2024
26e4e32
add api_reference
diegomarquezp Mar 7, 2024
df167fb
add codeowner_team
diegomarquezp Mar 7, 2024
94fa787
add excluded_dependencies
diegomarquezp Mar 7, 2024
4417f44
add excluded_poms
diegomarquezp Mar 7, 2024
1eb08df
add googleapis_commitish
diegomarquezp Mar 7, 2024
f10fbd6
add mutually exclusive logic for group_id and distribution_name
diegomarquezp Mar 7, 2024
8f489ab
add issue_tracker
diegomarquezp Mar 7, 2024
da92cf1
add extra_versioned_modules
diegomarquezp Mar 7, 2024
81d9274
remove untracked file
diegomarquezp Mar 7, 2024
9afaf9f
improve logic for inferring yaml variables
diegomarquezp Mar 7, 2024
03908a7
remove debug file
diegomarquezp Mar 8, 2024
28da276
compute all proto_path verions
diegomarquezp Mar 8, 2024
ce4125a
update googleapis_commitish for testing
diegomarquezp Mar 8, 2024
66872b3
add cleanup of googleapis folder
diegomarquezp Mar 8, 2024
12f7f95
add xtrace
diegomarquezp Mar 8, 2024
9675bab
update dependencies
diegomarquezp Mar 8, 2024
c4f426d
update dependencies ii
diegomarquezp Mar 8, 2024
6e326f5
remove owlbot label
diegomarquezp Mar 11, 2024
b544a21
add owlbot run label
diegomarquezp Mar 11, 2024
b0bfbe6
fix library_name
diegomarquezp Mar 11, 2024
b92c8d7
Merge remote-tracking branch 'origin/main' into new-library-hermetic-…
diegomarquezp Mar 11, 2024
e49c09d
remove cloudcontrolspartner
diegomarquezp Mar 11, 2024
17ea441
Merge branch 'new-library-hermetic-build' into diego-main
diegomarquezp Mar 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .github/workflows/generate_new_client.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ jobs:
\`\`\`
python generation/new_client/new-client.py generate ${GENERATION_ARGUMENTS}
\`\`\`"
gh pr create --title "${commit_message}" --label "owlbot:run" --head "${branch_name}" --body "${pr_body}"
gh pr create --title "${commit_message}" --head "${branch_name}" --body "${pr_body}"
env:
USERNAME: ${{ github.actor }}
API_SHORTNAME: ${{ github.event.inputs.api_shortname }}
Expand Down
178 changes: 178 additions & 0 deletions .github/workflows/generate_new_client_hermetic_build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
name: Generate new GAPIC client library (Hermetic Build)
on:
workflow_dispatch:
# some inputs are ommited due to limit of 10 input arguments
inputs:
api_shortname:
required: true
type: string
description: "`api_shortname`: Name for the new directory name and (default) artifact name"
name_pretty:
required: true
type: string
description: "`name_pretty`: The human-friendly name that appears in README.md"
proto_path:
required: true
type: string
description: |
`proto_path`: Path to proto file from the root of the googleapis repository to the
directory that contains the proto files (without the version).
For example, to generate the library for 'google/maps/routing/v2',
then you specify this value as 'google/maps/routing'
product_docs:
required: true
type: string
description: "`product_docs`: Documentation URL that appears in README.md"
rest_docs:
required: false
type: string
description: |
`rest_docs`: If it exists, link to the REST Documentation for a service
rpc_docs:
required: false
type: string
description: |
`rpc_docs`: If it exists, link to the RPC Documentation for a service
api_description:
required: true
description: "`api_description`: Description that appears in README.md"
library_name:
required: false
type: string
description: |
`library_name`: The directory name of the new library. By default it's
java-<api_shortname>
distribution_name:
required: false
type: string
description: |
`distribution_name`: Maven coordinates of the generated library. By default it's
com.google.cloud:google-cloud-<api_shortname>

jobs:
generate:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.9'
cache: 'pip' # caching pip dependencies
- name: Install new-client.py dependencies
run: pip install --require-hashes -r generation/new_client_hermetic_build/requirements.txt
- name: Add entry to generation_config.yaml
id: config_generation
run: |
set -x
arguments="--api_shortname=\"${API_SHORTNAME}\" \
--proto-path=\"${PROTO_PATH}\" \
--name-pretty=\"${NAME_PRETTY}\" \
--product-docs=\"${PRODUCT_DOCS}\" \
--api-description=\"${API_DESCRIPTION}\""

# helper function that appends a python argument only if specified in the GH action inputs
append_argument() {
py_arg=$1
# env vars look exactly like new-client arguments but uppercase + underscores
env_name=$(echo "${py_arg}" | sed 's/-/_/g' | sed -e 's/\([a-z]\)/\U\1/g')
if [[ -n "${!env_name}" ]]; then
# $(echo) is redundant but it works around a syntax highlighting problem in vim
arguments=$(echo "${arguments} --${py_arg}=\"${!env_name}\"")
fi
}

declare -a optional_args=('library-name' 'distribution-name' 'group-id' 'rest-docs' 'rpc-docs')

for python_argument in "${optional_args[@]}"; do
append_argument "${python_argument}"
done
echo "::set-output name=new_library_args::${arguments}"
echo "${arguments}" \
| xargs python generation/new_client_hermetic_build/new-client.py add-new-library
env:
API_SHORTNAME: ${{ github.event.inputs.api_shortname }}
NAME_PRETTY: ${{ github.event.inputs.name_pretty }}
PROTO_PATH: ${{ github.event.inputs.proto_path }}
PRODUCT_DOCS: ${{ github.event.inputs.product_docs }}
REST_DOCS: ${{ github.event.inputs.rest_docs }}
RPC_DOCS: ${{ github.event.inputs.rpc_docs }}
API_DESCRIPTION: ${{ github.event.inputs.api_description }}
LIBRARY_NAME: ${{ github.event.inputs.library_name }}
DISTRIBUTION_NAME: ${{ github.event.inputs.distribution_name }}
- name: setup docker environment
shell: bash
run: |
set -x
# we create a volume pointing to `pwd` (google-cloud-java) that will
# be referenced by the container and its children
if [[ $(docker volume inspect repo-google-cloud-java) != '[]' ]]; then
docker volume rm repo-google-cloud-java
fi
docker volume create --name "repo-google-cloud-java" --opt "type=none" --opt "device=$(pwd)" --opt "o=bind"
- name: generate from configuration
id: generation
shell: bash
run: |
set -x
repo_volumes="-v repo-google-cloud-java:/workspace/google-cloud-java"
echo "::set-output name=repo_volumes::${repo_volumes}"
docker run --rm \
${repo_volumes} \
-v /tmp:/tmp \
-v /var/run/docker.sock:/var/run/docker.sock \
-e "RUNNING_IN_DOCKER=true" \
-e "REPO_BINDING_VOLUMES=${repo_volumes}" \
gcr.io/cloud-devrel-public-resources/java-library-generation:latest \
python /src/generate_repo.py generate \
--generation-config-yaml=/workspace/google-cloud-java/generation_config.yaml \
--repository-path=/workspace/google-cloud-java \
--target-library-api-shortname=${API_SHORTNAME}
env:
API_SHORTNAME: ${{ github.event.inputs.api_shortname }}
- name: Push to branch and create PR
run: |
set -x
[ -z "`git config user.email`" ] && git config --global user.email "cloud-java-bot@google.com"
[ -z "`git config user.name`" ] && git config --global user.name "cloud-java-bot"

# create and push to branch in origin
# random_id allows multiple runs of this workflow
random_id=$(tr -dc A-Za-z0-9 </dev/urandom | head -c 5; echo)
branch_name="new-library/${{ github.event.inputs.api_shortname }}-${random_id}"
git checkout -b "${branch_name}"
git add --all
commit_message="feat: [${API_SHORTNAME}] new module for ${API_SHORTNAME}"
git commit -m "${commit_message}"
git remote add monorepo https://cloud-java-bot:${GH_TOKEN}@github.com/${{ github.repository }}.git
git fetch -q --unshallow monorepo
git push -f monorepo "${branch_name}"

# create PR
pr_body="Generated by @${USERNAME} via [generate_new_client_hermetic_build.yaml](https://github.com/googleapis/google-cloud-java/actions/workflows/generate_new_client_hermetic_build.yaml)

Command used:

\`\`\`
python generation/new_client_hermetic_build/new-client.py add-new-client ${GENERATION_ARGUMENTS}

docker run --rm \\
${DOCKER_VOLUMES} \\
-v /tmp:/tmp \\
-v /var/run/docker.sock:/var/run/docker.sock \\
-e \"RUNNING_IN_DOCKER=true\" \\
-e \"REPO_BINDING_VOLUMES=${DOCKER_VOLUMES}\" \\
gcr.io/cloud-devrel-public-resources/java-library-generation:latest \\
python /src/generate_repo.py generate \\
--generation-config-yaml=/workspace/google-cloud-java/generation_config.yaml \\
--repository-path=/workspace/google-cloud-java \\
--target-library-api-shortname=${API_SHORTNAME}

\`\`\`"
gh pr create --title "${commit_message}" --label "owlbot:run" --head "${branch_name}" --body "${pr_body}"
env:
USERNAME: ${{ github.actor }}
API_SHORTNAME: ${{ github.event.inputs.api_shortname }}
GENERATION_ARGUMENTS: ${{ steps.config_generation.outputs.new_library_args }}
DOCKER_VOLUMES: ${{ steps.generation.outputs.repo_volumes }}
GH_TOKEN: ${{ secrets.CLOUD_JAVA_BOT_TOKEN }}

1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
* [alloydb] support for obtaining the public IP address of an Instance ([#10439](https://github.com/googleapis/google-cloud-java/issues/10439)) ([06497ad](https://github.com/googleapis/google-cloud-java/commit/06497ada58a21579cc87665289d56ee99e19fd87))
* [apphub] new module for apphub ([#10476](https://github.com/googleapis/google-cloud-java/issues/10476)) ([9dab014](https://github.com/googleapis/google-cloud-java/commit/9dab01499649efd9e4314d56dd90688994faae26))
* [chat] new module for chat ([#10485](https://github.com/googleapis/google-cloud-java/issues/10485)) ([5252f16](https://github.com/googleapis/google-cloud-java/commit/5252f16a3e0130a6d1068775ae4ff5b522ed12fa))
* [cloudcontrolspartner] new module for cloudcontrolspartner ([#10473](https://github.com/googleapis/google-cloud-java/issues/10473)) ([ae92301](https://github.com/googleapis/google-cloud-java/commit/ae923015f4ea2d9c235084aaca60d7e4d70902f7))
* [cloudprofiler] add `start_time` to Profile proto ([#10434](https://github.com/googleapis/google-cloud-java/issues/10434)) ([c04c4f6](https://github.com/googleapis/google-cloud-java/commit/c04c4f676d291e63360236d79afebf4f437e3d17))
* [compute] Update Compute Engine API to revision 20240220 ([#886](https://github.com/googleapis/google-cloud-java/issues/886)) ([c87fa39](https://github.com/googleapis/google-cloud-java/commit/c87fa396003135a14dfded22d201b83b63d2edc2))
* [container] add API to enable Provisioning Request API on existing nodepools ([7d0f1cc](https://github.com/googleapis/google-cloud-java/commit/7d0f1cc61f2ba6b3f3e9f4b7b22c8397a570b1d9))
Expand Down
7 changes: 0 additions & 7 deletions gapic-libraries-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -315,13 +315,6 @@
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-cloudcontrolspartner-bom</artifactId>
<version>0.2.0-SNAPSHOT</version><!-- {x-version-update:google-cloud-cloudcontrolspartner:current} -->
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-cloudquotas-bom</artifactId>
Expand Down
160 changes: 160 additions & 0 deletions generation/new_client_hermetic_build/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
# New client generation (GitHub Action)
This new generation workflow enables generation of new libraries by
- appending a new library to our [generation_config.yaml](https://github.com/googleapis/google-cloud-java/blob/c7429c0eec419c01d4e2fe14d063b9335efb810b/generation_config.yaml).
- running the hermetic build scripts docker image and
generate the newly added library.
- create a PR with the changes.


## Components
### `new_library_hermetic_build/new-client.py`
This script takes 10 arguments that map to items in the newly added library that
goes in `generation_config.yaml`. A new entry will be added to `libraries` with
the necessary generation configuration.

### `.github/workflows/generate_new_client_hermetic_build.yaml`
This workflow orchestrates the `new-client.py` script and also uses our docker
image
([gcr.io/cloud-devrel-public-resources/java-library-generation](https://pantheon.corp.google.com/gcr/images/cloud-devrel-public-resources/global/java-library-generation))
to generate a new library. It also creates the pull request.


## Execute the Github Action

You in order to run the
[Github Action](https://github.com/googleapis/google-cloud-java/actions/workflows/generate_new_client_hermetic_build.yaml)
, you need to specify a few parameters.
These parameters will be available in the Cloud Drop link (a YAML file) included in the buganizer request.
The example in this README uses AlloyDB's [Cloud Drop](https://github.com/googleapis/googleapis/blob/master/google/cloud/alloydb/v1/alloydb_v1.yaml) file as an example.

### API short name (`api_shortname`)

For convenience of the subsequent commands, define a variable for API short name.
This value will be used by default to generate the following:
* `--distribution-name`
* `--destination-name`

The corresponding value in the Cloud Drop page is `api_short_name`.

Example: `alloydb`

> [!IMPORTANT]
> `api_short_name` is not always unique across client libraries.
> In the instance that the `api_short_name` is already in use by an existing client library, you will need to determine a unique name.
> See example under [Advanced Options](#Example with duplicate api_short_name).

### Proto path (`proto_path`)

The script takes "proto path" parameter. This is the path from the internal `google3/third_party/googleapis/stable` root to the
directory that contains versions (e.g., "v1" or "v2").
Note that the internal `google3/third_party/googleapis/stable` directory is mirrored externally in https://github.com/googleapis/googleapis/blob/master/.

For example, if the buganizer ticket includes:

> Link to protos: `http://...(omit).../google/cloud/alloydb/v1alpha/alloydb_v1alpha.yaml`.

then the corresponding external mirrored proto is here: https://github.com/googleapis/googleapis/blob/master/google/cloud/alloydb/v1alpha/alloydb_v1alpha.yaml.

Therefore, the "proto path" value we supply to the command is `google/cloud/alloydb`.

We will publish a single module for a service that includes all versions in this path. Once the service has been published once, any future additional versions will automatically be generated via OwlBot.

### Name pretty (`name_pretty`)

The corresponding value in the Cloud Drop page is `title`.

Example: `AlloyDB API`

### Product Docs (`product_docs`)

The corresponding value in the Cloud Drop page is `documentation_uri`.
The value must starts with "https://".

Example: `https://cloud.google.com/alloydb/docs`

### REST Docs (`rest_docs`)

The corresponding value in the Cloud Drop page is `rest_reference_documentation_uri`.
The value must starts with "https://".

Example: `https://cloud.google.com/alloydb/docs/reference/rest`

If they exist, add them as a flag to the python command below like:
`--rest-docs="https://cloud.google.com/alloydb/docs/reference/rest" \`

### RPC Docs (`rpc_docs`)

The corresponding value in the Cloud Drop page is `proto_reference_documentation_uri`.
The value must starts with "https://".

Example: `https://cloud.google.com/speech-to-text/docs/reference/rpc`

If they exist, add them as a flag to the python command below like:
`--rpc-docs="https://cloud.google.com/speech-to-text/docs/reference/rpc" \`

### API description (`api_description`)

The corresponding value in the Cloud Drop page is `documentation.summary` or `documentation.overview`.
If both of those fields are missing, take the description from the product page above. Use the first sentence to keep it concise.

Example:
```
AlloyDB for PostgreSQL is an open source-compatible database service that
provides a powerful option for migrating, modernizing, or building
commercial-grade applications.
```

### Transport (`transport`)

This variable represents the type of requests the library will make to
its corresponding service. It can be `grpc` (default), `http` or `both`. In
practice, it is mainly used to create a `.repo-metadata.json` file.

### Destination Name (`destination_name`)

This variable represents the folder name to be created in the root of the
monorepo. For example, if it is `java-example-library`, then a new folder
with the generated library will be created in
`google-cloud-java/java-example/library`.

### Distribution Name (`distribution_name`)

This variable determines the Maven coordinates of the generated library. It
defaults to `com.google.cloud:google-cloud-{api_shortname}`. This mainly affect
the values in the generated `pom.xml` files.

## Advanced Options

In case the steps above don't show you how to specify the desired options, you can
run the `new-client.py` script in your local evironment. The advanced options
not shown in the section above **cannot be specified in the Github Action**,
hence the need for a local run (refer to the "Prerequisites
(for local environment)" section).
For the explanation of the available parameters, run:
`python3.9 generation/new_client_hermetic_build/new-client.py generate --help`.

After you run the script, you will see that the `generation_config.yaml` file
was modified (or the script exited because the library already existed)

The last step you need is to `cd` into the root of `google-cloud-java` and run
```
docker volume create --name "repo-google-cloud-java" --opt "type=none" --opt "device=$(pwd)" --opt "o=bind"
repo_volumes="-v repo-google-cloud-java:/workspace/google-cloud-java"
docker run --rm \
${repo_volumes} \
-v /tmp:/tmp \
-v /var/run/docker.sock:/var/run/docker.sock \
-e "RUNNING_IN_DOCKER=true" \
-e "REPO_BINDING_VOLUMES=${repo_volumes}" \
gcr.io/cloud-devrel-public-resources/java-library-generation:latest \
python /src/generate_repo.py generate \
--generation-config-yaml=/workspace/google-cloud-java/generation_config.yaml \
--repository-path=/workspace/google-cloud-java \
--target-library-api-shortname=<your api_shortname>

```

This docker container will run the generation scripts and generate the library
in your repo. You can create a PR explaining what commands you used (the docker
command is not as informative as the `new-client.py` call, so make sure at least
the new-client arguments were listed.
Loading