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

feat: add node mono repo post processor #1471

Merged
merged 12 commits into from
Jul 6, 2022
Merged

Conversation

sofisl
Copy link
Contributor

@sofisl sofisl commented Jun 28, 2022

Same as #1470, with easier-to-read diff

@sofisl sofisl requested a review from a team June 28, 2022 23:05
@snippet-bot
Copy link

snippet-bot bot commented Jun 28, 2022

Here is the summary of changes.

You are about to add 26 region tags.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

Copy link
Contributor

@bcoe bcoe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some small refactoring suggestions. Mainly, I believe there are a few places where you could just import a method from node.py, rather than copying the helpers.

Algorithmically, I think there's a risk that glob won't scale well as we add 1000s of files. I would instead consider a simple directory list, since we know that files will be in a well known location.

Overall, I think this is great work 🎉 , it's great that you got through tests in place.

synthtool/gcp/common.py Outdated Show resolved Hide resolved
@@ -326,6 +326,36 @@ def node_library(self, **kwargs) -> Path:

return self._generic_library("node_library", **kwargs)

def node_mono_repo_library(self, relative_dir, **kwargs) -> Path:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since this logic is pretty much identical to def node_library, I might just make node_library take an optional relative_dir parameter, and then default to ./ unless there's an alternate relative_dir provided.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normally, I think it would be better to simply modify the existing code rather than duplicating it. However, I think in this case it's better to duplicate it, because: 1) it makes it easier to read and debug (just follow the node_mono_repo naming), and 2) we are eventually migrating to a mono repo, and eventually all the split repo paths will be deprecated. Given that it's only a few helper methods that are truly being copied over, I'd opt for copying over adding a new path to a helper method (this goes for other helper methods that are similar as well). Furthermore, if there are more specific changes we need to make for mono-repos, it will be easier to add to a mono-repo only path rather than making sure it doesn't affect split repos.

data["repository"] = f'{repo["owner"]}/{repo["name"]}'
data["repository_name"] = repo["name"]
data["lib_install_cmd"] = f'npm install {data["name"]}'
engines_field = re.search(r"([0-9][0-9])", data["engines"]["node"])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would switch this to [0-9]+, prevents a bug if Node ever goes to weekly releases like Chrome (which is up to version 101).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this logic is branched from the node module, I'd be ok leaving it and following up with a fix to both rather than diverging here.

Also if you want to keep the minimum of 2 digits \d{2,} could work (\d+ is one or more)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will do in a follow-up fix - I only added line 54-55 because the linter was complaining.

Returns:
The name of the key to fetch the publish token.
"""
return package_name.strip("@").replace("/", "-") + "-npm-token"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use a single token for all publication now, so this helper is obsolete, i.e., we should no longer be referencing publish_token anywhere.

return re.findall(r"\{(.*Client)\}", content)


def generate_index_ts(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think several of these helpers are identical to languages/node.py?

I think you could import the helpers from node.py, so that we don't have duplicate code (you can import individual functions).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment above!

A list of all metadata files.
"""
owlbot_dirs = []
for path_object in dir.glob("**/*"):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there's a risk that this glob will get slow once we have dozens of repositories in the repo, as it's going to just create a list of all files in the entire mono-repo.

By convention, we're always going to have the .OwlBot.yaml in one location:

packages/
   a/.OwlBot.yaml
   b/.OwlBot.yaml
   b/.OwlBot.yaml

Given this, I would just use os.listdir, to list directories in packages/, and then check for a .OwlBot.yaml in each folder.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another option too would be to try using the glob **/.OwlBot.yaml. The work is all on the glob side and you won't iterate over unnecessary files.

@sofisl sofisl requested a review from bcoe June 29, 2022 18:39
@sofisl sofisl merged commit 04cc5e8 into master Jul 6, 2022
@sofisl sofisl deleted the nodeMonoRepoPostProcessor branch July 6, 2022 08:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants