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

feat: create pr after library generation #10503

Merged
merged 47 commits into from Mar 12, 2024
Merged

Conversation

JoeWang1127
Copy link
Contributor

@JoeWang1127 JoeWang1127 commented Mar 8, 2024

In this PR:

  • Update workflow to create a PR of hermetic code generation.
    • search baseline commit (B) in generation_config.yaml.
    • search latest commit (L) in googleapis repository.
    • update googleapis commit to L in generation_config.yaml.
    • search for open pull request associated with branch generate-libraries.
      • create a new branch if no pull request is not found; otherwise checkout the pull request.
    • generate GAPIC libraries from generation_config.yaml.
    • generate pull request description from B to L.
    • create a pull request or push a commit.
  • Update generation_config.yaml to include new libraries and new versions.

Context: this is the launch plan of hermetic build project.

run: |
title="chore: generate libraries at $(date)"
git add java-* pom.xml gapic-libraries-bom/pom.xml versions.txt generation_config.yaml
git commit -m "chore: ${title}"
Copy link
Member

Choose a reason for hiding this comment

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

"chore" appears twice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated the commit message.

- name: create or update the pull request
shell: bash
run: |
title="chore: generate libraries at $(date)"
Copy link
Member

@suztomo suztomo Mar 11, 2024

Choose a reason for hiding this comment

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

My instinct says "chore:" does not goes to Release Please pull request and the pull request description is not read by Release Please. Let's see.

(If this is really the case, we can fix it by "BEGIN_COMMIT_OVERRIDE".)

Copy link
Contributor

Choose a reason for hiding this comment

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

I feel the same way. Can we make sure we understand the behavior before merging? e.g. If it is a chore, is release please going to include the NESTE_COMMIT in the description? If it is a feat, is the title going to be included? The behavior of release-please will affect how we generate the PR descriptions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

According to @chingor13, release-please won't skip a commit if it's a chore, it just ignores chore commit messages.

@blakeli0
Copy link
Contributor

Is this PR an example of the generated PR?

@JoeWang1127
Copy link
Contributor Author

Is this PR an example of the generated PR?

Yes.

@JoeWang1127
Copy link
Contributor Author

JoeWang1127 commented Mar 11, 2024

generation diff/root-pom and generation diff/gapic-bom failed because the sorted entries in pom.xml are in different order when using shell sort and python sorted.

The content is the same, thus no impact on build.

.github/workflows/verify-generation-config.yaml Outdated Show resolved Hide resolved
- name: create or update the pull request
shell: bash
run: |
title="chore: generate libraries at $(date)"
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel the same way. Can we make sure we understand the behavior before merging? e.g. If it is a chore, is release please going to include the NESTE_COMMIT in the description? If it is a feat, is the title going to be included? The behavior of release-please will affect how we generate the PR descriptions.

git fetch -q --unshallow monorepo
git push -f monorepo "${branch_name}"
set -x
gh pr create --title "${title}" --label "owlbot:run" --head "${branch_name}" --body "$(cat pr_description.txt)"
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we still need owlbot:run here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The check is not removed yet.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should remove the label here and disable the check for this branch, otherwise owlbot postprocessing would still be run against this PR right?

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 to removing the required check for owlbot postprocessor and the label

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.

@@ -30,3 +72,40 @@ jobs:
-e "REPO_BINDING_VOLUMES=${repo_volumes}" \
gcr.io/cloud-devrel-public-resources/java-library-generation:latest \
Copy link
Contributor

Choose a reason for hiding this comment

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

Ideally we should not use latest, but rather a versioned docker image, otherwise it is not hermetic. But since this is the first time we use the scripts and there might be bug fixes in this cycle, let's keep it for now. Once the scripts are stable, we should read the gapic-generator-java version from the build config file and use that version for the docker image.
For now, can we extract latest as a parameter and share it between this step and the step below?

Copy link
Contributor

Choose a reason for hiding this comment

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

Just FYI, we have a release job that releases gcr.io/cloud-devrel-public-resources/java-library-generation:${GGJ_VERSION}, so if we are to remove it, we can use that tag (and configure 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.

Once the scripts are stable, we should read the gapic-generator-java version from the build config file and use that version for the docker image.

I think we should group the docker image tag with generator update so that renovate bot can update them together.

For now, can we extract latest as a parameter and share it between this step and the step below?

Sounds good.

generate-from-configuration:
runs-on: ubuntu-22.04
env:
branch_name: generate-libraries
Copy link
Contributor

Choose a reason for hiding this comment

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

This could be a follow up PR. Can we make this a parameter so that we can test the Github action in a separate branch? Otherwise it would always override the current PR if it is not merged.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Otherwise it would always override the current PR if it is not merged

This is an intended behavior because we don't want a lot of open PRs in the repo.

This is the description of 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.

In addition, can we change the branch name to include the branch name, something like generate-libraries-main? As we would need to support LTS and multiple Java versions in the future.

Copy link
Contributor

Choose a reason for hiding this comment

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

Otherwise it would always override the current PR if it is not merged

This is an intended behavior because we don't want a lot of open PRs in the repo.

This is the description of the workflow.

I agree with this behavior. What I'm suggesting is to make it more flexible so that we can test the Github action without overriding the 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.

Done.

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. I think this PR should be a chore as it does not really change any code, otherwise it would appear in the release notes.
A few follow up enhancements that I can think of:

  1. Make this Github action more generic so that it can be reused for other use cases. e.g. Extract the target branch, googleapis commitish to parameters, do not always update googleapis commitish etc.
  2. Encapsulate the PR creation logic in the docker image. So that it can be tested independently and more hermetic.
  3. Create a separate Github action or reuse this Github action to automatically update renovate bot PRs for gapic-generator-java version update.

generate-from-configuration:
runs-on: ubuntu-22.04
env:
branch_name: generate-libraries
Copy link
Contributor

Choose a reason for hiding this comment

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

In addition, can we change the branch name to include the branch name, something like generate-libraries-main? As we would need to support LTS and multiple Java versions in the future.

git fetch -q --unshallow monorepo
git push -f monorepo "${branch_name}"
set -x
gh pr create --title "${title}" --head "${branch_name}" --body "$(cat pr_description.txt)"
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess this creates a PR against main branch by default? Can we make the target branch a parameter as well?

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.

- name: create or update the pull request
shell: bash
run: |
title="chore: generate libraries at $(date)"
Copy link
Contributor

Choose a reason for hiding this comment

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

The title generation could be moved to sdk-platform-java and/or inside the docker images.

env:
branch_name: generate-libraries
library_generation_image_tag: latest
repo_volumes: "-v repo-google-cloud-java:/workspace/google-cloud-java"
Copy link
Contributor

Choose a reason for hiding this comment

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

Anything that references google-cloud-java should be extracted to a parameter, so that we can reuse this Github action in handwritten library repos.

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'll leave this one as-is and we'll refactor it once we prove this is working on google-cloud-java.

@JoeWang1127 JoeWang1127 enabled auto-merge (squash) March 12, 2024 00:34
@JoeWang1127 JoeWang1127 merged commit cd29fa9 into main Mar 12, 2024
29 of 31 checks passed
@JoeWang1127 JoeWang1127 deleted the feat/hermetic-pr-creation branch March 12, 2024 01:51
@@ -167,6 +167,14 @@ libraries:
GAPICs:
- proto_path: google/appengine/v1

- api_shortname: apphub
Copy link
Contributor

Choose a reason for hiding this comment

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

Which script do you use to populate this yaml?

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 manually added these libraries, the parameters are copied from new library generation PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
owlbot:run Add this label to trigger the Owlbot post processor.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants