Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 74 additions & 10 deletions owlbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,96 @@
import os
from pathlib import Path
from synthtool import _tracked_paths
from typing import AnyStr
import shutil

logging.basicConfig(level=logging.DEBUG)

staging = Path("owl-bot-staging")

if staging.is_dir():
logging.info(f"Copying files from staging directory ${staging}.")
versions = ['v2']
versions_admin = [f"admin/{p}" for p in versions]

logging.info(f"Copying files from staging directory {staging}.")

src_paths = {}
src_files = {}
for version in versions + versions_admin:
src_paths[version] = staging / version
src_files[version] = list([fn for fn in src_paths[version].glob('**/*.*')])

# Copy bigtable library.
# src/index.ts src/v2/index.ts has added AdminClients manually, we don't wanna override it.
# src/index.ts src/admin/v2/index.ts has added AdminClients manually, we don't wanna override it.
# src/*.ts is a added layer for the client libraries, they need extra setting in tsconfig.json & tslint.json
# Tracking issues: 1. https://github.com/googleapis/nodejs-bigtable/issues/636
# 2. https://github.com/googleapis/nodejs-bigtable/issues/635
for version in ['v2']:
library = staging / version
for version in versions:
library = src_paths[version]
_tracked_paths.add(library)
s.copy([library], excludes=['package.json', 'README.md', 'src/index.ts', 'src/v2/index.ts', 'tsconfig.json', 'tslint.json', '.github/sync-repo-settings.yaml'])
admin_files = filter(
lambda f: str(f).find('_admin') >= 0,
src_files[version]
)
excludes = [
'package.json',
'README.md',
'src/index.ts',
'src/v2/index.ts',
'tsconfig.json',
'tslint.json',
'.github/sync-repo-settings.yaml',
'.OwlBot.yaml',
] + list(admin_files)
logging.info(f"excluding files for non-admin: {excludes}")
s.copy([library], excludes = excludes)

# Copy the admin library.
# Not override system-test for admin/v2, just keep the v2 version.
for version in ['v2']:
library = staging / 'admin' / version
# Copy the admin library pieces and knit them in.
# Don't override system-test for admin/v2, just keep the v2 version.
for version in versions:
admin_version = f"admin/{version}"
library = src_paths[admin_version]
inProtoPath = f"protos/google/bigtable/{admin_version}"
protos = library / inProtoPath
classes = library / 'src' / version
samples = library / 'samples' / 'generated'
tests = library / 'test'
_tracked_paths.add(library)
s.copy([library], excludes=['package.json', 'README.md', 'src/index.ts', 'src/v2/index.ts', 'tsconfig.json', 'tslint.json', 'system-test/fixtures/sample/src/index.ts', 'system-test/fixtures/sample/src/index.js', '.github/sync-repo-settings.yaml'])

# We also have to munge the proto paths in the *_proto_list.json due to making it a level deeper.
# That also applies to the classes themselves.
classesStr = str(classes)
jsons = [fn
for fn
in src_files[admin_version]
if str(fn)[:len(classesStr)] == classesStr]
for jfn in jsons:
logging.info(f"munging json file: {str(jfn)}")
contents = jfn.read_text()
contents = contents.replace("'../..", "'../../..")
contents = contents.replace('"../..', '"../../..')
jfn.write_text(contents)

# Also to the tests that import stuff from src. ../ -> ../../../
testsStr = str(tests)
tfns = [fn
for fn
in src_files[admin_version]
if str(fn)[:len(testsStr)] == testsStr]
for tfn in tfns:
logging.info(f"munging test file: {str(tfn)}")
contents = tfn.read_text()
contents = contents.replace("'../", "'../../../")
tfn.write_text(contents)

os.system(f"mkdir -p {inProtoPath}")
s.copy([protos / '*'], destination=inProtoPath)
os.system(f"mkdir -p src/{admin_version}")
s.copy([classes / '*'], destination=f"src/{admin_version}")
os.system(f"mkdir -p samples/generated/{admin_version}")
s.copy([samples / 'v2' / '*admin*'], destination=f"samples/generated/{admin_version}")
os.system(f"mkdir -p test/{admin_version}")
s.copy([tests / '*admin*.ts'], destination=f"test/{admin_version}")

# Replace the client name for generated system-test.
system_test_files=['system-test/fixtures/sample/src/index.ts','system-test/fixtures/sample/src/index.js']
Expand Down
Loading
Loading