-
Notifications
You must be signed in to change notification settings - Fork 164
Add sonarqube for cuopt - static analysis #762
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
Merged
rapids-bot
merged 22 commits into
NVIDIA:release/26.02
from
rgsl888prabhu:enable_sonar_cube_for_cuopt
Jan 24, 2026
Merged
Changes from 16 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
2398a0d
Adding sonarqube support
rgsl888prabhu 829c431
fix
rgsl888prabhu ff534a5
update as per review
rgsl888prabhu b10f210
Merge branch 'main' into enable_sonar_cube_for_cuopt
rgsl888prabhu f2b8381
Add it to PR job to test
rgsl888prabhu 906bd89
revert sonarqube changes
rgsl888prabhu 281881b
Adding sonarqube project details to cuopt and script to run
rgsl888prabhu ac0a4db
Add updates
rgsl888prabhu f390175
update
rgsl888prabhu 64e7cc5
fix style
rgsl888prabhu 2718429
fix style
rgsl888prabhu 14137bc
fix repo url
rgsl888prabhu 1f5605f
change from conda to mamba
rgsl888prabhu 07aa4fa
address review comment
rgsl888prabhu 99dd6b9
fix
rgsl888prabhu c3a5c5c
Merge branch 'main' into enable_sonar_cube_for_cuopt
rgsl888prabhu 83c97ac
remove wrapper
rgsl888prabhu 5d4713f
Merge branch 'enable_sonar_cube_for_cuopt' of github.com:rgsl888prabh…
rgsl888prabhu 0026e9a
Add update to address reviews
rgsl888prabhu 975cf58
fix style
rgsl888prabhu 6d50542
fix style
rgsl888prabhu f4bb4c2
Merge branch 'release/26.02' into enable_sonar_cube_for_cuopt
rgsl888prabhu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| # SonarQube Project Configuration | ||
| sonar.projectKey=GPUSW_cuOpt_Nvidia-cuOpt_cuopt | ||
| sonar.projectName=NVIDIA cuOpt | ||
| sonar.projectVersion=1.0 | ||
|
|
||
| # Source code location | ||
| sonar.sources=. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| # SonarQube Analysis | ||
|
|
||
| This directory contains the configuration and scripts for running automated SonarQube analysis on cuOpt branches. | ||
|
|
||
| ## Files | ||
|
|
||
| - `sonar-branches.txt` - List of branches to analyze (one per line) | ||
| - `run-sonar-analysis.sh` - Automated script that clones, builds, and analyzes branches | ||
|
|
||
| ## Quick Start | ||
|
|
||
| ### 1. Configure Branches | ||
|
|
||
| Edit `sonar-branches.txt` to specify which branches to analyze: | ||
|
|
||
| ```bash | ||
| # One branch per line | ||
| main | ||
| release/26.02 | ||
|
|
||
| # Lines starting with # are comments | ||
| # Empty lines are ignored | ||
| ``` | ||
|
|
||
| ### 2. Set Required Environment Variable | ||
|
|
||
| The script requires authentication: | ||
|
|
||
| ```bash | ||
| export SONAR_TOKEN="your_token_here" | ||
| ``` | ||
|
|
||
| **Note**: Contact the cuOpt team for token details. | ||
|
|
||
| ### 3. Run the Analysis | ||
|
|
||
| ```bash | ||
| cd /path/to/cuopt | ||
| ./sonarqube/run-sonar-analysis.sh | ||
| ``` | ||
|
|
||
| ## Script Behavior | ||
|
|
||
| The script will automatically: | ||
|
|
||
| 1. ✅ Validate branch configuration file exists and has at least one branch | ||
| 2. ✅ Clone each branch into a fresh temporary directory | ||
| 3. ✅ Create an isolated conda environment per branch | ||
| 4. ✅ Build the project using `./build.sh` | ||
| 5. ✅ Run SonarQube analysis with branch-specific tagging | ||
| 6. ✅ Clean up temporary files and conda environments | ||
| 7. ✅ Provide a summary of successful and failed branches | ||
|
|
||
| ## Support | ||
|
|
||
| **Contact**: cuOpt team | ||
|
|
||
| For issues with: | ||
| - Build failures: See [CONTRIBUTING.md](../CONTRIBUTING.md) | ||
| - Script bugs: Report to the cuOpt team |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| #!/bin/bash | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # Cron wrapper script for SonarQube analysis | ||
| # This script clones/pulls the cuopt repository and runs SonarQube analysis | ||
|
|
||
| set -e | ||
|
|
||
| # Configuration | ||
| REPO_URL="git@github.com:rgsl888prabhu/cuopt_public.git" | ||
| REPO_BRANCH="enable_sonar_cube_for_cuopt" | ||
| WORK_DIR="/tmp/cuopt-sonar-cron" | ||
| LOG_DIR="/var/log/sonarqube" | ||
|
|
||
| # Create log directory if it doesn't exist | ||
| mkdir -p "$LOG_DIR" | ||
|
|
||
| # Log file with timestamp | ||
| LOG_FILE="$LOG_DIR/sonar-cron-$(date +%Y%m%d-%H%M%S).log" | ||
|
|
||
| # Function to log messages | ||
| log() { | ||
| echo "[$(date '+%Y-%m-%d %H:%M:%S')] $*" | tee -a "$LOG_FILE" | ||
| } | ||
|
|
||
| log "========================================" | ||
| log "SonarQube Cron Job Started" | ||
| log "========================================" | ||
| log "Repository: $REPO_URL" | ||
| log "Branch: $REPO_BRANCH" | ||
| log "Work Directory: $WORK_DIR" | ||
| log "Log File: $LOG_FILE" | ||
|
|
||
| # Check if SONAR_TOKEN is set | ||
| if [ -z "$SONAR_TOKEN" ]; then | ||
| log "ERROR: SONAR_TOKEN environment variable is not set" | ||
| log "Please set it in crontab or source a secrets file" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Clone or update repository | ||
| if [ -d "$WORK_DIR" ]; then | ||
| log "Repository directory exists, pulling latest changes..." | ||
| cd "$WORK_DIR" | ||
|
|
||
| # Check if it's a git repository | ||
| if ! git rev-parse --git-dir > /dev/null 2>&1; then | ||
| log "ERROR: $WORK_DIR exists but is not a git repository" | ||
| log "Removing and will re-clone..." | ||
| cd /tmp | ||
| rm -rf "$WORK_DIR" | ||
| else | ||
| # Ensure we're on the correct branch | ||
| current_branch=$(git rev-parse --abbrev-ref HEAD) | ||
| if [ "$current_branch" != "$REPO_BRANCH" ]; then | ||
| log "Switching from branch $current_branch to $REPO_BRANCH" | ||
| if ! git fetch origin; then | ||
| log "ERROR: Failed to fetch from origin" | ||
| exit 1 | ||
| fi | ||
| if ! git checkout "$REPO_BRANCH"; then | ||
| log "ERROR: Failed to checkout branch $REPO_BRANCH" | ||
| exit 1 | ||
| fi | ||
| fi | ||
|
|
||
| # Pull latest changes | ||
| log "Pulling latest changes for branch: $REPO_BRANCH" | ||
| if ! git pull origin "$REPO_BRANCH"; then | ||
| log "ERROR: Failed to pull latest changes" | ||
| exit 1 | ||
| fi | ||
|
|
||
| log "Successfully updated repository" | ||
| fi | ||
| fi | ||
|
|
||
| # Clone if directory doesn't exist | ||
| if [ ! -d "$WORK_DIR" ]; then | ||
| log "Cloning repository for the first time..." | ||
| if ! git clone --branch "$REPO_BRANCH" "$REPO_URL" "$WORK_DIR"; then | ||
| log "ERROR: Failed to clone repository" | ||
| exit 1 | ||
| fi | ||
| log "Successfully cloned repository" | ||
| fi | ||
|
|
||
| # Change to repository directory | ||
| cd "$WORK_DIR" | ||
|
|
||
| # Show current commit | ||
| CURRENT_COMMIT=$(git rev-parse --short HEAD) | ||
| COMMIT_MSG=$(git log -1 --pretty=%B) | ||
| log "Current commit: $CURRENT_COMMIT" | ||
| log "Commit message: $COMMIT_MSG" | ||
|
|
||
| # Check if sonarqube directory exists | ||
| if [ ! -d "sonarqube" ]; then | ||
| log "ERROR: sonarqube directory not found in repository" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Check if run-sonar-analysis.sh exists | ||
| if [ ! -f "sonarqube/run-sonar-analysis.sh" ]; then | ||
| log "ERROR: sonarqube/run-sonar-analysis.sh not found" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Make script executable | ||
| chmod +x sonarqube/run-sonar-analysis.sh | ||
|
|
||
| # Run SonarQube analysis | ||
| log "========================================" | ||
| log "Starting SonarQube Analysis" | ||
| log "========================================" | ||
|
|
||
| if ./sonarqube/run-sonar-analysis.sh 2>&1 | tee -a "$LOG_FILE"; then | ||
| log "========================================" | ||
| log "SonarQube Analysis Completed Successfully" | ||
| log "========================================" | ||
| exit 0 | ||
| else | ||
| EXIT_CODE=$? | ||
| log "========================================" | ||
| log "SonarQube Analysis Failed (Exit Code: $EXIT_CODE)" | ||
| log "========================================" | ||
| exit $EXIT_CODE | ||
|
rgsl888prabhu marked this conversation as resolved.
Outdated
|
||
| fi | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.