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

Update test.yml Github Action to report coverage to sonarcloud #8712

Closed
wants to merge 2 commits into from

Conversation

deruelle
Copy link
Contributor

Update: #8711

What is the purpose of the change

Update test.yml Github Action to report code and test coverage to sonarcloud

Documentation and Release Note

  • Does this pull request introduce a new feature or user-facing behavior changes? No
  • Changelog entry added to Unreleased section of CHANGELOG.md? Not needed as doesn't affect codebase

Where is the change documented?

  • N/A

@github-actions github-actions bot added the T:CI label Sep 17, 2024
@PaddyMc PaddyMc closed this Sep 23, 2024
@PaddyMc PaddyMc reopened this Sep 23, 2024
@PaddyMc PaddyMc marked this pull request as ready for review September 24, 2024 11:31
@PaddyMc PaddyMc requested a review from a team as a code owner September 24, 2024 11:31
Copy link
Contributor

coderabbitai bot commented Sep 24, 2024

Walkthrough

The changes introduce enhancements to the testing workflow in the GitHub Actions configuration. A new job, sonarCloudTrigger, is added to execute after the main testing job, enabling the analysis of code quality using SonarCloud. The testing process is updated to include JSON output and a code coverage report, which are then utilized in the SonarCloud analysis.

Changes

File Path Change Summary
.github/workflows/test.yml Added a new job sonarCloudTrigger for SonarCloud analysis; modified testing commands to include JSON output and code coverage reporting.

Sequence Diagram(s)

sequenceDiagram
    participant Developer
    participant GitHub Actions
    participant SonarCloud

    Developer->>GitHub Actions: Push code changes
    GitHub Actions->>GitHub Actions: Run tests with go test -json
    GitHub Actions->>GitHub Actions: Generate coverage report
    GitHub Actions->>SonarCloud: Trigger sonarCloudTrigger job
    SonarCloud-->>GitHub Actions: Analyze code quality
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>, 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
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: 1

Outside diff range and nitpick comments (2)
.github/workflows/test.yml (2)

106-119: LGTM! Good addition of code coverage reporting.

The changes to the go job look good. Here are the key improvements:

  1. Adding the -json flag to the go test command (line 106) is beneficial for machine-readable output.
  2. Creating a separate step for code coverage report (lines 108-112) is necessary as -race and -covermode=count are incompatible.
  3. Archiving the code coverage results (lines 113-119) is crucial for the new SonarCloud integration.

Consider adding a comment explaining why we're running the tests twice (once with -race and once for coverage). This will help future maintainers understand the reasoning behind these steps.

Tools
actionlint

109-109: shellcheck reported issue in this script: SC2001:style:1:11: See if you can use ${variable//search/replace} instead

(shellcheck)


109-109: shellcheck reported issue in this script: SC2046:warning:1:16: Quote this to prevent word splitting

(shellcheck)


109-109: shellcheck reported issue in this script: SC2005:style:1:16: Useless echo? Instead of 'echo $(cmd)', just use 'cmd'

(shellcheck)


109-109: shellcheck reported issue in this script: SC2086:info:3:157: Double quote to prevent globbing and word splitting

(shellcheck)


109-112: Consider addressing shellcheck warnings for improved script robustness.

While not critical, addressing the following shellcheck warnings could improve the script's readability and robustness:

  1. Use ${variable//search/replace} instead of sed for simple string replacements.
  2. Quote the command substitution to prevent word splitting.
  3. Avoid useless echo by directly using the command output.
  4. Use double quotes to prevent globbing and word splitting.

Here's an improved version of the script addressing these issues:

      - name: Code coverage report creation
        run: |
          VERSION=${GITHUB_REF#refs/tags/v}
          VERSION=${VERSION:-$GITHUB_SHA}
          TESTS=$(cat "pkgs.txt.part.${{ matrix.part }}")
          VERSION="$VERSION" SKIP_WASM_WSL_TESTS="false" go test -coverprofile=coverage.out -covermode=count -json -mod=readonly -tags='ledger test_ledger_mock norace' $TESTS > report.json

This version:

  1. Uses parameter expansion instead of sed.
  2. Removes the unnecessary echo.
  3. Properly quotes variables to prevent word splitting.
  4. Still uses $TESTS unquoted as it's intended to be word-split for multiple test packages.
Tools
actionlint

109-109: shellcheck reported issue in this script: SC2001:style:1:11: See if you can use ${variable//search/replace} instead

(shellcheck)


109-109: shellcheck reported issue in this script: SC2046:warning:1:16: Quote this to prevent word splitting

(shellcheck)


109-109: shellcheck reported issue in this script: SC2005:style:1:16: Useless echo? Instead of 'echo $(cmd)', just use 'cmd'

(shellcheck)


109-109: shellcheck reported issue in this script: SC2086:info:3:157: Double quote to prevent globbing and word splitting

(shellcheck)

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 133d623 and 629cab4.

Files selected for processing (1)
  • .github/workflows/test.yml (2 hunks)
Additional context used
actionlint
.github/workflows/test.yml

109-109: shellcheck reported issue in this script: SC2001:style:1:11: See if you can use ${variable//search/replace} instead

(shellcheck)


109-109: shellcheck reported issue in this script: SC2046:warning:1:16: Quote this to prevent word splitting

(shellcheck)


109-109: shellcheck reported issue in this script: SC2005:style:1:16: Useless echo? Instead of 'echo $(cmd)', just use 'cmd'

(shellcheck)


109-109: shellcheck reported issue in this script: SC2086:info:3:157: Double quote to prevent globbing and word splitting

(shellcheck)

Additional comments not posted (1)
.github/workflows/test.yml (1)

Line range hint 1-204: Overall, good improvements to the CI pipeline with code coverage and SonarCloud integration.

The changes to this workflow file significantly enhance the CI pipeline by introducing code coverage reporting and SonarCloud integration. These additions will provide better insights into test coverage and code quality, which is valuable for maintaining a robust codebase.

Key improvements:

  1. Addition of code coverage reporting in the go job.
  2. New sonarCloudTrigger job for SonarCloud analysis.

While there are a few minor suggestions for improvement, the overall structure and implementation of these changes are sound. Once the projectBaseDir issue is resolved and the script improvements are considered, this will be a solid enhancement to your CI process.

Comment on lines +172 to +204
sonarCloudTrigger:
needs: go
name: SonarCloud Trigger
runs-on: ubuntu-latest
steps:
- name: Clone Repository
uses: actions/checkout@master
with:
fetch-depth: 0
- name: Download code coverage results
uses: actions/download-artifact@v4
with:
name: code-coverage-report
#path: app
- name: Analyze with SonarCloud
uses: sonarsource/sonarcloud-github-action@master
with:
projectBaseDir: app
args: >
-Dsonar.projectKey=osmosis-labs-osmosis
-Dsonar.organization=osmosis-labs-polaris
-Dsonar.host.url=https://sonarcloud.io
-Dsonar.go.coverage.reportPaths=coverage.out
-Dsonar.go.tests.reportPaths=report.json
-Dsonar.sources=.
-Dsonar.tests=.
-Dsonar.test.inclusions=**/*_test.go,**/testdata/**
-Dsonar.language=go
-Dsonar.go.exclusions=**/vendor/**,**/*_mock.go
-Dsonar.coverage.exclusions=**/mock*/**,**/mock*.go,commands/debug.go
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

⚠️ Potential issue

Update SonarCloud projectBaseDir to the repository root.

The app directory does not contain a go.mod file and includes multiple Go source files across various subdirectories. This suggests that app is not a standalone Go module but part of a larger monorepo structure.

Action Required:

  • Change projectBaseDir from app to . in the SonarCloud configuration to ensure that the entire repository is analyzed correctly.
with:
  projectBaseDir: .

This adjustment will help SonarCloud accurately assess the project's structure and dependencies.

Analysis chain

Good addition of SonarCloud integration, but check the projectBaseDir setting.

The new sonarCloudTrigger job is well-structured and comprehensive. It correctly depends on the go job, ensuring that code coverage results are available. The SonarCloud configuration covers essential aspects like coverage paths, test paths, and exclusions.

However, there's a potential issue:

The projectBaseDir is set to app (line 189), but it's not clear if this is the correct base directory for your project. This setting determines the root directory for SonarCloud analysis. If your project structure doesn't have an app directory at the root, this could lead to incorrect analysis results.

Please verify if app is the correct base directory. If not, you should adjust this setting to match your project structure, typically using . for the root of the repository.

To confirm the correct project structure, you can run:

This will display the directory structure, helping you determine the correct projectBaseDir setting.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check the project structure
ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//  /g' -e 's/^/    /' -e 's/-/|/'

Length of output: 8680


Script:

#!/bin/bash
# Check for go.mod in app directory
if [ -f app/go.mod ]; then
    echo "go.mod found in app directory."
else
    echo "go.mod not found in app directory."
fi

# List Go source files in app directory
echo "Listing Go source files in app:"
rg --files --glob "*.go" app

Length of output: 3406

@PaddyMc PaddyMc closed this Oct 2, 2024
@PaddyMc PaddyMc reopened this Oct 2, 2024
Copy link
Contributor

This pull request has been automatically marked as stale because it has not had any recent activity. It will be closed if no further activity occurs. Thank you!

@github-actions github-actions bot added the Stale label Oct 11, 2024
@github-actions github-actions bot closed this Oct 14, 2024
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.

2 participants