Skip to content

[FME-12336] - Metadata - Clients #653

[FME-12336] - Metadata - Clients

[FME-12336] - Metadata - Clients #653

Workflow file for this run

name: Sonar Scan
on:
pull_request:
branches:
- "**"
push:
branches:
- master
# Cancel in-progress runs when a new workflow with the same group is triggered
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
build-and-collect-coverage:
name: Build & Collect Coverage
runs-on: macos-15-xlarge
timeout-minutes: 15
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for proper SonarQube analysis
- name: Run tests with coverage (ignore failures)
continue-on-error: true
run: |
xcodebuild -quiet test \
-project Split.xcodeproj \
-scheme Split \
-testPlan "SplitiOSFull" \
-destination 'platform=iOS Simulator,OS=18.5,name=iPhone 16' \
-enableCodeCoverage YES \
-resultBundlePath build/Logs/Test/TestResults.xcresult \
-derivedDataPath build
- name: Generate SonarQube Coverage XML
run: |
set -euo pipefail
mkdir -p coverage
# Make the script executable (just in case)
chmod +x .github/scripts/xccov-to-sonarqube.sh
# Verify the xcresult bundle exists
echo "πŸ“ Checking for xcresult bundle..."
if [ ! -d "build/Logs/Test/TestResults.xcresult" ]; then
echo "❌ Error: TestResults.xcresult not found"
find build -name "*.xcresult" || echo "No xcresult files found"
exit 1
fi
echo "βœ… Found xcresult bundle at build/Logs/Test/TestResults.xcresult"
# Generate SonarQube generic coverage XML
echo "πŸ“Š Generating SonarQube coverage XML..."
.github/scripts/xccov-to-sonarqube.sh build/Logs/Test/TestResults.xcresult > sonarqube-generic-coverage.xml
# Verify the coverage file was created
if [ ! -f "sonarqube-generic-coverage.xml" ]; then
echo "❌ Error: Failed to generate sonarqube-generic-coverage.xml"
exit 1
fi
# Check file size and content
FILE_SIZE=$(stat -f%z sonarqube-generic-coverage.xml)
echo "πŸ“ Coverage XML file size: $FILE_SIZE bytes"
if [ "$FILE_SIZE" -lt 100 ]; then
echo "⚠️ Warning: Coverage file is suspiciously small ($FILE_SIZE bytes)"
cat sonarqube-generic-coverage.xml
exit 1
fi
# Show sample of the coverage file
echo "πŸ“„ Sample of coverage XML file:"
head -n 20 sonarqube-generic-coverage.xml
echo "βœ… SonarQube coverage XML generated successfully"
- name: Upload coverage artifact
uses: actions/upload-artifact@v4
with:
name: sonarqube-generic-coverage
path: sonarqube-generic-coverage.xml
sonar:
name: Run SonarQube Scan
runs-on: ubuntu-latest
timeout-minutes: 15
needs: build-and-collect-coverage
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for proper SonarQube analysis
- name: Download coverage
uses: actions/download-artifact@v4
with:
name: sonarqube-generic-coverage
path: .
- name: Verify SonarQube Coverage XML
run: |
echo "πŸ“Š Verifying SonarQube coverage XML..."
# Check if file exists and has content
if [ ! -f sonarqube-generic-coverage.xml ]; then
echo "❌ Error: sonarqube-generic-coverage.xml file does not exist"
echo "πŸ“‚ Current directory contents:"
ls -la
exit 1
fi
# Check file size
FILE_SIZE=$(stat -c%s sonarqube-generic-coverage.xml)
echo "πŸ“ File size: $FILE_SIZE bytes"
# Count coverage entries
COVERAGE_ENTRIES=$(grep -c "lineToCover" sonarqube-generic-coverage.xml || echo "0")
echo "πŸ“Š Number of coverage entries: $COVERAGE_ENTRIES"
if [ "$COVERAGE_ENTRIES" -lt 10 ]; then
echo "⚠️ Warning: Very few coverage entries found ($COVERAGE_ENTRIES)"
else
echo "βœ… Coverage entries look good"
fi
echo "βœ… SonarQube coverage XML validation passed"
# Show sample of the coverage XML
echo "πŸ“„ Sample of coverage XML:"
head -n 20 sonarqube-generic-coverage.xml
- name: Run SonarQube scan (Pull Request)
if: github.event_name == 'pull_request'
uses: sonarsource/sonarqube-scan-action@v7
with:
projectBaseDir: .
args: >
-Dsonar.projectKey=splitio_ios-client
-Dsonar.projectName=${{ github.event.repository.name }}
-Dsonar.c.file.suffixes=-
-Dsonar.cpp.file.suffixes=-
-Dsonar.objc.file.suffixes=-
-Dsonar.coverageReportPaths=sonarqube-generic-coverage.xml
-Dsonar.verbose=true
-Dsonar.sources=Split
-Dsonar.exclusions=**/Tests/**,**/*.generated.swift
-Dsonar.coverage.exclusions=**/Tests/**,**/*.generated.swift
-Dsonar.qualitygate.wait=true
-Dsonar.qualitygate.timeout=300
-Dsonar.new.code.ignore.list.patterns=**/*.generated.swift
-Dsonar.qualitygate.ignoreSmallChanges=false
-Dsonar.newCode.referenceBranch=${{ github.event.pull_request.base.ref }}
-Dsonar.pullrequest.provider=github
-Dsonar.pullrequest.github.repository=${{ github.repository }}
-Dsonar.pullrequest.key=${{ github.event.pull_request.number }}
-Dsonar.pullrequest.branch=${{ github.event.pull_request.head.ref }}
-Dsonar.pullrequest.base=${{ github.event.pull_request.base.ref }}
env:
SONAR_TOKEN: ${{ secrets.SONARQUBE_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONARQUBE_HOST }}
- name: Run SonarQube scan (Branch)
if: github.event_name == 'push'
uses: sonarsource/sonarqube-scan-action@v7
with:
projectBaseDir: .
args: >
-Dsonar.projectKey=splitio_ios-client
-Dsonar.projectName=${{ github.event.repository.name }}
-Dsonar.c.file.suffixes=-
-Dsonar.cpp.file.suffixes=-
-Dsonar.objc.file.suffixes=-
-Dsonar.coverageReportPaths=sonarqube-generic-coverage.xml
-Dsonar.verbose=true
-Dsonar.sources=Split
-Dsonar.exclusions=**/Tests/**,**/*.generated.swift
-Dsonar.coverage.exclusions=**/Tests/**,**/*.generated.swift
-Dsonar.qualitygate.wait=true
-Dsonar.qualitygate.timeout=300
-Dsonar.new.code.ignore.list.patterns=**/*.generated.swift
-Dsonar.qualitygate.ignoreSmallChanges=false
-Dsonar.branch.name=${{ github.ref_name }}
env:
SONAR_TOKEN: ${{ secrets.SONARQUBE_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONARQUBE_HOST }}