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

Linter checks go versions in Dockerfile and YAML files #8954

Merged
merged 3 commits into from
Aug 5, 2024

Conversation

ffranr
Copy link
Collaborator

@ffranr ffranr commented Jul 30, 2024

Change Description

This PR adds two checks to the linter. These checks ensure that the Go version used in Dockerfile files and YAML files are consistent and as expected.

This PR also ensures that Go version 1.22.5 is used throughout the project.

(Note that I couldn't re-open #8211 I think it's because I forced pushed to the branch before re-opening?)

Steps to Test

Steps for reviewers to follow to test the change.

Pull Request Checklist

Testing

  • Your PR passes all CI checks.
  • Tests covering the positive and negative (error paths) are included.
  • Bug fixes contain tests triggering the bug to prevent regressions.

Code Style and Documentation

📝 Please see our Contribution Guidelines for further guidance.

@ffranr ffranr requested a review from guggero July 30, 2024 01:01
@ffranr ffranr self-assigned this Jul 30, 2024
Copy link
Contributor

coderabbitai bot commented Jul 30, 2024

Important

Review skipped

Auto reviews are limited to specific labels.

Labels to auto review (1)
  • llm-review

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


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.

Copy link
Collaborator

@guggero guggero left a comment

Choose a reason for hiding this comment

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

Looks good. But it seems like the linter now crashes, due to the Golang version update...

Makefile Show resolved Hide resolved
Makefile Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
tools/Dockerfile Outdated Show resolved Hide resolved
Copy link
Collaborator

@guggero guggero left a comment

Choose a reason for hiding this comment

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

Very nice, LGTM 🎉

docs/INSTALL.md Show resolved Hide resolved
.golangci.yml Show resolved Hide resolved
Copy link
Collaborator

@yyforyongyu yyforyongyu left a comment

Choose a reason for hiding this comment

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

got this failure on my local machine,

make check-go-version

 Checking for target Go version (v1.22.5) in Dockerfile files (*Dockerfile)
./scripts/check-go-version-dockerfile.sh 1.22.5
Skipping ./tools/Dockerfile
./docker/btcd/Dockerfile is using Go version 1.22.5.
./Dockerfile is using Go version 1.22.5.
./dev.Dockerfile is using Go version 1.22.5.
./make/builder.Dockerfile is using Go version 1.22.5.
./lnrpc/Dockerfile is using Go version 1.22.5.
All Dockerfiles pass the Go version check for Go version 1.22.5.
 Checking for target Go version (v1.22.5) in YAML files (*.yaml, *.yml)
./scripts/check-go-version-yaml.sh 1.22.5
Error: ./.github/workflows/release.yaml specifies Go version '', but not version '1.22.5'.
make: *** [check-go-version-yaml] Error 1

Makefile Outdated
@$(call print, "Linting source.")
$(DOCKER_TOOLS) golangci-lint run -v $(LINT_WORKERS)

#? lint: Run static code analysis
lint: lint-source check-go-version
Copy link
Collaborator

Choose a reason for hiding this comment

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

should these two be switched to give much quicker feedback? I also wonder if it's better to have an independent version check in the CI, but I guess not since the linter also depends on the go version?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've switched these around.

I'm not sure if we need an independent check. Would be good to have a single Go version to update for all checks. Depends how independent you mean.

@ffranr ffranr force-pushed the check-go-versions branch 2 times, most recently from 536cb87 to f108730 Compare July 31, 2024 13:38
@ffranr
Copy link
Collaborator Author

ffranr commented Jul 31, 2024

got this failure on my local machine,

make check-go-version

 Checking for target Go version (v1.22.5) in Dockerfile files (*Dockerfile)
./scripts/check-go-version-dockerfile.sh 1.22.5
Skipping ./tools/Dockerfile
./docker/btcd/Dockerfile is using Go version 1.22.5.
./Dockerfile is using Go version 1.22.5.
./dev.Dockerfile is using Go version 1.22.5.
./make/builder.Dockerfile is using Go version 1.22.5.
./lnrpc/Dockerfile is using Go version 1.22.5.
All Dockerfiles pass the Go version check for Go version 1.22.5.
 Checking for target Go version (v1.22.5) in YAML files (*.yaml, *.yml)
./scripts/check-go-version-yaml.sh 1.22.5
Error: ./.github/workflows/release.yaml specifies Go version '', but not version '1.22.5'.
make: *** [check-go-version-yaml] Error 1

@yyforyongyu thanks for the review! I think this might be a difference in sed between linux and mac. I've updated the use of sed in the latest commits, please let me know if that works on your computer.

@ffranr ffranr requested a review from yyforyongyu July 31, 2024 13:40
Copy link
Collaborator

@yyforyongyu yyforyongyu left a comment

Choose a reason for hiding this comment

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

Stil has an error tho - will figure out how to parse it in mac

local yamlfile="$1"
local required_go_version="$2"

# Use grep to find lines with 'go:'. The grep exist status is ignored.
Copy link
Collaborator

Choose a reason for hiding this comment

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

do we use the prefix go:? I thought we always use GO_VERSION:

Copy link
Collaborator Author

@ffranr ffranr Jul 31, 2024

Choose a reason for hiding this comment

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

Good point. I think the only example is in .golangci.yml:

  staticcheck:
    go: "1.21"
    checks: ["-SA1019"]

And I don't think even care about that case. See: #8954 (comment)

Do we keep this check anyway because it might come into play and be useful later?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok, in the latest commits, I've bumped the Go version in .golangci.yml. And I've modified the lint check so that it's included in the check.

# GO_VERSION: '1.21.0'
# GO_VERSION: 1.21.0
# GO_VERSION:1.21.0
# GO_VERSION:1.21.0
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: remove the spaces

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

the leading spaces here are intentional. We need to be robust to leading white space.

Renamed the Makefile variable `GO_VERSION` to `ACTIVE_GO_VERSION` for
improved clarity. This change also frees up the name `GO_VERSION` to be
used for defining the global Go version for reproducible binaries in a
subsequent commit.
Copy link
Collaborator

@yyforyongyu yyforyongyu left a comment

Choose a reason for hiding this comment

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

I got this error,

Checking for target Go version (v1.22.5) in YAML files (*.yaml, *.yml)
./scripts/check-go-version-yaml.sh 1.22.5
grep: invalid option -- P

By applying this diff it now works on a mac,

diff --git a/scripts/check-go-version-yaml.sh b/scripts/check-go-version-yaml.sh
index a8469abdc..af4bdbfa8 100755
--- a/scripts/check-go-version-yaml.sh
+++ b/scripts/check-go-version-yaml.sh
@@ -13,11 +13,11 @@ check_go_version_yaml() {
     if [ -n "$go_lines" ]; then
         # Extract the Go version from the file's lines. Example matching strings:
         # go: "1.21.0"
-        local extracted_go_version=$(echo "$go_lines" | grep -oP '^\s*go:\s*"\K[^"]+')
+        local extracted_go_version=$(echo "$go_lines" | sed -n 's/.*go: "\([^"]*\)".*/\1/p')
 
         # Check if the extracted Go version matches the required version.
         if [ "$extracted_go_version" != "$required_go_version" ]; then
-            echo "Error: $yamlfile specifies Go version '$extracted_go_version', but not version '$required_go_version'."
+            echo "Error finding pattern 'go:': $yamlfile specifies Go version '$extracted_go_version', but not version '$required_go_version'."
             exit 1
         else
             echo "$yamlfile specifies Go version $required_go_version."
@@ -43,11 +43,11 @@ check_go_version_env_variable() {
         # GO_VERSION: 1.21.0
         # GO_VERSION:1.21.0
         #   GO_VERSION:1.21.0
-        local extracted_go_version=$(echo "$go_lines" | sed -n 's/^[[:space:]]*GO_VERSION:[[:space:]]*\(['"'"'"]\?\)\([0-9]\+\.[0-9]\+\.[0-9]\+\)\(['"'"'"]\?\)/\2/p')
+        local extracted_go_version=$(echo "$go_lines" | sed -n 's/.*GO_VERSION[: ]*["'\'']*\([0-9.]*\).*/\1/p')
 
         # Check if the extracted Go version matches the required version.
         if [ "$extracted_go_version" != "$required_go_version" ]; then
-            echo "Error: $yamlfile specifies Go version '$extracted_go_version', but not version '$required_go_version'."
+            echo "Error finding pattern 'GO_VERSION:': $yamlfile specifies Go version '$extracted_go_version', but not version '$required_go_version'."
             exit 1
         else
             echo "$yamlfile specifies Go version $required_go_version."

Implemented linter scripts to ensure consistency of the Go version
specified in Dockerfiles and YAML files. These scripts verify that the
Go version used across these files is uniform, enhancing maintainability
and reducing configuration errors.

This commit also introduces a `GO_VERSION` Makefile variable to control
the Go version used throughout the project.
@ffranr
Copy link
Collaborator Author

ffranr commented Aug 1, 2024

Thanks for the mac fix @yyforyongyu !

@ffranr ffranr requested a review from yyforyongyu August 1, 2024 13:43
Copy link
Collaborator

@yyforyongyu yyforyongyu left a comment

Choose a reason for hiding this comment

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

LGTM🙏

@guggero guggero merged commit 546c8eb into lightningnetwork:master Aug 5, 2024
19 of 21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants