Skip to content

Commit

Permalink
Merge branch 'master' into rename-rst-files
Browse files Browse the repository at this point in the history
  • Loading branch information
dizcology authored Sep 26, 2023
2 parents 1511e04 + 4c4063f commit 265654c
Show file tree
Hide file tree
Showing 24 changed files with 87 additions and 41 deletions.
7 changes: 1 addition & 6 deletions docker/owlbot/nodejs/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
# build from the root of this repo:
# docker build -t gcr.io/repo-automation-bots/owlbot-nodejs -f docker/owlbot/nodejs/Dockerfile .
FROM python:3.10.12-bookworm

WORKDIR /

###################### Install nodejs.
Expand Down Expand Up @@ -46,11 +45,7 @@ COPY post-processor-changes.txt /post-processor-changes.txt
RUN find /synthtool -exec chmod a+r {} \;
RUN find /synthtool -type d -exec chmod a+x {} \;

# Install dependencies used for post processing:
# * gts/typescript are used for linting.
# * google-gax and gapic-tools are used for compiling protos.
RUN cd /synthtool && mkdir node_modules && npm i [email protected] [email protected] \
[email protected] @google-cloud/[email protected] [email protected]
RUN cd /synthtool && mkdir node_modules && npm install @google-cloud/[email protected]

ENTRYPOINT [ "/bin/bash" ]
CMD [ "/synthtool/docker/owlbot/nodejs/entrypoint.sh" ]
2 changes: 2 additions & 0 deletions docker/owlbot/nodejs/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

set -ex

npm i --only=dev --ignore-scripts

if [ -f owlbot.py ]; then
python owlbot.py
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ branchProtectionRules:
requiredStatusCheckContexts:
- "ci/kokoro: Samples test"
- "ci/kokoro: System test"
- docs
- lint
- test ({{metadata['engine'] | int}})
- test ({{metadata['engine'] | int+2}})
Expand Down
1 change: 1 addition & 0 deletions synthtool/gcp/templates/python_library/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ docs.metadata

# Virtual environment
env/
venv/

# Test logs
coverage.xml
Expand Down
21 changes: 0 additions & 21 deletions synthtool/gcp/templates/python_mono_repo_library/noxfile.py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -472,24 +472,3 @@ def prerelease_deps(session):
session.run("python", "-c", "import google.auth; print(google.auth.__version__)")

session.run("py.test", "tests/unit")

system_test_path = os.path.join("tests", "system.py")
system_test_folder_path = os.path.join("tests", "system")

# Only run system tests if found.
if os.path.exists(system_test_path):
session.run(
"py.test",
"--verbose",
f"--junitxml=system_{session.python}_sponge_log.xml",
system_test_path,
*session.posargs,
)
if os.path.exists(system_test_folder_path):
session.run(
"py.test",
"--verbose",
f"--junitxml=system_{session.python}_sponge_log.xml",
system_test_folder_path,
*session.posargs,
)
29 changes: 22 additions & 7 deletions synthtool/languages/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,20 +213,22 @@ def fix(hide_output=False):
shell.run(["npm", "run", "fix"], hide_output=hide_output)


# TODO: delete these functions if it turns out we no longer
# need them to be hermetic.
def fix_hermetic(hide_output=False):
"""
Fixes the formatting in the current Node.js library. It assumes that gts
is already installed in a well known location on disk (node_modules/.bin).
"""
logger.debug("Copy eslint config")
shell.run(
["cp", "-r", f"{_TOOLS_DIRECTORY}/node_modules", "."],
["cp", "-r", "node_modules", "."],
check=True,
hide_output=hide_output,
)
logger.debug("Running fix...")
shell.run(
[f"{_TOOLS_DIRECTORY}/node_modules/.bin/gts", "fix"],
["node_modules/.bin/gts", "fix"],
check=False,
hide_output=hide_output,
)
Expand All @@ -241,6 +243,8 @@ def compile_protos(hide_output=False):
shell.run(["npx", "compileProtos", "src"], hide_output=hide_output)


# TODO: delete these functions if it turns out we no longer
# need them to be hermetic.
def compile_protos_hermetic(hide_output=False):
"""
Compiles protos into .json, .js, and .d.ts files using
Expand All @@ -249,7 +253,7 @@ def compile_protos_hermetic(hide_output=False):
"""
logger.debug("Compiling protos...")
shell.run(
[f"{_TOOLS_DIRECTORY}/node_modules/.bin/compileProtos", "src"],
["node_modules/.bin/compileProtos", "src"],
check=True,
hide_output=hide_output,
)
Expand All @@ -265,8 +269,8 @@ def postprocess_gapic_library(hide_output=False):

def postprocess_gapic_library_hermetic(hide_output=False):
logger.debug("Post-processing GAPIC library...")
fix_hermetic(hide_output=hide_output)
compile_protos_hermetic(hide_output=hide_output)
fix(hide_output=hide_output)
compile_protos(hide_output=hide_output)
logger.debug("Post-processing completed")


Expand All @@ -277,15 +281,26 @@ def write_release_please_config(dirs: list):
with open("release-please-config.json", "r") as f:
data = json.load(f)
for dir in dirs:
isPrivate = check_if_private_package(dir)
result = re.search(r"(src/apis/.*)", dir)
assert result is not None
data["packages"][result.group()] = {}
if result and isPrivate is False:
data["packages"][result.group()] = {}
# Make sure base package is also published
data["packages"]["."] = {}
if check_if_private_package(".") is False:
data["packages"]["."] = {}
with open("release-please-config.json", "w") as f:
json.dump(data, f, indent=2)


def check_if_private_package(path: str):
with open(Path(path, "package.json"), "r") as f:
packageJson = json.load(f)
if "private" in packageJson and packageJson["private"] is True:
return True
return False


default_staging_excludes = ["README.md", "package.json", "src/index.ts"]
default_templates_excludes: List[str] = []

Expand Down
5 changes: 4 additions & 1 deletion synthtool/languages/python_mono_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,12 @@ def owlbot_main(package_dir: str) -> None:
microgenerator=True,
default_python_version="3.9",
unit_test_python_versions=["3.7", "3.8", "3.9", "3.10", "3.11"],
system_test_python_versions=["3.8", "3.9", "3.10", "3.11"],
cov_level=100,
versions=gcp.common.detect_versions(
path=f"{package_dir}/google", default_first=True
path=f"{package_dir}/google",
default_version=default_version,
default_first=True,
),
)
s.move([templated_files], package_dir)
Expand Down
5 changes: 5 additions & 0 deletions tests/fixtures/node_apiary/with_private/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "gax-nodejs",
"private": true,
"description": "Google API Extensions"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"release-type": "node",
"packages": {
"src/apis/docs": {}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"release-type": "node",
"packages": {
"src/apis/docs": {}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "admin",
"private": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "docs"
}
4 changes: 4 additions & 0 deletions tests/fixtures/node_apiary/without_private/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "gax-nodejs",
"description": "Google API Extensions"
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "admin"
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "docs"
}
Empty file.
28 changes: 23 additions & 5 deletions tests/test_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,13 +242,29 @@ def test_owlbot_main_with_staging_index_from_staging(hermetic_mock, nodejs_dlp):
assert staging_text == text


def test_write_release_please_config():
def test_write_release_please_config_without_private_indicator():
# use a non-nodejs template directory
with util.copied_fixtures_dir(FIXTURES / "node_apiary"):
with util.copied_fixtures_dir(FIXTURES / "node_apiary" / "without_private"):
node.write_release_please_config(
[
"Users/person/src/apis/admin",
"tmpfs/src/apis/docs",
"src/apis/admin",
"src/apis/docs",
]
)

assert filecmp.cmp(
pathlib.Path("release-please-config.json"),
pathlib.Path("release-please-config-post-apiary.json"),
)


def test_write_release_please_config_with_private_indicator():
# use a non-nodejs template directory
with util.copied_fixtures_dir(FIXTURES / "node_apiary" / "with_private"):
node.write_release_please_config(
[
"src/apis/admin",
"src/apis/docs",
]
)

Expand All @@ -264,7 +280,9 @@ def test_walk_through_apiary(mock_subproc_popen):
attrs = {"communicate.return_value": ("output", "error")}
process_mock.configure_mock(**attrs)
mock_subproc_popen.return_value = process_mock
dirs = node.walk_through_apiary(FIXTURES / "node_apiary", "src/apis/**/*")
dirs = node.walk_through_apiary(
FIXTURES / "node_apiary" / "without_private", "src/apis/**/*"
)
assert not mock_subproc_popen.called
assert re.search(
"(?:% s)" % "|".join(["src/apis/admin", "src/apis/docs"]),
Expand Down

0 comments on commit 265654c

Please sign in to comment.