-
Notifications
You must be signed in to change notification settings - Fork 91
chore(java): use separate autosynth job for README #767
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
Changes from 8 commits
e5d3604
85f6310
ee6b751
fbd206d
a1a4a08
0dc4be4
b16e6e1
d73587d
a3da900
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Copyright 2020 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. | ||
|
||
"""This script is used to synthesize generated the README for this library.""" | ||
|
||
from synthtool.languages import java | ||
|
||
java.custom_templates(["java_library/README.md"]) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Copyright 2020 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. | ||
|
||
# Format: //devtools/kokoro/config/proto/build.proto | ||
|
||
env_vars: { | ||
key: "TRAMPOLINE_IMAGE" | ||
value: "gcr.io/cloud-devrel-kokoro-resources/python-multi" | ||
} | ||
|
||
env_vars: { | ||
key: "TRAMPOLINE_BUILD_FILE" | ||
value: "github/{{ metadata['repo']['repo_short'] }}/.kokoro/readme.sh" | ||
} | ||
|
||
# Build logs will be here | ||
action { | ||
define_artifacts { | ||
regex: "**/*sponge_log.xml" | ||
regex: "**/*sponge_log.log" | ||
} | ||
} | ||
|
||
# The github token is stored here. | ||
before_action { | ||
fetch_keystore { | ||
keystore_resource { | ||
keystore_config_id: 73713 | ||
keyname: "yoshi-automation-github-key" | ||
# TODO(theacodes): remove this after secrets have globally propagated | ||
backend_type: FASTCONFIGPUSH | ||
} | ||
} | ||
} | ||
|
||
# Common env vars for all repositories and builds. | ||
env_vars: { | ||
key: "GITHUB_USER" | ||
value: "yoshi-automation" | ||
} | ||
env_vars: { | ||
key: "GITHUB_EMAIL" | ||
value: "[email protected]" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/bin/bash | ||
# Copyright 2020 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. | ||
|
||
set -eo pipefail | ||
|
||
cd ${KOKORO_ARTIFACTS_DIR}/github/{{ metadata['repo']['repo_short'] }} | ||
|
||
# Disable buffering, so that the logs stream through. | ||
export PYTHONUNBUFFERED=1 | ||
|
||
# Kokoro exposes this as a file, but the scripts expect just a plain variable. | ||
export GITHUB_TOKEN=$(cat ${KOKORO_KEYSTORE_DIR}/73713_yoshi-automation-github-key) | ||
|
||
# Setup git credentials | ||
echo "https://${GITHUB_TOKEN}:@github.com" >> ~/.git-credentials | ||
git config --global credential.helper 'store --file ~/.git-credentials' | ||
|
||
python3.6 -m pip install git+https://github.com/googleapis/synthtool.git#egg=gcp-synthtool | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does #egg= do? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's used to specify the name of the library being installed: https://pip.pypa.io/en/stable/reference/pip_install/#working-out-the-name-and-version |
||
python3.6 -m autosynth.synth \ | ||
--repository={{metadata['repo']['repo']}} \ | ||
--synth-file-name=.github/readme/synth.py \ | ||
--metadata-path=.github/readme/synth.metadata \ | ||
--pr-title="chore: regenerate README" \ | ||
--branch-suffix="readme" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -323,19 +323,7 @@ def _merge_common_templates( | |
return source_text | ||
|
||
|
||
def common_templates( | ||
excludes: List[str] = [], template_path: Optional[Path] = None, **kwargs | ||
) -> None: | ||
"""Generate common templates for a Java Library | ||
|
||
Fetches information about the repository from the .repo-metadata.json file, | ||
information about the latest artifact versions and copies the files into | ||
their expected location. | ||
|
||
Args: | ||
excludes (List[str], optional): List of template paths to ignore | ||
**kwargs: Additional options for CommonTemplates.java_library() | ||
""" | ||
def _common_template_metadata() -> Dict[str, Any]: | ||
metadata = {} # type: Dict[str, Any] | ||
repo_metadata = common._load_repo_metadata() | ||
if repo_metadata: | ||
|
@@ -359,6 +347,44 @@ def common_templates( | |
else: | ||
metadata["min_java_version"] = DEFAULT_MIN_SUPPORTED_JAVA_VERSION | ||
|
||
kwargs["metadata"] = metadata | ||
return metadata | ||
|
||
|
||
def common_templates( | ||
excludes: List[str] = [], template_path: Optional[Path] = None, **kwargs | ||
) -> None: | ||
"""Generate common templates for a Java Library | ||
|
||
Fetches information about the repository from the .repo-metadata.json file, | ||
information about the latest artifact versions and copies the files into | ||
their expected location. | ||
|
||
Args: | ||
excludes (List[str], optional): List of template paths to ignore | ||
**kwargs: Additional options for CommonTemplates.java_library() | ||
""" | ||
kwargs["metadata"] = _common_template_metadata() | ||
templates = gcp.CommonTemplates(template_path=template_path).java_library(**kwargs) | ||
|
||
# README.md is now synthesized separately. This prevents synthtool from deleting the | ||
# README as it's no longer generated here. | ||
excludes.append("README.md") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This prevents synthtool from removing the README. |
||
|
||
s.copy([templates], excludes=excludes, merge=_merge_common_templates) | ||
|
||
|
||
def custom_templates(files: List[str], **kwargs) -> None: | ||
"""Generate custom template files | ||
|
||
Fetches information about the repository from the .repo-metadata.json file, | ||
information about the latest artifact versions and copies the files into | ||
their expected location. | ||
|
||
Args: | ||
files (List[str], optional): List of template paths to include | ||
**kwargs: Additional options for CommonTemplates.render() | ||
""" | ||
kwargs["metadata"] = _common_template_metadata() | ||
for file in files: | ||
template = gcp.CommonTemplates().render(file, **kwargs) | ||
s.copy([template]) |
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.
Running nox locally made this change on my machine. It still seems to pass tests.