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

Improve Dependency Resolution for Workflow Optimization #2355

Conversation

oliverqx
Copy link
Contributor

@oliverqx oliverqx commented Mar 23, 2024

/claim #2235

Description
This PR implements module package-based dependency resolution as requested by issue #2235.

Additional context
Linked issue explains it quite well.

Metadata

Summary by CodeRabbit

  • New Features
    • Enhanced the Git Changes Action to export a variable with changed Go modules in pull requests, introducing Module to module and Module to package dependency resolution methods.
    • Customization options include levelOfDependencyResolution for specifying resolution method and examples for testing based on modified modules and dependencies.
  • Refactor
    • Updated function calls in the main function to include an additional argument for specifying the type of dependency.
  • Documentation
    • README.md now provides details on new features, dependency resolution methods, and examples for testing with different resolution levels.

Copy link
Contributor

coderabbitai bot commented Mar 23, 2024

Walkthrough

The suite of changes enhances the Git Changes Action, focusing on optimizing dependency resolution within Go projects. By introducing package-level dependency detection and refining the action's ability to discern relevant module changes, these updates aim to streamline workflow triggers, ensuring they're only activated by pertinent modifications.

Changes

File Path Change Summary
.../detector/package/depgraph.go Introduced functionality for detecting package dependencies and creating dependency graphs.
.../detector/package/detector.go Added a package detector for identifying changed modules by analyzing their dependency trees.
.../detector/git/eventtype_string.go Moved package declaration to git, affecting package structure and import paths.
contrib/git-changes-action/README.md Updated documentation to reflect new dependency resolution approaches and customization options.
contrib/git-changes-action/main.go Modified outputModuleChanges function to support specifying the type of dependency.

Assessment against linked issues

Objective Addressed Explanation
Improve Dependency Resolution for Workflow Optimization (#2235)
Address repository problems related to custom registries and package lookup failures (#16) The changes focus on dependency detection within Go projects and may not directly address custom registry or package lookup issues.
Force creation of updates for rate-limited dependencies; update dependencies across categories (#16) The enhancements are specific to Go modules and packages, and it's unclear how they affect broader dependency update mechanisms for other technologies.

Possibly related issues

  • None identified. The changes are highly specific to Go dependency resolution within the context of GitHub Actions, and the reviewed issues concern broader dependency management and updates that aren't directly impacted by these changes.

🐰✨

In fields of code, where dependencies lie,
A rabbit hopped, with a discerning eye.
"Let's trim the runs," it said with glee,
To changes that matter, as it should be."
With graphs and detectors, it danced around,
Ensuring that only relevant changes were found.
🌟📦🚀

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added go Pull requests that update Go code size/m labels Mar 23, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between 1e0c559 and c11c90d.
Files selected for processing (3)
  • contrib/git-changes-action/detector/depgraph.go (1 hunks)
  • contrib/git-changes-action/detector/detector.go (2 hunks)
  • contrib/git-changes-action/main.go (2 hunks)
Additional comments: 6
contrib/git-changes-action/main.go (2)
  • 44-44: The addition of the "packages" argument to outputModuleChanges function calls aligns with the PR's objectives to enhance dependency resolution by focusing on package-level changes. This is a necessary update for the intended functionality.

Also applies to: 49-49

  • 64-64: The update to the outputModuleChanges function signature, adding typeOfDependency string, is essential for supporting the new package-level dependency tracking. This change is well-integrated and necessary for the functionality being introduced.
contrib/git-changes-action/detector/depgraph.go (2)
  • 21-21: The addition of the typeOfDependency parameter to getDependencyGraph is crucial for enabling the differentiation between module and package dependencies, aligning with the PR's objectives. This change is well-implemented.
  • 57-115: The logic for handling different types of dependencies ("module" and "packages") within getDependencyGraph is well-structured and aligns with the PR's goal of enhancing dependency resolution. The conditional processing based on the typeOfDependency parameter is effectively implemented, ensuring accurate dependency tracking.
contrib/git-changes-action/detector/detector.go (2)
  • 23-50: The introduction of the identifyNestedDependencyChange function is well-executed, providing necessary functionality for recursively identifying changes in nested dependencies. This addition significantly enhances the granularity of dependency tracking, aligning with the PR's objectives.
  • 70-125: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [53-122]

The updates to DetectChangedModules, incorporating logic to handle "modules" and "packages" types of dependencies, are well-implemented. These changes are essential for the PR's goal of optimizing workflow triggers by focusing on package-level changes, thereby enhancing the efficiency and accuracy of dependency tracking.

@oliverqx oliverqx marked this pull request as draft March 23, 2024 08:48
avoids redundant recursion on previously analyzed packages
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between c11c90d and b86fd2b.
Files selected for processing (1)
  • contrib/git-changes-action/detector/detector.go (2 hunks)
Additional comments: 2
contrib/git-changes-action/detector/detector.go (2)
  • 23-42: The function identifyNestedDependencyChange is introduced to recursively identify changes in nested dependencies. While the logic appears sound, there are a couple of points to consider:
  • Performance: Recursive calls can be expensive, especially for large dependency graphs. Consider adding a mechanism to prevent re-evaluation of packages that have already been checked.
  • Documentation: Adding comments to explain the function's purpose, parameters, and return value would improve readability and maintainability.

Consider implementing memoization to avoid redundant checks on packages that have already been evaluated. Additionally, enhance the function's documentation for clarity.

  • 62-117: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [45-114]

In the DetectChangedModules function, the handling of different types of dependencies (modules or packages) based on the typeOfDependency parameter is a significant change. A few observations and suggestions:

  • Error Handling: The function returns early if it encounters an error, which is good practice. However, consider logging these errors for easier debugging.
  • Complexity: The function's complexity has increased with the addition of package-level dependency tracking. Consider refactoring to reduce complexity and improve readability.
  • Consistency: Ensure that the handling of modules and packages is consistent and that any edge cases are accounted for.

To improve maintainability, consider breaking down the function into smaller, more focused sub-functions. Additionally, ensure comprehensive error logging and review the consistency of handling different dependency types.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between b86fd2b and 3b0b02c.
Files selected for processing (1)
  • contrib/git-changes-action/detector/detector.go (2 hunks)
Additional comments: 2
contrib/git-changes-action/detector/detector.go (2)
  • 23-48: The function identifyNestedDependencyChange is well-structured for recursively identifying nested dependency changes. However, there are a few points to consider:
  • Performance: The recursive approach might lead to performance issues for deeply nested dependencies or large dependency graphs. Consider implementing memoization to avoid re-processing packages that have already been evaluated.
  • Error Handling: Currently, there's no error handling for cases where packageName might not exist in depGraph. Adding a check for the existence of packageName in depGraph before proceeding with the recursion could prevent potential runtime panics.
  • Documentation: Adding comments to explain the function's logic, especially around the use of the packages map for caching results, would improve readability and maintainability.

Consider adding memoization to improve performance and error handling for non-existent package names in the dependency graph.

  • 68-130: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [51-127]

In the DetectChangedModules function:

  • Error Handling and Validation: The function starts by checking for the existence of a go.work file but does not validate the typeOfDependency parameter. Given that the function's behavior significantly depends on this parameter, adding validation for expected values ("modules" or "packages") could prevent unexpected behavior.
  • Complexity: The function's complexity has increased with the addition of handling for package dependencies. Consider refactoring to separate concerns, such as extracting the logic for module and package dependency handling into separate functions. This would not only reduce complexity but also improve the function's readability and maintainability.
  • Documentation: The function could benefit from more detailed comments, especially explaining the new logic introduced for handling package dependencies. This would aid in understanding the changes and the rationale behind them.

Refactor to improve error handling, reduce complexity, and enhance documentation. Consider validating typeOfDependency and extracting logic into smaller, focused functions.

@trajan0x
Copy link
Contributor

@oliverqx btw working on some changes to let these wokflows run correctly

This was referenced Mar 24, 2024
Step 1:
1. Get all packages per module
2. Get all package names publicName<->relativeName

Step 2:
1. Extracts dependencies

This is in preparation for the next commit which will make dependencies per package a set (to avoid dupllicates), and will add dependency filtering to step 2, so that only synapsecns/sanguine packages are included
Changed from map[string][]string to map[string]map[string]struct{}. Will essentially work as a set to avoid any dependency duplication
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between 3b0b02c and 53300cd.
Files selected for processing (1)
  • contrib/git-changes-action/detector/depgraph.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • contrib/git-changes-action/detector/depgraph.go

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between 53300cd and 1c8201f.
Files selected for processing (1)
  • contrib/git-changes-action/detector/depgraph.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • contrib/git-changes-action/detector/depgraph.go

@trajan0x trajan0x marked this pull request as ready for review March 25, 2024 16:34
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between 1c8201f and dd43542.
Files selected for processing (1)
  • contrib/git-changes-action/detector/depgraph.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • contrib/git-changes-action/detector/depgraph.go

@trajan0x trajan0x marked this pull request as draft March 25, 2024 18:06
nested packages whose directory name is found in the module's name, were overriding the module's dependencyNames entry, this commit fixes that issue
dependency filtering is now taken care of on dependency map creation
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between dd43542 and 6f4ceb2.
Files selected for processing (1)
  • contrib/git-changes-action/detector/depgraph.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • contrib/git-changes-action/detector/depgraph.go

@oliverqx oliverqx marked this pull request as ready for review March 25, 2024 19:27
@oliverqx oliverqx marked this pull request as draft March 25, 2024 19:34
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

Review Status

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between faf1fda and a33e94c.
Files selected for processing (1)
  • contrib/git-changes-action/README.md (6 hunks)
Additional Context Used

contrib/git-changes-action/README.md Outdated Show resolved Hide resolved
contrib/git-changes-action/README.md Outdated Show resolved Hide resolved
contrib/git-changes-action/README.md Outdated Show resolved Hide resolved
contrib/git-changes-action/README.md Outdated Show resolved Hide resolved
@oliverqx
Copy link
Contributor Author

oliverqx commented Apr 1, 2024

Note to self: would like to investigate why 89d9aa9 triggered contrib/promexporter as I don't see how that dependency would've been triggered

Looking into this, quite a strange bug

@oliverqx
Copy link
Contributor Author

oliverqx commented Apr 1, 2024

Would you let me know if the README.md is accurate and understandable

cc: @trajan0x

@trajan0x
Copy link
Contributor

trajan0x commented Apr 2, 2024

README looks great, glad you're seeing the behavior in 89d9aa9 as well. That was the one thing I was looking at just to make sure this was working as intended

I'm fairly busy today working on #2410, but I can try and take a look at that tomorrow. In the meantime let me know if I can answer any qs

@oliverqx
Copy link
Contributor Author

oliverqx commented Apr 2, 2024

@trajan0x today im pretty much free, will be looking into that bug. I think Its got to do with ct.HasPath() might need to do some edits there, will keep you updated

@trajan0x
Copy link
Contributor

trajan0x commented Apr 2, 2024

Appreciate it

@oliverqx
Copy link
Contributor Author

oliverqx commented Apr 2, 2024

@trajan0x Actually I realized its not a bug.

I created this PR in my own sanguine replica: https://github.com/oliverqx/sanguine-git-changes/pull/4

And I added an fmt.Println to all ./contrib/promexporter dependencies to my image and it looks like ./ethergo/submitter is one of the dependencies. Keep in mind that this array a contains all transitive dependencies, so manually following it might be quite complicated.

Screenshot 2024-04-02 at 16 44 41

Edit:

To manually folllow:

  1. contrib/promexporter/exporters imports services/omnirpc/client link
  2. services/omnirpc/client imports ethergo/submitter link

Current solution will render a module as changed if any of the packages within its dependency tree is changed

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Review Status

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between a33e94c and 12dc6f5.
Files selected for processing (1)
  • contrib/git-changes-action/README.md (5 hunks)
Additional comments not posted (1)
contrib/git-changes-action/README.md (1)

97-138: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [1-138]

Review the entire documentation for clarity and consistency.
Ensure that the documentation accurately reflects the changes made in the PR, particularly the transition to package-based dependency tracking. Verify that examples and usage instructions are up-to-date and align with the new functionality introduced.

contrib/git-changes-action/README.md Outdated Show resolved Hide resolved
contrib/git-changes-action/README.md Outdated Show resolved Hide resolved
contrib/git-changes-action/README.md Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review Status

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between 12dc6f5 and 4a316fd.
Files selected for processing (1)
  • contrib/git-changes-action/main.go (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • contrib/git-changes-action/main.go

@oliverqx
Copy link
Contributor Author

oliverqx commented Apr 3, 2024

@trajan0x just checking in, I think the solution is ready. Please let me know is there's anything else I could do

@trajan0x
Copy link
Contributor

trajan0x commented Apr 3, 2024

Okay, will stage the latest build today

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

Review Status

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between 4a316fd and 39b33bf.
Files selected for processing (2)
  • contrib/git-changes-action/README.md (5 hunks)
  • contrib/git-changes-action/main.go (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • contrib/git-changes-action/main.go

contrib/git-changes-action/README.md Show resolved Hide resolved
contrib/git-changes-action/README.md Show resolved Hide resolved
contrib/git-changes-action/README.md Show resolved Hide resolved
contrib/git-changes-action/README.md Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review Status

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between 39b33bf and c3ac016.
Files selected for processing (1)
  • contrib/git-changes-action/main.go (4 hunks)
Files skipped from review as they are similar to previous changes (1)
  • contrib/git-changes-action/main.go

trajan0x added a commit that referenced this pull request Apr 4, 2024
@trajan0x trajan0x mentioned this pull request Apr 4, 2024
trajan0x added a commit that referenced this pull request Apr 4, 2024
Co-authored-by: Trajan0x <trajan0x@users.noreply.github.com>
@trajan0x
Copy link
Contributor

trajan0x commented Apr 4, 2024

staged in #2444

Assuming no snafus for next day im good to gtm

@oliverqx
Copy link
Contributor Author

oliverqx commented Apr 4, 2024

sounds good, thanks!

@oliverqx
Copy link
Contributor Author

oliverqx commented Apr 5, 2024

@trajan0x once the bounty has been settled, I can provide support if anything is wrong. I know my solution is right, but nonetheless.

Was also wondering if I could get a linkedin review or a recommendation for my personal blog. Would greatly appreciate your input

@trajan0x trajan0x merged commit 38fcca1 into synapsecns:master Apr 5, 2024
3 checks passed
@trajan0x
Copy link
Contributor

trajan0x commented Apr 5, 2024

Absolutely. Wanna dm me somewhere?

@oliverqx
Copy link
Contributor Author

oliverqx commented Apr 5, 2024

can i get your discord?

@oliverqx
Copy link
Contributor Author

oliverqx commented Apr 5, 2024

@trajan0x my discord is @olxverqx, or oliverquixchan@gmail.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🙋 Bounty claim go Pull requests that update Go code size/m
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve Dependency Resolution for Workflow Optimization
2 participants