Skip to content

Commit

Permalink
build: ignore private repos when walking through repos with release-p…
Browse files Browse the repository at this point in the history
…lease (#1860)

* build: ignore private repos when walking through repos with release-please
  • Loading branch information
sofisl committed Sep 19, 2023
1 parent fa95f29 commit 0e18f75
Show file tree
Hide file tree
Showing 18 changed files with 70 additions and 7 deletions.
15 changes: 13 additions & 2 deletions synthtool/languages/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,15 +277,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: 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 0e18f75

Please sign in to comment.