Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 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 emitted due to limit of 10 input arguments
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: ommited should be omitted

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

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

2 changes: 1 addition & 1 deletion .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 @@ -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
26 changes: 12 additions & 14 deletions .github/workflows/hermetic_library_generation.yaml
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
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
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 }}
24 changes: 24 additions & 0 deletions .github/workflows/update_googleapis_commit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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
bash generation/update_googleapis_commit.sh \
--base_branch "${base_branch}"\
--repo ${{ github.repository }}
env:
GH_TOKEN: ${{ secrets.CLOUD_JAVA_BOT_TOKEN }}
113 changes: 113 additions & 0 deletions generation/hermetic_library_generation.sh
Copy link
Contributor

Choose a reason for hiding this comment

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

Really like this script! This script is generic enough to be reused by any repo. We need to come up with a way to reused this script, but worst case we can just copy this script to every handwritten repos.

Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#!/bin/bash
# This script should be run at the root of the repository.
# This script is used to, when a pull request changes the generation
# configuration (generation_config.yaml by default):
# 1. compare generation configurations in the current branch (with which the
# pull request associated) and target branch (into which the pull request is
# merged);
# 2. generate changed libraries using library_generation image;
# 3. commit the change to the pull request
# 4. edit the pr body with generated pull request description, if applicable.

# The following commands need to be installed before running the script:
# 1. git
# 2. gh
# 3. docker

# The parameters of this script is:
# 1. target_branch, the branch into which the pull request is merged.
# 2. current_branch, the branch with which the pull request is associated.
# 3. image_tag, the tag of gcr.io/cloud-devrel-public-resources/java-library-generation.
# 3. [optional] generation_config, the path to the generation configuration,
# the default value is generation_config.yaml in the repository root.
while [[ $# -gt 0 ]]; do
key="$1"
case "${key}" in
--target_branch)
target_branch="$2"
shift
;;
--current_branch)
current_branch="$2"
shift
;;
--image_tag)
image_tag="$2"
shift
;;
--generation_config)
generation_config="$2"
shift
;;
*)
echo "Invalid option: [$1]"
exit 1
;;
esac
shift
done

if [ -z "${target_branch}" ]; then
echo "missing required argument --target_branch"
exit 1
fi

if [ -z "${current_branch}" ]; then
echo "missing required argument --current_branch"
exit 1
fi

if [ -z "${image_tag}" ]; then
echo "missing required argument --image_tag"
exit 1
fi

if [ -z "${generation_config}" ]; then
generation_config=generation_config.yaml
echo "Use default generation config: ${generation_config}"
fi

volume_name="repo"
workspace_name="/workspace/repo"
repo_volumes="${volume_name}:${workspace_name}"
baseline_generation_config="baseline_generation_config.yaml"
message="chore: generate libraries at $(date)"

git checkout "${target_branch}"
git checkout "${current_branch}"
Copy link
Contributor

Choose a reason for hiding this comment

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

qq: Has this double checkout statement a special effect?

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.

In the action, the fetch-depth is 0 so it needs git checkout "${target_branch}" to load target_branch.

We want to copy generation_config.yaml from target branch to current branch.

# copy generation configuration from target branch to current branch.
git show "${target_branch}":"${generation_config}" > "${baseline_generation_config}"
diff "${generation_config}" "${baseline_generation_config}" || echo "config diff"
# bind docker volume to include google-cloud-java in docker running environment.
Copy link
Contributor

Choose a reason for hiding this comment

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

This script is not specific to google-cloud-java anymore, can we mention something more generic?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

if [[ $(docker volume inspect ${volume_name}) != '[]' ]]; then
docker volume rm ${volume_name}
fi
docker volume create \
--name ${volume_name} \
--opt "type=none" \
--opt "device=$(pwd)" \
--opt "o=bind"
# run hermetic code generation docker image.
docker run \
--rm \
-v "${repo_volumes}" \
-v /tmp:/tmp \
-v /var/run/docker.sock:/var/run/docker.sock \
-e "RUNNING_IN_DOCKER=true" \
-e "REPO_BINDING_VOLUMES=-v ${repo_volumes}" \
gcr.io/cloud-devrel-public-resources/java-library-generation:"${image_tag}" \
python /src/cli/entry_point.py generate \
--baseline-generation-config-path="${workspace_name}/${baseline_generation_config}" \
--current-generation-config-path="${workspace_name}/${generation_config}" \
--repository-path="${workspace_name}"
# commit the change to the pull request.
[ -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"
git add java-* pom.xml gapic-libraries-bom/pom.xml versions.txt "${generation_config}"
git commit --allow-empty -m "${message}"
git push
# set pr body if pr_description.txt is generated.
if [[ -f "pr_description.txt" ]]; then
pr_num=$(gh pr list -s open -H "${current_branch}" -q . --json number | jq ".[] | .number")
gh pr edit "${pr_num}" --body "$(cat pr_description.txt)"
fi
2 changes: 1 addition & 1 deletion generation/new_client/new-client.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def generate(
)

# In monorepo, .OwlBot.yaml needs to be in the directory of the module.
owlbot_yaml_location_from_module = ".OwlBot.yaml"
owlbot_yaml_location_from_module = ".OwlBot-hermetic.yaml"
# create owlbot config
templates.render(
template_name="owlbot.yaml.monorepo.j2",
Expand Down
Loading