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

chores: update golangci-lint config & add sonarcloud #44

Merged
merged 2 commits into from
Oct 12, 2024

Conversation

creativeprojects
Copy link
Owner

@creativeprojects creativeprojects commented Oct 12, 2024

  • update golangci-lint config
  • add sonarcloud config
  • update GitHub action to build with go 1.23

Summary by CodeRabbit

  • New Features

    • Introduced a new job for SonarCloud analysis to enhance code quality checks.
    • Added steps to archive code coverage results for better tracking.
  • Bug Fixes

    • Updated build configurations to improve compatibility and performance across different operating systems.
  • Documentation

    • Added a new configuration file for SonarQube project settings, detailing project organization and source file specifications.
  • Chores

    • Updated .gitignore to exclude the new coverage report file.
    • Renamed coverage file variable for consistency across the project.

Copy link

coderabbitai bot commented Oct 12, 2024

Walkthrough

The pull request introduces several changes to the build and configuration files for the go-selfupdate project. Key modifications include updating the Go version in the workflow, refining the operating system matrix, adding steps for code coverage archiving, and integrating SonarCloud analysis. Additionally, the .gitignore file now excludes coverage.txt, while the .golangci.yml file has undergone significant changes to its linter configuration. The Makefile has been updated to reflect a new coverage file name and includes new linting targets. Lastly, a new sonar-project.properties file has been created for SonarQube configuration.

Changes

File Change Summary
.github/workflows/build.yml Updated Go version to 1.23, changed macOS matrix to macos-latest, added artifact upload step, and introduced sonarCloudTrigger job.
.gitignore Added coverage.txt to the ignore list.
.golangci.yml Removed linters-settings, updated linters to include new linters, removed enable-all and fast options.
Makefile Renamed COVERAGE_FILE from coverage.out to coverage.txt, added .PHONY targets for lint and fix.
codecov.yml Updated after_n_builds parameter from 6 to 3 in both notify and comment sections.
sonar-project.properties Added configuration for SonarQube, including project key, name, version, source files, and coverage report path.
update/hide_noop.go Updated build constraint syntax from // +build !windows to //go:build !windows.

Sequence Diagram(s)

sequenceDiagram
    participant CI as CI/CD Pipeline
    participant Build as Build Job
    participant Coverage as Coverage Step
    participant Sonar as SonarCloud Trigger

    CI->>Build: Start Build
    Build->>Coverage: Archive Coverage Results
    Coverage->>Build: Coverage Archived
    Build->>Sonar: Trigger SonarCloud Analysis
    Sonar->>Build: Analysis Complete
Loading

🐰 In the meadow, changes bloom,
A coverage file finds its room.
Linting paths now brightly shine,
Sonar's watch, a friend divine.
With Go updated, we take flight,
Hopping forward, all feels right! 🌼


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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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

Copy link

codecov bot commented Oct 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 76.99%. Comparing base (faefb9e) to head (f84b11b).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #44   +/-   ##
=======================================
  Coverage   76.99%   76.99%           
=======================================
  Files          26       26           
  Lines        1091     1091           
=======================================
  Hits          840      840           
  Misses        211      211           
  Partials       40       40           
Flag Coverage Δ
unittests 76.99% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

@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 (5)
.golangci.yml (1)

1-22: Significant update to linting configuration

The changes to the .golangci.yml file represent a substantial shift in the project's linting strategy. The previous configuration has been replaced with a new set of enabled linters, which could lead to improved code quality and consistency. Here's a breakdown of the changes and their potential impact:

  1. The new configuration enables 21 specific linters, replacing the previous enable-all: true approach. This targeted selection allows for more control over the linting process.

  2. Several new linters have been added that focus on different aspects of code quality:

    • Security: gosec
    • Performance: noctx, bodyclose
    • Code style and consistency: asasalint, asciicheck, errname, misspell, nilnil, predeclared, sloglint
    • Potential bugs: contextcheck, reassign, spancheck
  3. The removal of the linters-settings section suggests that default settings are being used for all linters. This might be intentional for simplicity, but it could be worth considering custom settings for some linters to better suit the project's needs.

  4. The fast option has been removed, which might increase linting time but provide more thorough checks.

These changes are likely to improve the overall code quality and catch more potential issues. However, be prepared for an increase in linting errors when first applying these changes to the existing codebase.

Consider the following recommendations to further enhance the linting configuration:

  1. Add custom settings for specific linters in the linters-settings section. For example, you might want to adjust the complexity threshold for maintidx or configure specific checks for gosec.

  2. If there are any project-specific patterns that should be ignored, consider adding them to the issues.exclude section.

  3. Evaluate the need for the run.tests option, which was present in the previous configuration but is now removed. If running linters on test files is important for your project, you might want to re-add this option.

  4. Consider adding comments in the file to explain why certain linters were chosen or excluded, which can be helpful for future maintenance.

Would you like me to provide examples of custom settings for any specific linters?

Makefile (2)

55-60: LGTM: New lint target added.

The addition of a lint target that runs golangci-lint for multiple operating systems (Darwin, Linux, Windows) is excellent. This will help catch platform-specific issues early.

Consider parameterizing the GOOS values to make the target more maintainable:

GOOS_VALUES := darwin linux windows

lint:
    @echo "[*] $@"
    $(foreach os,$(GOOS_VALUES),GOOS=$(os) golangci-lint run;)

This approach would make it easier to add or remove operating systems in the future.


62-69: LGTM: New fix target added.

The addition of a fix target that runs go mod tidy, go fix, and golangci-lint --fix for multiple operating systems is excellent. This will help automatically correct various issues and keep the codebase up-to-date.

Similar to the lint target, consider parameterizing the GOOS values:

GOOS_VALUES := darwin linux windows

fix:
    @echo "[*] $@"
    $(GOCMD) mod tidy
    $(GOCMD) fix ./...
    $(foreach os,$(GOOS_VALUES),GOOS=$(os) golangci-lint run --fix;)

This approach would make it easier to maintain the list of operating systems in the future.

.github/workflows/build.yml (2)

69-79: Well-structured SonarCloud job setup.

The steps for the SonarCloud job are well-structured:

  1. Cloning the repository with full history is recommended for accurate SonarCloud analysis.
  2. Downloading code coverage results is necessary for processing.
  3. Displaying the structure of downloaded files can be helpful for debugging.

Consider adding a conditional step to check if the code coverage artifacts exist before attempting to download them. This can prevent potential errors if the build job fails to generate coverage files.

- name: Check for code coverage artifacts
  id: check_artifacts
  run: |
    artifacts=$(gh api repos/${{ github.repository }}/actions/artifacts --jq '.artifacts[] | select(.name | startswith("code-coverage-report-")) | .id')
    echo "artifacts_exist=${{ artifacts != '' }}" >> $GITHUB_OUTPUT
  env:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Download code coverage results
  if: steps.check_artifacts.outputs.artifacts_exist == 'true'
  uses: actions/download-artifact@v4

81-85: Correct setup for SonarCloud analysis.

The SonarCloud analysis step is correctly configured:

  • It uses the official SonarCloud GitHub action.
  • Both GITHUB_TOKEN and SONAR_TOKEN are correctly used as environment variables.

Consider adding a comment explaining the purpose of each token for better maintainability:

env:
  # Required for SonarCloud to authenticate with GitHub
  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  # Required for SonarCloud to authenticate and send analysis results
  SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between faefb9e and f84b11b.

📒 Files selected for processing (7)
  • .github/workflows/build.yml (2 hunks)
  • .gitignore (1 hunks)
  • .golangci.yml (1 hunks)
  • Makefile (3 hunks)
  • codecov.yml (1 hunks)
  • sonar-project.properties (1 hunks)
  • update/hide_noop.go (1 hunks)
✅ Files skipped from review due to trivial changes (3)
  • .gitignore
  • sonar-project.properties
  • update/hide_noop.go
🧰 Additional context used
🔇 Additional comments (5)
Makefile (3)

44-44: LGTM: Clean target updated correctly.

The clean target has been properly updated to remove coverage.txt instead of coverage.out, maintaining consistency with the COVERAGE_FILE variable change.


Line range hint 1-69: Overall, excellent improvements to the Makefile.

The changes to this Makefile significantly enhance the project's build process, linting capabilities, and code maintenance tools. The updates to the coverage file naming and the addition of lint and fix targets for multiple operating systems are particularly noteworthy. These improvements will contribute to better code quality and easier maintenance of the project.


15-15: LGTM: Coverage file name updated.

The change from coverage.out to coverage.txt is good. The .txt extension is more generic and potentially more compatible with various tools.

To ensure this change doesn't break any existing processes, please run the following script:

.github/workflows/build.yml (2)

57-61: Good addition: Archiving code coverage results.

The new step to archive code coverage results is a valuable addition to the workflow. It allows for easy access to coverage data for later analysis or comparison. The use of the matrix OS in the artifact name is a good practice for distinguishing between different environments.


63-67: Excellent addition: SonarCloud integration.

The new 'sonarCloudTrigger' job is a valuable addition to the workflow. Integrating SonarCloud analysis helps maintain code quality. The condition to run only on non-pull request events is a good practice to avoid duplicate analysis.

codecov.yml Show resolved Hide resolved
.github/workflows/build.yml Show resolved Hide resolved
@creativeprojects creativeprojects merged commit 29f7d50 into main Oct 12, 2024
7 checks passed
@creativeprojects creativeprojects deleted the chores/sonarcloud branch October 12, 2024 21:54
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.

1 participant