-
Notifications
You must be signed in to change notification settings - Fork 1.1k
chore: GitHub Actions workflow to generate new client library #10179
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
Changes from 35 commits
e313fee
181f802
aad1040
2e1ef6a
f766b2c
24a8b39
d1fe119
07d1762
a096c7c
b61577e
6a53ab9
10f9068
2da7fbf
8855e9a
9b65c2b
9e286e9
b93107e
c869604
7ea2f64
8222925
7e9162d
03e746d
72cfefa
4299d4b
6611ec1
4d2cebb
4c57f8f
538b16d
4bb1dda
473c27c
f3fa637
9319d8b
63607c4
1d22d73
5830b21
63bf9e6
f4e8d71
741e7bd
ce0a744
c3ca1d2
a9dcd70
ac16f1d
5d0e9c3
b975972
2fb8246
097a778
26162d0
9ef6e56
f255a2b
99857c0
7beb584
13dfea1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| name: Generate new GAPIC client library | ||
| 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" | ||
| transport: | ||
| required: false | ||
| type: choice | ||
| default: grpc | ||
| options: | ||
| - grpc | ||
| - http | ||
| - both | ||
| description: "`transport`: A label that appears in repo-metadata.json" | ||
| destination_name: | ||
| required: false | ||
| type: string | ||
| description: | | ||
| `destination_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: Get current week within the year | ||
| id: date | ||
| run: echo "::set-output name=week_of_year::$(date +'%W' --utc)" | ||
| - name: Install new-client.py dependencies | ||
| run: pip install --require-hashes -r generation/new_client/requirements.txt | ||
| - name: Generate | ||
| id: 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=('transport' 'destination-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} --googleapis-gen-url=\"${GOOGLEAPIS_GEN_URL}\"" | xargs python generation/new_client/new-client.py generate | ||
| env: | ||
| GOOGLEAPIS_GEN_URL: https://yoshi-approver:${{ secrets.YOSHI_CODE_BOT_TOKEN }}@github.com/googleapis/googleapis-gen.git | ||
| 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 }} | ||
| TRANSPORT: ${{ github.event.inputs.transport }} | ||
| DESTINATION_NAME: ${{ github.event.inputs.destination_name }} | ||
| DISTRIBUTION_NAME: ${{ github.event.inputs.distribution_name }} | ||
| - name: Push to branch and create PR | ||
| run: | | ||
| set -x | ||
| [ -z "`git config user.email`" ] && git config --global user.email "${USERNAME:-script}@google.com" | ||
| [ -z "`git config user.name`" ] && git config --global user.name "${USERNAME:-script}" | ||
|
|
||
| # 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 | ||
| git commit -m "feat: [${API_SHORTNAME}] new module for ${API_SHORTNAME} | ||
|
|
||
|
|
||
| Generated with https://github.com/googleapis/google-cloud-java/actions/workflows/generate_new_client.yaml | ||
|
|
||
| Command used: | ||
|
|
||
| \`\`\` | ||
| python generation/new_client/new-client.py generate ${GENERATION_ARGUMENTS} | ||
| \`\`\`" | ||
| git remote add monorepo https://${{ github.actor }}:${{ github.token }}@github.com/${{ github.repository }}.git | ||
| git fetch -q --unshallow monorepo | ||
| git push -f monorepo "${branch_name}" | ||
|
|
||
| # create PR | ||
| gh pr create --fill --head "${branch_name}" | ||
| env: | ||
| USERNAME: ${{ github.actor }} | ||
| API_SHORTNAME: ${{ github.event.inputs.api_shortname }} | ||
| GENERATION_ARGUMENTS: ${{ steps.generation.outputs.new_library_args }} | ||
| GH_TOKEN: ${{ secrets.YOSHI_CODE_BOT_TOKEN }} | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,12 +5,37 @@ google-cloud-java monorepo. | |
|
|
||
| **This tool is for repository maintainers only. Not for library users.** | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| This section is only needed for the first run of this script. If it's already | ||
| ## Run via github action | ||
|
|
||
| You can save the time to setup the environment by calling the | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This reads as if this is a good option for the reader. Would you rewrite this is the way for the reader to follow? In other words, don't give the reader a task of determining whether they should use GitHub Actions or new-client.py script. |
||
| [`generate_new_client.yaml` github action](https://github.com/googleapis/google-cloud-java/actions/workflows/generate_new_client.yaml) directly. You can jump to | ||
| [this section](https://github.com/googleapis/google-cloud-java/blob/main/generation/new_client/README.md#run-client-generation-script) | ||
| to find workflow arguments. | ||
|
|
||
| > ![IMPORTANT] | ||
| > Not all the `new-client.py` arguments are available in the Github Action. | ||
| > Please refer to | ||
| > [this | ||
| > section](https://github.com/googleapis/google-cloud-java/blob/main/generation/new_client/README.md#advanced-options) | ||
| > for more arguments (it requires to setup a local environment). | ||
| > The arguments currently supported by the workflow are: | ||
| > - [API short Name (`api_shortname`)](https://github.com/googleapis/google-cloud-java/blob/main/generation/new_client/README.md#api-short-name) | ||
| > - [Proto path (`proto_path`)](https://github.com/googleapis/google-cloud-java/blob/main/generation/new_client/README.md#proto-path) | ||
| > - [Name pretty (`name_pretty`)](https://github.com/googleapis/google-cloud-java/blob/main/generation/new_client/README.md#name-pretty) | ||
| > - [Product Docs (`product_docs`)](https://github.com/googleapis/google-cloud-java/blob/main/generation/new_client/README.md#product-docs) | ||
| > - [REST Docs (`rest_docs`)](https://github.com/googleapis/google-cloud-java/blob/main/generation/new_client/README.md#rest-docs) | ||
| > - [RPC Docs (`rpc_docs`)](https://github.com/googleapis/google-cloud-java/blob/main/generation/new_client/README.md#rpc-docs) | ||
| > - [API description (`api_description`)](https://github.com/googleapis/google-cloud-java/blob/main/generation/new_client/README.md#api-description) | ||
| > - [`transport`](https://github.com/googleapis/google-cloud-java/blob/main/generation/new_client/README.md#advanced-options) | ||
| > - [`destination_name`](https://github.com/googleapis/google-cloud-java/blob/main/generation/new_client/README.md#advanced-options) | ||
| > - [`distribution_name`](https://github.com/googleapis/google-cloud-java/blob/main/generation/new_client/README.md#advanced-options) | ||
|
|
||
|
|
||
| ## Prerequisites (for local environment) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you bring environment setup to the bottom? It's now not that important.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'Ensure no Release Please "snapshot" pull request open', which is not environment setup, is still valid. |
||
|
|
||
| This section is only needed for the first _local_ run of this script. If it's already | ||
| done, go to "Run client generation script" section. | ||
|
|
||
|
|
||
| ### Environment | ||
|
|
||
| Use Linux environment. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also add a line that says this pull request was created via this workflow?
https://github.com/googleapis/google-cloud-java/actions/workflows/generate_new_client.yaml
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added. This is the example: diegomarquezp#11
I'm adding the example to the PR description