forked from googleapis/google-cloud-java
-
Notifications
You must be signed in to change notification settings - Fork 0
143 lines (135 loc) · 6.08 KB
/
generate_new_client.yaml
File metadata and controls
143 lines (135 loc) · 6.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
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-'
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
- 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}\""
# 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} --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 }}
CLOUD_API: ${{ github.event.inputs.CLOUD_API }}
GROUP_ID: ${{ github.event.inputs.group_id }}
- 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
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_SHORTNAME}
\`\`\`
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 }}