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

Output and consider Go toolchain version, too #156

Merged
merged 2 commits into from
Jun 19, 2024
Merged

Output and consider Go toolchain version, too #156

merged 2 commits into from
Jun 19, 2024

Conversation

scop
Copy link
Contributor

@scop scop commented Jun 18, 2024

Closes #154

Summary by CodeRabbit

  • New Features

    • Enhanced the check command to verify both the latest version and the build toolchain of the installed binary.
    • Improved the update command to utilize the current Go toolchain for updates.
  • Bug Fixes

    • Modified error handling in the import command.
  • Tests

    • Updated test cases to reflect changes in output messages and remove specific prefixes for better readability.
  • Dependencies

    • Added github.com/shogo82148/pointer as a new dependency.
  • Internal Improvements

    • Updated internal logic for managing package and Go toolchain versions.

Copy link
Contributor

coderabbitai bot commented Jun 18, 2024

Warning

Review failed

The pull request is closed.

Walkthrough

The recent code changes enhance the check and update commands to include the verification and update of the Go toolchain version used to build binaries. These checks ensure binaries are rebuilt with the latest Go toolchain if available, even when the binary version itself is unchanged. This update includes changes to command definitions, adds new methods for managing version information, and refines testing and informational outputs for better user experience.

Changes

File Change Summary
cmd/check.go, cmd/update.go Enhanced check and update commands to verify and use the current Go toolchain during checks and updates.
cmd/import.go Refactored runImport function to remove unused parameters and handle errors differently.
cmd/root_test.go, internal/print/... Updated tests and printing logic to remove specific prefixes from informational messages.
go.mod Added new dependency github.com/shogo82148/pointer v1.3.0.
internal/goutil/examples_test.go Modified ExampleIsAlreadyUpToDate to check for both package and Go version updates.
internal/goutil/goutil.go Introduced GoVersion field in Package struct, updated methods for version handling, added new functions for retrieving and comparing Go toolchain versions.
internal/config/config.go Updated ReadConfFile function to handle Go versions using new pointer package.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CheckCmd
    participant GoUtil
    participant UpdateCmd
    
    Note over GoUtil,UpdateCmd: Updated Go toolchain available

    User->>CheckCmd: Execute check command
    CheckCmd->>GoUtil: Check latest version and build toolchain
    GoUtil->>CheckCmd: Return version and Go toolchain status
    CheckCmd->>User: Inform if binary needs updating or toolchain refresh
    
    User->>UpdateCmd: Execute update command
    UpdateCmd->>GoUtil: Use current Go toolchain to update
    GoUtil->>UpdateCmd: Return updated status
    UpdateCmd->>User: Confirm update
Loading

Assessment against linked issues

Objective Addressed Explanation
Ensure binaries are rebuilt with the latest Go toolchain if available (#154)
Check both package version and Go toolchain version when running check (#154)
Update documentation to reflect these new checks and updates The changes summary does not indicate documentation updates were made.

Poem

In the realm of code where binaries play,
Updates now occur in a grand new way.
Check and rebuild with the latest toolchain,
Ensuring our software remains without stain.
Tools now stronger, fresh and bright,
Built with Go's latest, every byte.


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 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/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.

@scop
Copy link
Contributor Author

scop commented Jun 18, 2024

@nao1215 feel free to push to this branch, I'll probably get to it eventually to finish this but it might take a while.

@nao1215 nao1215 marked this pull request as ready for review June 18, 2024 17:11
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: 2

Outside diff range and nitpick comments (3)
cmd/check.go (1)

Line range hint 143-143: Avoid using magic numbers in the code to enhance maintainability.

Consider defining a constant for the magic number 11 used in the indentation:

- strings.Repeat(" ", 11) +
+ const indentSpace = 11
+ strings.Repeat(" ", indentSpace) +
internal/goutil/goutil_test.go (2)

Line range hint 423-424: Ensure to handle potential errors from environment variable setting.

- t.Setenv("GOBIN", "")
- t.Setenv("GOPATH", "")
+ if err := t.Setenv("GOBIN", ""); err != nil {
+     t.Fatal("Failed to set GOBIN:", err)
+ }
+ if err := t.Setenv("GOPATH", ""); err != nil {
+     t.Fatal("Failed to set GOPATH:", err)
+ }

Handling errors from t.Setenv ensures that the test setup is correctly configured and prevents false negatives in the test environment.


Line range hint 166-166: Consider defining a constant for repeated strings like echo.

+ const mockGoCommand = "echo"

- goExe = "echo"
+ goExe = mockGoCommand

Using a constant for repeated string values like echo used in multiple test cases enhances maintainability and readability by centralizing the change to one location.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between ca700e0 and 060888a.

Files selected for processing (5)
  • cmd/check.go (2 hunks)
  • cmd/update.go (1 hunks)
  • internal/goutil/examples_test.go (1 hunks)
  • internal/goutil/goutil.go (6 hunks)
  • internal/goutil/goutil_test.go (4 hunks)
Additional context used
golangci-lint
cmd/check.go

143-143: Magic number: 11, in detected (gomnd)

internal/goutil/examples_test.go

142-142: tests: ExampleInstall refers to unknown identifier: Install (govet)


163-163: tests: ExampleIsAlreadyUpToDate refers to unknown identifier: IsAlreadyUpToDate (govet)

internal/goutil/goutil.go

336-336: string unknown has 5 occurrences, make it a constant (goconst)


160-160: ifElseChain: rewrite if-else to switch statement (gocritic)


185-185: ifElseChain: rewrite if-else to switch statement (gocritic)


23-23: goExe is a global variable (gochecknoglobals)


25-25: keyGoBin is a global variable (gochecknoglobals)


27-27: keyGoPath is a global variable (gochecknoglobals)


29-29: osMkdirTemp is a global variable (gochecknoglobals)

internal/goutil/goutil_test.go

423-423: Error return value of os.Setenv is not checked (errcheck)


424-424: Error return value of os.Setenv is not checked (errcheck)


166-166: string echo has 3 occurrences, make it a constant (goconst)

Additional comments not posted (7)
cmd/check.go (1)

20-23: Updated command description to reflect the enhanced functionality of checking both the binary version and the Go toolchain version.

cmd/update.go (1)

30-31: Updated command description to clarify that updates will use the current installed Go toolchain.

internal/goutil/examples_test.go (1)

164-182: The test example has been updated to include checks for both the package version and the Go version.

internal/goutil/goutil.go (1)

52-53: Added GoVersion field to the Package struct to store the Go toolchain version.

internal/goutil/goutil_test.go (3)

286-337: The updated TestIsAlreadyUpToDate_golden function effectively captures the new requirement to consider both the package version and the Go toolchain version. The test cases are comprehensive, covering regular, irregular, and compatibility scenarios. This ensures robustness in the functionality to check if a package is up-to-date considering both the software and the Go version.


560-563: The addition of GoVersion to the Package struct in these test functions (TestPackage_CurrentToLatestStr_not_up_to_date and TestPackage_VersionCheckResultStr_not_up_to_date) is a welcome change, aligning with the new feature requirements. This modification allows the functions to check both the package version and the Go toolchain version, enhancing the utility and accuracy of the version checks.

Also applies to: 584-587


599-620: The function TestPackage_VersionCheckResultStr_go_not_up_to_date correctly implements the new logic to compare the current Go version with the installed version. This is crucial for ensuring that the software is running on the latest Go toolchain, which can include important performance improvements and bug fixes.

@@ -92,7 +93,7 @@ func doCheck(pkgs []goutil.Package, cpus int) int {
err = fmt.Errorf(" %s %w", p.Name, err)
}
p.Version.Latest = latestVer
if !goutil.IsAlreadyUpToDate(*p.Version) {
if !p.IsAlreadyUpToDate() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure the mutex lock is held for the shortest time necessary to avoid potential performance bottlenecks.

Consider moving the mu.Unlock() call immediately after the append operation to minimize the critical section:

mu.Lock()
needUpdatePkgs = append(needUpdatePkgs, p)
mu.Unlock()
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if !p.IsAlreadyUpToDate() {
if !p.IsAlreadyUpToDate() {
mu.Lock()
needUpdatePkgs = append(needUpdatePkgs, p)
mu.Unlock()
}

Comment on lines +79 to +92
if p.IsAlreadyUpToDate() {
return "Already up-to-date: " + color.GreenString(p.Version.Latest) + " / " + color.GreenString(p.GoVersion.Current)
}
return color.GreenString(p.Version.Current) + " to " + color.YellowString(p.Version.Latest)
var ret string
if p.Version.Current != p.Version.Latest {
ret += color.GreenString(p.Version.Current) + " to " + color.YellowString(p.Version.Latest)
}
if p.GoVersion.Current != p.GoVersion.Latest {
if len(ret) != 0 {
ret += ", "
}
ret += color.GreenString(p.GoVersion.Current) + " to " + color.YellowString(p.GoVersion.Latest)
}
return ret
Copy link
Contributor

Choose a reason for hiding this comment

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

Enhanced the string representation functions to include both package and Go toolchain versions.

However, consider simplifying the logic to improve readability and maintainability.

Refactor the repeated conditional logic into a helper function:

func formatVersionChange(current, latest string) string {
	if current == latest {
		return color.GreenString(current)
	}
	return "current: " + color.GreenString(current) + ", latest: " + color.YellowString(latest)
}

Also applies to: 97-123

Some tests stopped passing due to the addition of a specification to
check the Go version. The tests that do not pass were examples for
developers, so they have been cleanly removed.
@nao1215
Copy link
Owner

nao1215 commented Jun 19, 2024

@scop
Thank you for the Pull Request.
I have made corrections to ensure the unit tests pass.

@nao1215 nao1215 merged commit 26d92e8 into nao1215:main Jun 19, 2024
19 checks passed
@scop scop deleted the feat/go-toolchain-version branch June 22, 2024 06:02
@scop
Copy link
Contributor Author

scop commented Jun 22, 2024

Thanks!

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.

Feature: rebuild with newer toolchain if available, even if version same
2 participants