Sitelet https://github.com/MultiSlacker/google-cloud-java/commit/7a0fa4dd1294de9cbfc5d0a318ef26aedab9f624
Skip to content

Commit 7a0fa4d

Browse files
authored
chore: add test for new client generation (googleapis#8670)
1 parent beefe83 commit 7a0fa4d

3 files changed

Lines changed: 84 additions & 6 deletions

File tree

‎.github/workflows/newclient.yaml‎

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: New Client
2+
on:
3+
schedule:
4+
- cron: '0 2 * * *' # nightly at 2 am UTC
5+
push:
6+
branches: [ main ]
7+
paths:
8+
- generation/**
9+
pull_request:
10+
branches: [ main ]
11+
paths:
12+
- generation/**
13+
14+
workflow_dispatch:
15+
16+
jobs:
17+
generate:
18+
runs-on: ubuntu-latest
19+
env:
20+
API_SHORT_NAME: apikeys
21+
API_PRETTY_NAME: API Keys
22+
steps:
23+
- uses: actions/checkout@v3
24+
- uses: actions/setup-python@v4
25+
with:
26+
python-version: '3.9'
27+
cache: 'pip' # caching pip dependencies
28+
- name: Get current date
29+
id: date
30+
run: echo "::set-output name=date::$(date +'%Y-%m-%d' --utc)"
31+
- uses: actions/setup-java@v3
32+
with:
33+
distribution: zulu
34+
java-version: 11
35+
- run: java -version
36+
- uses: actions/cache@v3
37+
id: mvn-cache
38+
with:
39+
path: ~/.m2/repository
40+
key: ${{ runner.os }}-maven-unified-${{ steps.date.outputs.date }}
41+
- name: Install dependencies
42+
run: pip install -r generation/new_client/requirements.txt
43+
- name: Remove Client
44+
run: |
45+
rm -rf java-${API_SHORT_NAME} || true
46+
sed -i "/${API_SHORT_NAME}/d" pom.xml
47+
sed -i "/${API_SHORT_NAME}/d" gapic-libraries-bom/pom.xml
48+
- name: Verify Client Removal
49+
run: |
50+
! test -d java-${API_SHORT_NAME}
51+
! grep -q ${API_SHORT_NAME} pom.xml
52+
! grep -q ${API_SHORT_NAME} gapic-libraries-bom/pom.xml
53+
- name: Generate
54+
run: |
55+
python generation/new_client/new-client.py generate \
56+
--api_shortname=${API_SHORT_NAME} \
57+
--proto-path=google/api/${API_SHORT_NAME} \
58+
--name-pretty="${API_PRETTY_NAME}" \
59+
--product-docs="https://github.com/googleapis/google-cloud-java/tree/main/java-${API_SHORT_NAME}" \
60+
--api-description="${API_PRETTY_NAME} Client lets you use ${API_PRETTY_NAME} API." \
61+
--googleapis-gen-url=https://yoshi-approver:${{ secrets.YOSHI_APPROVER_PRIVATE_TOKEN }}@github.com/googleapis/googleapis-gen.git
62+
- name: Push to branch
63+
run: |
64+
[ -z "`git config user.email`" ] && git config --global user.email "${USERNAME:-script}@google.com"
65+
[ -z "`git config user.name`" ] && git config --global user.name "${USERNAME:-script}"
66+
git checkout -b newclient_output_${{ github.event_name }}
67+
git add --all
68+
git commit -m 'feat: re-generated ${API_SHORT_NAME}'
69+
git remote add monorepo https://${{ github.actor }}:${{ github.token }}@github.com/${{ github.repository }}.git
70+
git fetch -q --unshallow monorepo
71+
git push -f monorepo newclient_output_${{ github.event_name }}
72+
- name: Verify Client Creation
73+
run: |
74+
test -d java-${API_SHORT_NAME}
75+
grep -q ${API_SHORT_NAME} pom.xml
76+
grep -q ${API_SHORT_NAME} gapic-libraries-bom/pom.xml
77+
- name: Test
78+
run: mvn test -T C1 -B

‎generation/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ See: [bootstrap_output](https://github.com/googleapis/google-cloud-java/tree/boo
2828
### Diffs
2929

3030
The workflow also generates a diff between the current `main` branch and the generated aggregation of modules from split repos.
31-
See: `boostrap_outout_diff_{event}` branches.
31+
See: `boostrap_outout_diff_{event}` branches.

‎generation/new_client/new-client.py‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ def main(ctx):
6868
"--owlbot-image", type=str, default="gcr.io/cloud-devrel-public-resources/owlbot-java"
6969
)
7070
@click.option("--library-type", type=str)
71+
@click.option("--googleapis-gen-url", type=str, default="https://github.com/googleapis/googleapis-gen.git")
7172
def generate(
7273
api_shortname,
7374
name_pretty,
@@ -85,6 +86,7 @@ def generate(
8586
group_id,
8687
owlbot_image,
8788
library_type,
89+
googleapis_gen_url,
8890
):
8991
cloud_prefix = "cloud-" if cloud_api else ""
9092

@@ -160,7 +162,7 @@ def generate(
160162
)
161163

162164
# get the sha256 digets for the owlbot image
163-
subprocess.check_call(["docker", "pull", owlbot_image])
165+
subprocess.check_call(["docker", "pull", "-q", owlbot_image])
164166
owlbot_image_digest = (
165167
subprocess.check_output(
166168
["docker", "inspect", "--format='{{index .RepoDigests 0}}", owlbot_image,],
@@ -175,7 +177,7 @@ def generate(
175177

176178
# run owlbot copy
177179
print("Cloning googleapis-gen...")
178-
subprocess.check_call(["git", "clone", "https://github.com/googleapis/googleapis-gen.git", "./gen/googleapis-gen"], cwd=workdir)
180+
subprocess.check_call(["git", "clone", "-q", googleapis_gen_url, "./gen/googleapis-gen"], cwd=workdir)
179181
subprocess.check_call(["docker", "pull", "gcr.io/cloud-devrel-public-resources/owlbot-cli:latest"])
180182
copy_code_parameters = [
181183
"docker",
@@ -216,6 +218,7 @@ def generate(
216218
cwd=workdir,
217219
)
218220
monorepo_root=(workdir / '..').resolve()
221+
print("monorepo_root=",monorepo_root)
219222
print("Running the post-processor...")
220223
subprocess.check_call(
221224
[
@@ -231,9 +234,6 @@ def generate(
231234
cwd=monorepo_root,
232235
)
233236

234-
subprocess.check_call(["rm", "-f", ".gitignore"],
235-
cwd=workdir)
236-
237237
# Remove irrelevant files from templates
238238
subprocess.check_call(
239239
["bash", "generation/update_owlbot_postprocessor_config.sh"],

0 commit comments

Comments
 (0)