-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
52 commits
Select commit
Hold shift + click to select a range
e313fee
feat: new client workflow
diegomarquezp 181f802
define inputs to workflow
diegomarquezp aad1040
initial new library script
diegomarquezp 2e1ef6a
improve input description
diegomarquezp f766b2c
test correct backtick syntax
diegomarquezp 24a8b39
enclose backtick containing descriptions in double quotes
diegomarquezp d1fe119
remove "less necessary" inputs
diegomarquezp 07d1762
default values for non-string inputs
diegomarquezp a096c7c
fix ubuntu version, remove java install
diegomarquezp b61577e
fix xargs and arguments
diegomarquezp 6a53ab9
fix input-to-env list
diegomarquezp 10f9068
correct underscores in input to new-client
diegomarquezp 2da7fbf
add PR creation
diegomarquezp 8855e9a
fix id typo
diegomarquezp 9b65c2b
add gh token to pr creation step
diegomarquezp 9e286e9
use YOSHI_CODE_BOT_TOKEN
diegomarquezp b93107e
use distribution_name instead of group_id
diegomarquezp c869604
use debug output
diegomarquezp 7ea2f64
remove wrong push option
diegomarquezp 8222925
sanitize token commit message
diegomarquezp 7e9162d
specify branch in gh pr create
diegomarquezp 03e746d
escape newlines for pr message
diegomarquezp 72cfefa
try different newline approach
diegomarquezp 4299d4b
improve pr description
diegomarquezp 6611ec1
correct username to author the commits
diegomarquezp 4d2cebb
use destination_name argument instead of cloud_api
diegomarquezp 4c57f8f
prepare `destination-name` argument
diegomarquezp 538b16d
correct env var setup
diegomarquezp 4bb1dda
randomize branch name
diegomarquezp 473c27c
correct random_id syntax
diegomarquezp f3fa637
add distribution-name to arguments
diegomarquezp 9319d8b
remove dummy message step
diegomarquezp 63607c4
include workflow location in commit message
diegomarquezp 1d22d73
use url for workflow link
diegomarquezp 5830b21
update new-client README
diegomarquezp 63bf9e6
move local prerequisites to bottom
diegomarquezp f4e8d71
explain advanced options not called in gh action
diegomarquezp 741e7bd
clarify advanced options note
diegomarquezp ce0a744
simplify readme local links
diegomarquezp c3ca1d2
use alternative warning format
diegomarquezp a9dcd70
move local example to the bottom
diegomarquezp ac16f1d
add links to gh action
diegomarquezp 5d0e9c3
highlight advanced options note with warning
diegomarquezp b975972
add explanation on finding the generated PR
diegomarquezp 2fb8246
correct terminology/capitalization
diegomarquezp 097a778
improve top-to-bottom readability
diegomarquezp 26162d0
fix "option" bias in doc
diegomarquezp 9ef6e56
remove links for arguments
diegomarquezp f255a2b
punctuation
diegomarquezp 99857c0
remove redundant advanced options explanation
diegomarquezp 7beb584
restore principles section
diegomarquezp 13dfea1
Merge branch 'main' into main
diegomarquezp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 }} | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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