Skip to content

Conversation

@sabollim-silabs
Copy link
Contributor

@sabollim-silabs sabollim-silabs commented Sep 29, 2025

Description of Problem/Feature:

This pull request adds a new static analysis pipeline using SonarQube to the Jenkins integration, enabling automated quality gate checks and reporting results directly to GitHub pull requests. The main changes include introducing a dedicated SonarQube analysis stage, new Groovy and Python scripts for running the analysis and posting results, and improved handling of output and commit SHA extraction.

Description of Fix/Solution:

Static Analysis Integration:

  • Added a new Static Analysis with SonarQube stage to the Jenkins pipeline, which runs SonarQube analysis in a Docker container and posts results to GitHub PRs.
  • Implemented the publishSonarAnalysis Groovy function to configure SonarQube, execute the scanner, parse quality gate status and commit SHA, and return results for reporting.

GitHub Reporting:

  • Added send_sonar_results_to_github Groovy function to invoke a Python script that posts SonarQube results as a formatted comment to the relevant GitHub PR, handling credentials and output escaping.
  • Created send_sonar_results_to_github.py, a Python script that posts SonarQube analysis results and summary to GitHub PRs, including output truncation and error handling.

Testing Done:

  • Added DummyFunction to performance_test_commands.cpp as a simple function for static analysis validation, ensuring the pipeline can analyze code without issues.
  • test static analysis #89

Copilot AI review requested due to automatic review settings September 29, 2025 04:24
@github-actions
Copy link

github-actions bot commented Sep 29, 2025

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enables static analysis using SonarQube in the Jenkins pipeline. The changes integrate SonarQube scanning into the build process and add functionality to report results back to GitHub pull requests.

  • Adds SonarQube static analysis step to the Jenkins pipeline
  • Creates Python script to post SonarQube results as GitHub PR comments
  • Adds Groovy functions for SonarQube integration and GitHub reporting

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
silabs_utils/performance_test_commands.cpp Adds dummy function for testing static analysis
jenkins_integration/jenkinsFunctions.groovy Implements SonarQube analysis and GitHub integration functions
jenkins_integration/github/send_sonar_results_to_github.py Python script to post SonarQube results to GitHub PRs
jenkins_integration/Jenkinsfile Replaces artifact upload stage with SonarQube static analysis step

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@sabollim-silabs sabollim-silabs force-pushed the feature/enable_static_analysis branch from a768d01 to 7882bcf Compare September 29, 2025 04:28
Copilot AI review requested due to automatic review settings September 29, 2025 13:59
@sabollim-silabs sabollim-silabs force-pushed the feature/enable_static_analysis branch from abbeaf5 to eb27663 Compare September 29, 2025 13:59
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

qualityGateStatus = qualityGateMatcher[0][1]
qualityGateResult = (qualityGateStatus == "PASSED") ? "PASS" : "FAIL"
} else {
qualityGateResult = "PASS"
Copy link

Copilot AI Sep 29, 2025

Choose a reason for hiding this comment

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

The fallback logic assumes a successful quality gate when the status cannot be parsed from the output. This could mask actual failures and should default to "FAIL" for safety, or throw an error to indicate the parsing failed.

Suggested change
qualityGateResult = "PASS"
echo "WARNING: Could not parse QUALITY GATE STATUS from SonarQube output. Defaulting to FAIL."
qualityGateResult = "FAIL"

Copilot uses AI. Check for mistakes.
def commit_sha = env.GIT_COMMIT ?: "unknown"

try {
sonarOutput = sh(script: "sonar-scanner ${sonarqubeParams.join(' ')}", returnStdout: true).trim()
Copy link

Copilot AI Sep 29, 2025

Choose a reason for hiding this comment

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

The sonarqubeParams array contains sensitive data (SONAR_SECRET token) that could be exposed in logs when the command fails or in debug output. Consider using a separate approach to handle the token parameter securely.

Copilot uses AI. Check for mistakes.
else:
print(f"❌ Failed to post comment to PR #{pr_number}")
print(f"Status: {response.status_code}")
print(f"Response: {response.text}")
Copy link

Copilot AI Sep 29, 2025

Choose a reason for hiding this comment

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

The GitHub API response may contain sensitive information that should not be logged. Consider sanitizing the response or limiting what gets printed to avoid potential credential exposure.

Suggested change
print(f"Response: {response.text}")
try:
error_message = response.json().get("message", "No error message provided.")
except Exception:
error_message = "Unable to parse error message from response."
print(f"Error: {error_message}")

Copilot uses AI. Check for mistakes.
usernamePassword(credentialsId: 'Matter-Extension-GitHub', usernameVariable: 'GITHUB_APP', passwordVariable: 'GITHUB_ACCESS_TOKEN')
]) {
// Escape sonar output for shell command
def escapedOutput = sonar_output.replace('"', '\\"').replace('`', '\\`').replace('$', '\\$')
Copy link

Copilot AI Sep 29, 2025

Choose a reason for hiding this comment

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

The shell escaping is incomplete and could allow command injection. Consider using proper shell escaping methods or passing the output through a file instead of as a command line argument.

Copilot uses AI. Check for mistakes.
@sabollim-silabs
Copy link
Contributor Author

I have read the CLA Document and I hereby sign the CLA behalf of my company, e-mail: satyanaag.bollimpalli@silabs.com

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.

2 participants