Skip to content
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

chore: update hermetic library generation workflow #10693

Merged
merged 17 commits into from
Apr 20, 2024

Conversation

JoeWang1127
Copy link
Contributor

@JoeWang1127 JoeWang1127 commented Apr 12, 2024

In this PR:

  • Add a workflow, when generation_config.yaml is changed in a pull request, to generate changed libraries and push commits to the corresponding pull request.
  • Update workflow only to update googleapis commit.
  • Update workflow only to add library configuration to generation_config.yaml.
  • Change image tag to 2.39.0

Follow up of googleapis/sdk-platform-java#2616

For the goal of series of PRs, please refer to improvement proposal.

@JoeWang1127 JoeWang1127 marked this pull request as ready for review April 17, 2024 18:21
@JoeWang1127 JoeWang1127 requested a review from a team as a code owner April 17, 2024 18:21
@JoeWang1127
Copy link
Contributor Author

JoeWang1127 commented Apr 17, 2024

The workflows are tests in a forked repo:
https://github.com/JoeWang1127/google-cloud-java/pull/19 (update a library)
https://github.com/JoeWang1127/google-cloud-java/pull/17 (update googleapis commit)

shell: bash
run: |
diff generation_config.yaml baseline/generation_config.yaml
git show ${{ github.base_ref }}:generation_config.yaml > baseline_generation_config.yaml
- name: show configuration diff
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we extract most of the logics here to a shell script so that we can call the script directly here? That way we can easily call it in local and possibly in a non-Github environment in the future.
Ideally, we should try to put this logic into Docker container as well, so that this logic could be reused by handwritten libraries, otherwise we would need to duplicate this in every handwritten repos. Bake it into Docker can be a future enhancement, but I think we should at least extract it to a separate script.

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.

Moved command lines to a script.

base_branch: main
steps:
- uses: actions/checkout@v4
- name: Setup branch for pull request
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as above. Let's extract it to a script for now, and think about ways to make it more reusable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved command lines to a script.

@JoeWang1127 JoeWang1127 requested review from blakeli0 and suztomo April 19, 2024 14:46
@JoeWang1127
Copy link
Contributor Author

Should we remove "Verify GAPIC client library generation" or rewrite it using hermetic build script?

Copy link
Contributor

@diegomarquezp diegomarquezp left a comment

Choose a reason for hiding this comment

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

LGTM, just a couple nits and a question

@@ -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.

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.

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.

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.

generation/new_client/new-client.py Outdated Show resolved Hide resolved
@@ -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.

# 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.

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.

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.

generation/hermetic_library_generation.sh Outdated Show resolved Hide resolved
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.

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.

@blakeli0
Copy link
Contributor

Should we remove "Verify GAPIC client library generation" or rewrite it using hermetic build script?

I think we can remove it as the logic of "new client generation" is part of the hermetic build scripts now.

@JoeWang1127
Copy link
Contributor Author

I think we can remove it as the logic of "new client generation" is part of the hermetic build scripts now.

I'll remove this check in another PR.

Copy link
Contributor

@blakeli0 blakeli0 left a comment

Choose a reason for hiding this comment

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

LGTM. Please update the PR title to make it more meaningful before merging, and update relevant docs after merging.

@JoeWang1127 JoeWang1127 changed the title chore: update generation workflow chore: update hermetic library generation workflow Apr 20, 2024
@JoeWang1127 JoeWang1127 merged commit 91fa7be into main Apr 20, 2024
31 of 32 checks passed
@JoeWang1127 JoeWang1127 deleted the chore/update-gen-workflow branch April 20, 2024 00:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants