Skip to content

Commit

Permalink
chore: update hermetic library generation workflow (#10693)
Browse files Browse the repository at this point in the history
* chore: update generation workflow

* update workflow

* update new client creation workflow

* add base branch

* use shell script

* generalize repo name

* add script to update googleapis commit

* update comments

* update workflow file

* update image tag

* try to fix workflow error

* change comment

* update comment

* refactor according to code review

* restore change

* update branch
  • Loading branch information
JoeWang1127 authored Apr 20, 2024
1 parent 61aa5c2 commit 91fa7be
Show file tree
Hide file tree
Showing 7 changed files with 273 additions and 175 deletions.
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
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
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"

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
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: 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

0 comments on commit 91fa7be

Please sign in to comment.