Skip to content
This repository was archived by the owner on Apr 23, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 7 additions & 48 deletions .github/workflows/python-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ jobs:

# Fix SonarCloud scan to use proper configuration
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
continue-on-error: true
uses: SonarSource/sonarqube-scan-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to decorate PRs with analysis results
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} # Required: Store your SonarCloud token as a GitHub secret
SONAR_HOST_URL: "https://sonarcloud.io"
with:
args: >
-Dsonar.projectKey=BlueCentre_cli-code
Expand All @@ -108,63 +108,22 @@ jobs:
-Dsonar.sourceEncoding=UTF-8
-Dsonar.verbose=true
-Dsonar.scm.provider=git
-Dsonar.coverage.jacoco.xmlReportPaths=coverage.xml
-Dsonar.coverage.reportPaths=coverage.xml
-Dsonar.genericcoverage.reportPaths=coverage.xml
-Dsonar.issue.ignore.multicriteria=e1
-Dsonar.issue.ignore.multicriteria.e1.ruleKey=*
-Dsonar.issue.ignore.multicriteria.e1.resourceKey=**/*.py

# Add specific PR properties based on GitHub context
- name: SonarCloud PR Scan
uses: SonarSource/sonarcloud-github-action@master
- name: SonarCloud PR Analysis
if: github.event_name == 'pull_request'
continue-on-error: true
uses: SonarSource/sonarqube-scan-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to decorate PRs with analysis results
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} # Required: Store your SonarCloud token as a GitHub secret
SONAR_HOST_URL: "https://sonarcloud.io"
with:
args: >
-Dsonar.projectKey=BlueCentre_cli-code
-Dsonar.organization=vitruviansoftware
-Dsonar.pullrequest.key=${{ github.event.pull_request.number }}
-Dsonar.pullrequest.branch=${{ github.head_ref }}
-Dsonar.pullrequest.base=${{ github.base_ref }}

# Force build success even if SonarCloud analysis fails
- name: Override SonarCloud failure
run: |
echo "SonarCloud analysis may have failed, but we're overriding the status"
echo "This is a temporary measure to allow the PR to be merged despite coverage issues"
echo "Actual code coverage from manual testing shows good coverage, but SonarCloud is having trouble detecting it"
exit 0

# Force the GitHub check to succeed regardless of SonarCloud status
- name: Mark PR as successful
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
continue-on-error: true
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
try {
const { owner, repo } = context.repo;
const { sha } = context.payload.pull_request.head;

// Create a successful check status
await github.rest.repos.createCommitStatus({
owner,
repo,
sha: sha,
state: 'success',
context: 'SonarCloud Override',
description: 'Manually verified code coverage is adequate',
target_url: 'https://github.com/BlueCentre/cli-code/pull/7'
});

console.log('Successfully set PR status to success');
} catch (error) {
console.error('Failed to set PR status:', error.message);
// Continue the workflow even if this step fails
}

- name: Report SonarCloud Results
run: |
Expand Down
85 changes: 32 additions & 53 deletions scripts/run_coverage_ci.sh
Original file line number Diff line number Diff line change
@@ -1,59 +1,38 @@
#!/bin/bash
# Ultra-simplified coverage script that definitely won't fail
# Script to generate coverage for CI pipeline

# Print commands for debugging
set -x
set -e # Exit on error

echo "Generating minimal coverage report for SonarCloud..."
echo "Starting coverage generation for CI..."

# Create a coverage directory for HTML report
# Set up coverage directory
mkdir -p coverage_html

# Create a simple HTML coverage report
cat > coverage_html/index.html << EOF
<!DOCTYPE html>
<html>
<head><title>Coverage Report</title></head>
<body>
<h1>Coverage Report</h1>
<p>This is a simplified coverage report created for CI pipeline.</p>
</body>
</html>
EOF

# Create a SonarCloud-compatible coverage XML file
cat > coverage.xml << EOF
<?xml version="1.0" ?>
<coverage version="1">
<file path="src/cli_code/tools/file_tools.py">
<lineToCover lineNumber="1" covered="true"/>
<lineToCover lineNumber="2" covered="true"/>
<lineToCover lineNumber="3" covered="true"/>
<lineToCover lineNumber="4" covered="true"/>
<lineToCover lineNumber="5" covered="true"/>
</file>
<file path="src/cli_code/tools/directory_tools.py">
<lineToCover lineNumber="1" covered="true"/>
<lineToCover lineNumber="2" covered="true"/>
<lineToCover lineNumber="3" covered="true"/>
<lineToCover lineNumber="4" covered="true"/>
<lineToCover lineNumber="5" covered="true"/>
</file>
<file path="src/cli_code/tools/system_tools.py">
<lineToCover lineNumber="1" covered="true"/>
<lineToCover lineNumber="2" covered="true"/>
<lineToCover lineNumber="3" covered="true"/>
<lineToCover lineNumber="4" covered="true"/>
<lineToCover lineNumber="5" covered="true"/>
</file>
</coverage>
EOF

# Print generated coverage report for verification
echo "Coverage XML file content:"
cat coverage.xml

echo "✅ Successfully generated coverage report for SonarCloud."

# Always exit with success
exit 0
# Run pytest with coverage enabled and generate reports
echo "Running test suite with coverage enabled..."
python -m pytest \
--cov=src.cli_code \
--cov-report=xml:coverage.xml \
--cov-report=html:coverage_html \
--cov-report=term \
test_dir/test_file_tools.py test_dir/test_directory_tools.py test_dir/test_system_tools.py \
test_dir/improved/test_quality_tools.py test_dir/improved/test_summarizer_tool.py test_dir/improved/test_tree_tool.py

echo "Coverage report generated in coverage.xml and coverage_html/"

# Extract overall coverage percentage for GitHub output
if [ -f "coverage.xml" ]; then
echo "✅ coverage.xml file exists"

# Extract overall coverage percentage
COVERAGE=$(python -c "import xml.etree.ElementTree as ET; tree = ET.parse('coverage.xml'); root = tree.getroot(); line_rate = float(root.attrib['line-rate'])*100; print('{:.2f}%'.format(line_rate))")
echo "Overall coverage percentage: $COVERAGE"

# Set output for GitHub Actions
echo "percentage=$COVERAGE" >> $GITHUB_OUTPUT
else
echo "❌ coverage.xml file not generated!"
echo "percentage=0.00%" >> $GITHUB_OUTPUT
fi
Comment on lines +23 to +36

Choose a reason for hiding this comment

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

medium

This section extracts the coverage percentage from the coverage.xml file and sets it as an output for GitHub Actions. It's good to see error handling for the case where the file doesn't exist. Consider adding a check to ensure the coverage percentage meets a minimum threshold, and fail the CI job if it doesn't.

if [ -f "coverage.xml" ]; then
  echo "✅ coverage.xml file exists"
  
  # Extract overall coverage percentage
  COVERAGE=$(python -c "import xml.etree.ElementTree as ET; tree = ET.parse('coverage.xml'); root = tree.getroot(); line_rate = float(root.attrib['line-rate'])*100; print('{:.2f}%'.format(line_rate))")
  echo "Overall coverage percentage: $COVERAGE"
  
  # Set output for GitHub Actions
  echo "percentage=$COVERAGE" >> $GITHUB_OUTPUT

  # Check if coverage meets the minimum threshold (e.g., 80%)
  MIN_COVERAGE=80.00
  if (( $(echo "${COVERAGE%\%}< $MIN_COVERAGE" | bc -l) )); then
    echo "❌ Coverage is below the minimum threshold of $MIN_COVERAGE%!"
    exit 1 # Fail the CI job
  else
    echo "✅ Coverage meets the minimum threshold of $MIN_COVERAGE%!"
  fi
else
  echo "❌ coverage.xml file not generated!"
  echo "percentage=0.00%" >> $GITHUB_OUTPUT
fi


echo "Coverage generation for CI completed."
26 changes: 2 additions & 24 deletions sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,17 @@ sonar.projectVersion=0.2.1
sonar.sources=src/cli_code
sonar.tests=test_dir

# Coverage report paths - try all formats to ensure detection
# Coverage report paths
sonar.python.coverage.reportPaths=coverage.xml
sonar.coverage.jacoco.xmlReportPaths=coverage.xml
sonar.coverage.reportPaths=coverage.xml
sonar.genericcoverage.reportPaths=coverage.xml

# Configure test coverage exclusions
sonar.coverage.exclusions=test_dir/**/*,tests/**/*,src/cli_code/models/ollama.py

# Disable some checks that are problematic in this scan
sonar.issue.ignore.multicriteria=e1
sonar.issue.ignore.multicriteria.e1.ruleKey=*
sonar.issue.ignore.multicriteria.e1.resourceKey=**/*.py

# Force 100% coverage on new code to work around the detection issue
sonar.coverage.force=true

# Skip waiting for quality gate
sonar.qualitygate.wait=false

# Set branch patterns
sonar.branch.longLivedBranches.regex=(master|main|develop)
sonar.branch.name=feature/improve-models-coverage

# Consider all code as "old code" to avoid new code checks
sonar.newCode.referenceBranch=feature/improve-models-coverage

# Specify Python version
sonar.python.version=3.11

# Encoding of the source code. Default is default system encoding
sonar.sourceEncoding=UTF-8

# SCM configuration
sonar.scm.provider=git
sonar.scm.forceReloadAll=true
sonar.scm.provider=git
Loading