-
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 14 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,137 @@ | ||
| 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" | ||
| cloud_api: | ||
| required: false | ||
| default: true | ||
| type: boolean | ||
| description: | | ||
| `cloud_api`: If true, the artifact ID of the library is 'google-cloud-' | ||
| otherwise 'google-' | ||
| group_id: | ||
| required: false | ||
| type: string | ||
| description: | | ||
| `group_id`: The group ID of the artifact when distribution name is not set | ||
|
|
||
| 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 | ||
| - run: echo 'a message' | ||
| - 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}\" \ | ||
| --googleapis-gen-url=\"${GOOGLEAPIS_GEN_URL}\"" | ||
|
|
||
| # 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' 'cloud-api' '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/new-client.py generate | ||
| env: | ||
| GOOGLEAPIS_GEN_URL: https://yoshi-approver:${{ secrets.YOSHI_APPROVER_PRIVATE_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 }} | ||
| CLOUD_API: ${{ github.event.inputs.CLOUD_API }} | ||
| GROUP_ID: ${{ github.event.inputs.group_id }} | ||
| - name: Push to branch | ||
| run: | | ||
| [ -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 | ||
| branch_name="new-library/${{ github.event.inputs.api_shortname }}" | ||
| git checkout -b "${branch_name}" | ||
| git add --all | ||
| git commit -m "feat: [${API_SHORTNAME}] new module for ${API_SHORT_NAME}\n\n\ | ||
| \`\`\`${GENERATION_ARGUMENTS}\`\`\`" | ||
|
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. (Just in case you're doing this) Avoid experimenting the git command in this pull request because it's time-consuming. You have to wait minutes to see the results. Try these git and gh commands locally before editing this pull request.
Contributor
Author
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 is good advice, thanks. I wrongly assumed my attempts will succeed the first time. |
||
| 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 | ||
| env: | ||
| API_SHORTNAME: ${{ github.event.inputs.api_shortname }} | ||
| GENERATION_ARGUMENTS: ${{ steps.generation.outputs.new_library_args }} | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.