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

build(node): update client library version in samples metadata #1356

Merged
merged 10 commits into from
Apr 20, 2022
45 changes: 45 additions & 0 deletions synthtool/languages/common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright 2018 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
#
# https://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.

from synthtool import transforms
sofisl marked this conversation as resolved.
Show resolved Hide resolved
import json
import os
sofisl marked this conversation as resolved.
Show resolved Hide resolved
import re

def update_library_version(version):
sofisl marked this conversation as resolved.
Show resolved Hide resolved
"""
read package name and repository in package.json from a Node library.

Returns:
data - package.json file as a dict.
"""
snippet_metadata_files = get_sample_metadata_files()
for file in snippet_metadata_files:
file_to_overwrite = open(file, "w")
data = json.load(file)
data["version"] = version
file_to_overwrite(data)

def get_sample_metadata_files():
sofisl marked this conversation as resolved.
Show resolved Hide resolved
sofisl marked this conversation as resolved.
Show resolved Hide resolved
rootdir = "./samples/generated"
regex = re.compile('snipppet_metdata')

metadata_files = []
for root, dirs, files in os.walk(rootdir):
for file in files:
if regex.match(file):
metadata_files.append[os.path.join(rootdir,file)]

return metadata_files

18 changes: 17 additions & 1 deletion synthtool/languages/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from typing import Any, Dict, List, Optional, Callable
import logging
import shutil
import common

_REQUIRED_FIELDS = ["name", "repository"]
_TOOLS_DIRECTORY = "/synthtool"
Expand Down Expand Up @@ -52,6 +53,19 @@ def read_metadata():
return data


def get_library_version():
"""
get library version from package.json

Returns:
client library version
"""
sofisl marked this conversation as resolved.
Show resolved Hide resolved
sofisl marked this conversation as resolved.
Show resolved Hide resolved
with open("./package.json") as f:
data = json.load(f)
version = data["version"]

return version

def template_metadata() -> Dict[str, Any]:
"""Load node specific template metadata.

Expand Down Expand Up @@ -336,7 +350,9 @@ def owlbot_main(
else:
templates = common_templates.node_library(source_location="build/src")
s_copy([templates], excludes=templates_excludes)


library_version = get_library_version()
common.update_library_version(library_version)

if __name__ == "__main__":
owlbot_main()