Skip to content

chore: update hermetic library generation workflow #10693

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 17 commits into from
Apr 20, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 0 additions & 113 deletions .github/workflows/generate-from-configuration.yaml

This file was deleted.

48 changes: 2 additions & 46 deletions .github/workflows/generate_new_client_hermetic_build.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Generate new GAPIC client library (Hermetic Build)
on:
workflow_dispatch:
# some inputs are ommited due to limit of 10 input arguments
# some inputs are omitted due to limit of 10 input arguments
inputs:
api_shortname:
required: true
Expand Down Expand Up @@ -53,7 +53,7 @@ jobs:
generate:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: '3.9'
Expand All @@ -78,36 +78,6 @@ jobs:
API_DESCRIPTION: ${{ github.event.inputs.api_description }}
LIBRARY_NAME: ${{ github.event.inputs.library_name }}
DISTRIBUTION_NAME: ${{ github.event.inputs.distribution_name }}
- name: setup docker environment
shell: bash
run: |
set -x
# we create a volume pointing to `pwd` (google-cloud-java) that will
# be referenced by the container and its children
if [[ $(docker volume inspect repo-google-cloud-java) != '[]' ]]; then
docker volume rm repo-google-cloud-java
fi
docker volume create --name "repo-google-cloud-java" --opt "type=none" --opt "device=$(pwd)" --opt "o=bind"
- name: generate from configuration
id: generation
shell: bash
run: |
set -x
repo_volumes="-v repo-google-cloud-java:/workspace/google-cloud-java"
echo "::set-output name=repo_volumes::${repo_volumes}"
docker run --rm \
${repo_volumes} \
-v /tmp:/tmp \
-v /var/run/docker.sock:/var/run/docker.sock \
-e "RUNNING_IN_DOCKER=true" \
-e "REPO_BINDING_VOLUMES=${repo_volumes}" \
gcr.io/cloud-devrel-public-resources/java-library-generation:latest \
python /src/generate_repo.py generate \
--generation-config-yaml=/workspace/google-cloud-java/generation_config.yaml \
--repository-path=/workspace/google-cloud-java \
--target-library-names=${API_SHORTNAME}
env:
API_SHORTNAME: ${{ github.event.inputs.api_shortname }}
- name: Push to branch and create PR
run: |
set -x
Expand All @@ -133,19 +103,6 @@ jobs:

\`\`\`
python generation/new_client_hermetic_build/add-new-client-config.py add-new-client ${GENERATION_ARGUMENTS}

docker run --rm \\
${DOCKER_VOLUMES} \\
-v /tmp:/tmp \\
-v /var/run/docker.sock:/var/run/docker.sock \\
-e \"RUNNING_IN_DOCKER=true\" \\
-e \"REPO_BINDING_VOLUMES=${DOCKER_VOLUMES}\" \\
gcr.io/cloud-devrel-public-resources/java-library-generation:latest \\
python /src/generate_repo.py generate \\
--generation-config-yaml=/workspace/google-cloud-java/generation_config.yaml \\
--repository-path=/workspace/google-cloud-java \\
--target-library-names=${API_SHORTNAME}

\`\`\`"
gh pr create --title "${commit_message}" --label "owlbot:run" --head "${branch_name}" --body "${pr_body}"
env:
Expand All @@ -154,4 +111,3 @@ jobs:
GENERATION_ARGUMENTS: ${{ steps.config_generation.outputs.new_library_args }}
DOCKER_VOLUMES: ${{ steps.generation.outputs.repo_volumes }}
GH_TOKEN: ${{ secrets.CLOUD_JAVA_BOT_TOKEN }}

4 changes: 2 additions & 2 deletions .github/workflows/generated_files_sync.yaml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit (maybe not in scope): What's the purpose of this script? Maybe a one-liner comment can help.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a one-liner comment in each job in the workflow.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remind me what this file is used for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This workflow is used to verify generated files, e.g., owlbot.py, are not modified by pull request. Each job verifies one file.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we do want to update owlbot.py for a certain library? Also does it mean we run the generation for the whole repo on every PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we do want to update owlbot.py for a certain library?

The check will fail. This is a not required check only to remain the author the change is indeed intentional.

Also does it mean we run the generation for the whole repo on every PR?

root pom and gapic-libraries-bom are generated through hermetic build cli script (just like repo-level post processing). Other checks are done through shell script in this repo, which are not generating any java file, so they are relatively fast.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Github action job to test core java library features on
# GitHub action job to test core java library features on
# downstream client libraries before they are released.
on:
push:
Expand All @@ -20,7 +20,7 @@ on:
pull_request:
name: generation diff
env:
library_generation_image_tag: latest
library_generation_image_tag: 2.39.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this configured to be updated renovate bot?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I plan to update renovate config in separate PR.

repo_volumes: "-v repo-google-cloud-java:/workspace/google-cloud-java"
jobs:
root-pom:
Expand Down
43 changes: 29 additions & 14 deletions .github/workflows/hermetic_library_generation.yaml
Original file line number Diff line number Diff line change
@@ -1,27 +1,42 @@
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# GitHub action job to test core java library features on
# downstream client libraries before they are released.
name: Hermetic library generation upon generation config change through pull requests
on:
pull_request:
types:
- synchronize
paths:
- generation_config.yaml
- "generation_config.yaml"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the trigger only for main branch? If yes, can this be configured to be triggered for other branches, like a future LTS branch?

Copy link
Contributor Author

@JoeWang1127 JoeWang1127 Apr 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be triggered when a pull request changes generation_config.yaml.

Therefore, it can be used in any branch since the pull request is not necessarily based on main.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any configuration for a target branch, does it mean if I create a PR with generation_config.yaml changes against a release/2.x branch, this workflow would be triggered too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.


jobs:
library_generation:
runs-on: ubuntu-latest
env:
library_generation_image_tag: latest
repo_volumes: "-v repo-google-cloud-java:/workspace/google-cloud-java"
library_generation_image_tag: 2.39.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this configured to be updated renovate bot?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I plan to update renovate config in separate PR.

steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
- name: get baseline generation config
uses: actions/checkout@v4
with:
ref: ${{ github.base_ref }}
path: baseline
sparse-checkout: generation_config.yaml
- name: diff
fetch-depth: 0
- name: Generate changed libraries
shell: bash
run: |
diff generation_config.yaml baseline/generation_config.yaml
set -x
[ -z "$(git config user.email)" ] && git config --global user.email "[email protected]"
[ -z "$(git config user.name)" ] && git config --global user.name "cloud-java-bot"
bash generation/hermetic_library_generation.sh \
--target_branch ${{ github.base_ref }} \
--current_branch ${{ github.head_ref }} \
--image_tag "${library_generation_image_tag}"
env:
GH_TOKEN: ${{ secrets.CLOUD_JAVA_BOT_TOKEN }}
41 changes: 41 additions & 0 deletions .github/workflows/update_googleapis_commit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# GitHub action job to test core java library features on
# downstream client libraries before they are released.
name: Update googleapis commit
on:
schedule:
- cron: '* 2 * * *'
workflow_dispatch:


jobs:
update-googleapis-commit:
runs-on: ubuntu-22.04
env:
# the branch into which the pull request is merged
base_branch: lts-11
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this lts-11 intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this is a test value. I changed it to main.

steps:
- uses: actions/checkout@v4
- name: Update googleapis commit to latest
shell: bash
run: |
set -x
[ -z "$(git config user.email)" ] && git config --global user.email "[email protected]"
[ -z "$(git config user.name)" ] && git config --global user.name "cloud-java-bot"
bash generation/update_googleapis_commit.sh \
--base_branch "${base_branch}"\
--repo ${{ github.repository }}
env:
GH_TOKEN: ${{ secrets.CLOUD_JAVA_BOT_TOKEN }}
Loading