-
Notifications
You must be signed in to change notification settings - Fork 55
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: [hermetic-build] simplify usage of synthtool #2772
Conversation
This PR eliminates the need for: * `library_generation/owlbot/src/apply_repo_templates.py` * Passing the path to the config yaml to the postprocessing scripts ### How is it achieved? We set the environment variable `SYNTHTOOL_TEMPLATES` to point to a temp dir where we copy the contents of `owlbot/templates` plus a modification of the template using `sed` (instead of `synthtool.common_templates`). In this way, we avoid the usage of `apply_repo_templates.py`. generation_config.template_excludes. #### Why don't we use common_templates to pass libraries_bom_version? Because `owlbot.py` is a legacy script that was written when `java.common_templates` didn't take `libraries_bom_version` as a parameter. If we don't like this approach of having two template replacement workflows we could 1. Modify all owlbot.py files 2. Pass libraries_bom_version as an environment variable (not bad) #### What about template_excludes in the config yaml? We still need it to generate new libraries. This is done by rendering a new `owlbot.py` via templates.
export SYNTHTOOL_TEMPLATES=$(mktemp -d) | ||
cp -r ${scripts_root}/owlbot/templates/* "${SYNTHTOOL_TEMPLATES}" | ||
sed -i 's/\$\$__libraries_bom_version__\$\$/'"${libraries_bom_version}"'/g' "${SYNTHTOOL_TEMPLATES}/java_library/README.md" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if we migrate java.py to sdk-platform-java? Do you think of another solution?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be ideal. A couple considerations:
owlbot.py
importssynthtool
, meaning that we would need to not only transferjava.py
but other scripts such ascommon.py
(or we could merge all the logic in a single script)- If we migrate synthtool/java.py, we would still need a way to pass
libraries_bom_version
toowlbot.py
. We can either modifyowlbot.py
or we can rely on an environment variable consumed in java.py
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another more hacky approach would be to pass the version in repo-metadata
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic here seems not easy to maintain, as it is tightly coupled with a magic string __libraries_bom_version__
.
I'm leaning towards the environment variable approach you mentioned. If we go with that approach, I guess we should not need any changes in this file or the template, we just need to load the libraries bom version from environment variable and add it to the kwargs in synthtool?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added googleapis/synthtool#1967 to infer the bom version from the environment. Once that's merged, we can enable the env var approach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What was this file used for? I think it was not only for libraries_bom_version
? Or maybe it was a mistake that we rendered the templates twice?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It allowed us to run common_templates
with the list of template_excludes
listed in the config yaml
export SYNTHTOOL_TEMPLATES=$(mktemp -d) | ||
cp -r ${scripts_root}/owlbot/templates/* "${SYNTHTOOL_TEMPLATES}" | ||
sed -i 's/\$\$__libraries_bom_version__\$\$/'"${libraries_bom_version}"'/g' "${SYNTHTOOL_TEMPLATES}/java_library/README.md" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic here seems not easy to maintain, as it is tightly coupled with a magic string __libraries_bom_version__
.
I'm leaning towards the environment variable approach you mentioned. If we go with that approach, I guess we should not need any changes in this file or the template, we just need to load the libraries bom version from environment variable and add it to the kwargs in synthtool?
Quality Gate passed for 'gapic-generator-java-root'Issues Measures |
Quality Gate passed for 'java_showcase_integration_tests'Issues Measures |
cloud build failed after merging this PR:
|
This PR eliminates the need for: * `library_generation/owlbot/src/apply_repo_templates.py` * Passing the config yaml path to the postprocessing scripts ### How is it achieved? We set the environment variable `SYNTHTOOL_TEMPLATES` to point to a temp dir where we copy the contents of `owlbot/templates` plus a modification of the template using `sed` (instead of `synthtool.common_templates`). In this way, we avoid the usage of `apply_repo_templates.py`. generation_config.template_excludes. #### Why don't we use common_templates to pass libraries_bom_version? Because `owlbot.py` is a legacy script that was written when `java.common_templates` didn't take `libraries_bom_version` as a parameter. If we don't like this approach of having two template replacement workflows we could 1. Modify all owlbot.py files 2. Pass libraries_bom_version as an environment variable (not bad) #### What about template_excludes in the config yaml? We still need it to generate new libraries. This is done by rendering a new `owlbot.py` via templates.
This PR eliminates the need for:
library_generation/owlbot/src/apply_repo_templates.py
How is it achieved?
We set the environment variable
SYNTHTOOL_TEMPLATES
to point to atemp dir where we copy the contents of
owlbot/templates
plus amodification of the template using
sed
(instead ofsynthtool.common_templates
). In this way, we avoid the usage ofapply_repo_templates.py
.generation_config.template_excludes.
Why don't we use common_templates to pass libraries_bom_version?
Because
owlbot.py
is a legacy script that was written whenjava.common_templates
didn't takelibraries_bom_version
as aparameter. If we don't like this approach of having two template
replacement workflows we could
What about template_excludes in the config yaml?
We still need it to generate new libraries. This is done by rendering a
new
owlbot.py
via templates.