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

chore(schema/testing): upgrade to go 1.23 iterators #21282

Merged
merged 8 commits into from
Aug 15, 2024

Conversation

aaronc
Copy link
Member

@aaronc aaronc commented Aug 13, 2024

Description

This PR upgrades some of the code in schema/testing to use go 1.23 iterators, mainly to demonstrate the use of go 1.23 and these iterators. It also upgrades linting CI to support go 1.23.

The code was already prepared to use the iterator API, go 1.23 just wasn't stable yet so this is an easy refactor.


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title, you can find examples of the prefixes below:
  • confirmed ! in the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • updated the relevant documentation or specification, including comments for documenting Go code
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

Please see Pull Request Reviewer section in the contributing guide for more information on how to review a pull request.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic, API design and naming, documentation is accurate, tests and test coverage

Summary by CodeRabbit

  • Chores
    • Updated Go version in workflow files to improve build and testing environments.
    • Changed Go version in module file for compatibility with new features and improvements.
  • Refactor
    • Enhanced error handling and code readability by replacing callback mechanisms with straightforward loop structures in various functions.

Copy link
Contributor

coderabbitai bot commented Aug 13, 2024

Walkthrough

Walkthrough

The primary changes in this update include upgrading the Go version across multiple workflow files and the Go module, which enhances the development environment with new features and improvements from Go 1.23. Additionally, significant refactoring was made in the DiffAppStates, DiffModuleStates, and DiffObjectCollections functions, transitioning from callback mechanisms to more streamlined loop structures. This refactor improves error handling and overall code readability while preserving the original functionality.

Changes

Files Change Summary
.github/workflows/lint.yml, .github/workflows/test.yml, schema/testing/go.mod Updated Go version from 1.22 to 1.23, enhancing compatibility and allowing the use of new features and improvements.
schema/testing/statesim/app_diff.go, schema/testing/statesim/module_diff.go, schema/testing/statesim/object_coll_diff.go Refactored control flow from callback functions to straightforward loops, improving readability and error handling in comparison logic.

Sequence Diagram(s)

sequenceDiagram
    participant A as Client
    participant B as Workflow
    participant C as Go Module

    A->>B: Start Build Process
    B->>C: Set Go Version 1.23
    C->>B: Go Version Set
    B->>A: Build Process Completed
Loading
sequenceDiagram
    participant A as Client
    participant B as State Comparison
    participant C as Module States
    participant D as Object Collections

    A->>B: Initiate State Comparison
    B->>C: Compare Expected Module States
    C->>B: Return Results
    B->>D: Compare Expected Object Collections
    D->>B: Return Results
    B->>A: Final Comparison Results
Loading

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.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

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

CodeRabbit Configuration 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/schema.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.

@aaronc aaronc marked this pull request as ready for review August 13, 2024 23:53
@aaronc aaronc requested a review from a team as a code owner August 13, 2024 23:53
@aaronc aaronc marked this pull request as draft August 14, 2024 00:01
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 details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 67ed23b and 1976828.

Files selected for processing (6)
  • .github/workflows/lint.yml (1 hunks)
  • .github/workflows/test.yml (1 hunks)
  • schema/testing/go.mod (1 hunks)
  • schema/testing/statesim/app_diff.go (1 hunks)
  • schema/testing/statesim/module_diff.go (1 hunks)
  • schema/testing/statesim/object_coll_diff.go (3 hunks)
Files skipped from review due to trivial changes (1)
  • schema/testing/go.mod
Additional context used
Path-based instructions (3)
schema/testing/statesim/app_diff.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

schema/testing/statesim/module_diff.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

schema/testing/statesim/object_coll_diff.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

Additional comments not posted (7)
schema/testing/statesim/app_diff.go (2)

30-33: Improved error handling in module iteration.

The use of a for loop with error logging and continuation enhances the robustness of the function by ensuring all modules are processed, even if some errors occur. This approach improves maintainability and readability.


40-44: Consistent error handling for missing modules.

The consistent handling of errors and missing modules ensures that the function can continue processing and provide comprehensive error reporting.

.github/workflows/lint.yml (1)

21-21: Upgrade to Go 1.23.

The upgrade to Go 1.23 in the workflow file ensures that the latest features and improvements of the language are utilized. This change is consistent with the PR objectives.

schema/testing/statesim/module_diff.go (2)

30-33: Improved error handling in object collection iteration.

The use of a for loop with error logging and continuation enhances the robustness of the function by ensuring all object collections are processed, even if some errors occur. This approach improves maintainability and readability.


40-44: Consistent error handling for missing object collections.

The consistent handling of errors and missing object collections ensures that the function can continue processing and provide comprehensive error reporting.

schema/testing/statesim/object_coll_diff.go (1)

Line range hint 32-64:
Refactoring improves readability and maintainability.

The switch from a callback mechanism to a for loop with continue statements simplifies the control flow and enhances readability. Ensure that this change aligns with the Uber Golang style guide, particularly regarding error handling and loop usage.

Verification successful

Refactoring aligns with Go style practices.

The use of continue statements after error checks and specific conditions is consistent with Go's idiomatic style and the Uber Golang style guide. The error handling pattern if err != nil is appropriately used throughout the code.

  • The code effectively manages control flow with continue after error checks.
  • Error handling is consistent and follows Go conventions.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify conformity with the Uber Golang style guide, focusing on error handling and loop usage.

# Test: Check for style guide conformity. Expect: No style violations.
golangci-lint run --enable=stylecheck

Length of output: 120


Script:

#!/bin/bash
# Check for the usage of `continue` within loops in the specified file.
rg --context 3 'continue' schema/testing/statesim/object_coll_diff.go

# Check for error handling patterns in the specified file.
rg 'if err != nil' schema/testing/statesim/object_coll_diff.go

Length of output: 905

.github/workflows/test.yml (1)

488-488: Go version updated to 1.23.

The update to Go 1.23 in the test-schema-testing job aligns with the PR objectives. Ensure consistency across all relevant jobs in the workflow.

@aaronc aaronc marked this pull request as ready for review August 14, 2024 13:26
@aaronc
Copy link
Member Author

aaronc commented Aug 14, 2024

Marking as R4R as linting works with go 1.23 now, but the linting errors are unrelated to the code in this PR.

@aaronc aaronc changed the title chore(schema/testing): upgrade to go 1.23 iterators chore(schema/testing): upgrade CI to go 1.23 and demonstrate iterators Aug 14, 2024
@aaronc aaronc changed the title chore(schema/testing): upgrade CI to go 1.23 and demonstrate iterators chore(schema/testing): upgrade to go 1.23 iterators Aug 14, 2024
@aaronc
Copy link
Member Author

aaronc commented Aug 14, 2024

@julienrbrt noting that there's some overlap with this and #21280

@julienrbrt
Copy link
Member

julienrbrt commented Aug 14, 2024

@julienrbrt noting that there's some overlap with this and #21280

Yes, let's merge your PR first, makes the diff there smaller.

EDIT: I'm fixing linting there so we may need that one first actually.

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 details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1976828 and 9474b3a.

Files selected for processing (2)
  • schema/testing/go.mod (1 hunks)
  • scripts/build/linting.mk (1 hunks)
Files skipped from review due to trivial changes (1)
  • scripts/build/linting.mk
Files skipped from review as they are similar to previous changes (1)
  • schema/testing/go.mod

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 details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9474b3a and fcaea75.

Files selected for processing (1)
  • schema/testing/go.mod (1 hunks)
Files skipped from review due to trivial changes (1)
  • schema/testing/go.mod

@aaronc aaronc enabled auto-merge August 15, 2024 15:26
Copy link

sonarcloud bot commented Aug 15, 2024

Quality Gate Passed Quality Gate passed for 'Cosmos SDK - Schema Testing'

Issues
1 New issue
0 Accepted issues

Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud

@aaronc aaronc added this pull request to the merge queue Aug 15, 2024
Merged via the queue into main with commit 0f39b4e Aug 15, 2024
74 of 75 checks passed
@aaronc aaronc deleted the aaronc/schema-testing-go1.23 branch August 15, 2024 21:03
alpe added a commit that referenced this pull request Aug 19, 2024
* main: (76 commits)
  docs: more app v2 renaming (#21336)
  chore: update link in disclaimer (#21339)
  refactor(x/distribution): audit QA (#21316)
  docs: rename app v2 to app di when talking about runtime v0 (#21329)
  feat(schema): specify JSON mapping (#21243)
  fix(x/authz): bring back msg response in `DispatchActions` (#21044)
  chore: fix all lint issue since golangci-lint bump (#21326)
  refactor(x/mint): v0.52 audit x/mint (#21301)
  chore: fix spelling errors (#21327)
  feat: export genesis in simapp v2 (#21199)
  fix(baseapp)!: Halt at height now does not produce the halt height block (#21256)
  refactor(scripts): remove unused variable (#21320)
  chore(schema/testing): upgrade to go 1.23 iterators (#21282)
  chore: readmes + upgrading docs (#21271)
  feat(client): add auto cli for node service (#21074)
  ci: fix github workflow vulnerable to script injection (#21304)
  build(deps): Bump github.com/prometheus/client_golang from 1.19.1 to 1.20.0 (#21307)
  build(deps): use Go 1.23 instead of Go 1.22 (#21280)
  refactor(x/auth): audit x/auth changes (#21146)
  chore: remove todo: "abstract out staking message back to staking" (#21266)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants