Skip to content

Commit

Permalink
chore: add test for new client generation (#8670)
Browse files Browse the repository at this point in the history
  • Loading branch information
meltsufin authored Oct 27, 2022
1 parent beefe83 commit 7a0fa4d
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 6 deletions.
78 changes: 78 additions & 0 deletions .github/workflows/newclient.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: New Client
on:
schedule:
- cron: '0 2 * * *' # nightly at 2 am UTC
push:
branches: [ main ]
paths:
- generation/**
pull_request:
branches: [ main ]
paths:
- generation/**

workflow_dispatch:

jobs:
generate:
runs-on: ubuntu-latest
env:
API_SHORT_NAME: apikeys
API_PRETTY_NAME: API Keys
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.9'
cache: 'pip' # caching pip dependencies
- name: Get current date
id: date
run: echo "::set-output name=date::$(date +'%Y-%m-%d' --utc)"
- uses: actions/setup-java@v3
with:
distribution: zulu
java-version: 11
- run: java -version
- uses: actions/cache@v3
id: mvn-cache
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-unified-${{ steps.date.outputs.date }}
- name: Install dependencies
run: pip install -r generation/new_client/requirements.txt
- name: Remove Client
run: |
rm -rf java-${API_SHORT_NAME} || true
sed -i "/${API_SHORT_NAME}/d" pom.xml
sed -i "/${API_SHORT_NAME}/d" gapic-libraries-bom/pom.xml
- name: Verify Client Removal
run: |
! test -d java-${API_SHORT_NAME}
! grep -q ${API_SHORT_NAME} pom.xml
! grep -q ${API_SHORT_NAME} gapic-libraries-bom/pom.xml
- name: Generate
run: |
python generation/new_client/new-client.py generate \
--api_shortname=${API_SHORT_NAME} \
--proto-path=google/api/${API_SHORT_NAME} \
--name-pretty="${API_PRETTY_NAME}" \
--product-docs="https://github.com/googleapis/google-cloud-java/tree/main/java-${API_SHORT_NAME}" \
--api-description="${API_PRETTY_NAME} Client lets you use ${API_PRETTY_NAME} API." \
--googleapis-gen-url=https://yoshi-approver:${{ secrets.YOSHI_APPROVER_PRIVATE_TOKEN }}@github.com/googleapis/googleapis-gen.git
- 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}"
git checkout -b newclient_output_${{ github.event_name }}
git add --all
git commit -m 'feat: re-generated ${API_SHORT_NAME}'
git remote add monorepo https://${{ github.actor }}:${{ github.token }}@github.com/${{ github.repository }}.git
git fetch -q --unshallow monorepo
git push -f monorepo newclient_output_${{ github.event_name }}
- name: Verify Client Creation
run: |
test -d java-${API_SHORT_NAME}
grep -q ${API_SHORT_NAME} pom.xml
grep -q ${API_SHORT_NAME} gapic-libraries-bom/pom.xml
- name: Test
run: mvn test -T C1 -B
2 changes: 1 addition & 1 deletion generation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ See: [bootstrap_output](https://github.com/googleapis/google-cloud-java/tree/boo
### Diffs

The workflow also generates a diff between the current `main` branch and the generated aggregation of modules from split repos.
See: `boostrap_outout_diff_{event}` branches.
See: `boostrap_outout_diff_{event}` branches.
10 changes: 5 additions & 5 deletions generation/new_client/new-client.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def main(ctx):
"--owlbot-image", type=str, default="gcr.io/cloud-devrel-public-resources/owlbot-java"
)
@click.option("--library-type", type=str)
@click.option("--googleapis-gen-url", type=str, default="https://github.com/googleapis/googleapis-gen.git")
def generate(
api_shortname,
name_pretty,
Expand All @@ -85,6 +86,7 @@ def generate(
group_id,
owlbot_image,
library_type,
googleapis_gen_url,
):
cloud_prefix = "cloud-" if cloud_api else ""

Expand Down Expand Up @@ -160,7 +162,7 @@ def generate(
)

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

# run owlbot copy
print("Cloning googleapis-gen...")
subprocess.check_call(["git", "clone", "https://github.com/googleapis/googleapis-gen.git", "./gen/googleapis-gen"], cwd=workdir)
subprocess.check_call(["git", "clone", "-q", googleapis_gen_url, "./gen/googleapis-gen"], cwd=workdir)
subprocess.check_call(["docker", "pull", "gcr.io/cloud-devrel-public-resources/owlbot-cli:latest"])
copy_code_parameters = [
"docker",
Expand Down Expand Up @@ -216,6 +218,7 @@ def generate(
cwd=workdir,
)
monorepo_root=(workdir / '..').resolve()
print("monorepo_root=",monorepo_root)
print("Running the post-processor...")
subprocess.check_call(
[
Expand All @@ -231,9 +234,6 @@ def generate(
cwd=monorepo_root,
)

subprocess.check_call(["rm", "-f", ".gitignore"],
cwd=workdir)

# Remove irrelevant files from templates
subprocess.check_call(
["bash", "generation/update_owlbot_postprocessor_config.sh"],
Expand Down

0 comments on commit 7a0fa4d

Please sign in to comment.