|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" |
| 5 | +cd "$ROOT_DIR" |
| 6 | + |
| 7 | +SONAR_DIR="${SONAR_DIR:-dist/quality/sonar}" |
| 8 | +COVERAGE_DIR="${COVERAGE_DIR:-dist/quality/coverage}" |
| 9 | +VERSION="${VERSION:-1.0.0}" |
| 10 | + |
| 11 | +mkdir -p "$SONAR_DIR" "$COVERAGE_DIR" |
| 12 | + |
| 13 | +echo "Generating coverage report for SonarQube..." |
| 14 | +python -m pytest \ |
| 15 | + --cov=claude_code_api \ |
| 16 | + --cov-report=xml:"$COVERAGE_DIR/coverage.xml" \ |
| 17 | + --cov-report=term-missing \ |
| 18 | + --junitxml="$SONAR_DIR/xunit-report.xml" \ |
| 19 | + -v tests/ |
| 20 | + |
| 21 | +if ! command -v sonar-scanner >/dev/null 2>&1; then |
| 22 | + echo "sonar-scanner not found. Install with: brew install sonar-scanner or download from https://docs.sonarqube.org/latest/analysis/scan/sonarscanner/" |
| 23 | + exit 1 |
| 24 | +fi |
| 25 | + |
| 26 | +if [ -f ".env.vault" ]; then |
| 27 | + . ./.env.vault |
| 28 | +fi |
| 29 | + |
| 30 | +if [ -f ".env" ]; then |
| 31 | + set -a |
| 32 | + . ./.env |
| 33 | + set +a |
| 34 | +fi |
| 35 | + |
| 36 | +if [ -n "${VAULT_SECRET_PATHS:-}" ] || [ -n "${VAULT_REQUIRED_VARS:-}" ]; then |
| 37 | + if [ -f "./scripts/vault-helper.sh" ]; then |
| 38 | + . ./scripts/vault-helper.sh |
| 39 | + vault_helper::load_from_definitions \ |
| 40 | + "${VAULT_SECRET_PATHS:-}" \ |
| 41 | + "${VAULT_REQUIRED_VARS:-}" \ |
| 42 | + "${VAULT_TOKEN_FILE:-}" |
| 43 | + fi |
| 44 | +fi |
| 45 | + |
| 46 | +SONAR_HOST_URL="${SONAR_HOST_URL:-${SONAR_URL:-}}" |
| 47 | +if [ -z "$SONAR_HOST_URL" ]; then |
| 48 | + echo "SONAR_URL or SONAR_HOST_URL is required (e.g., https://sonarcloud.io or https://sonar.local)" |
| 49 | + exit 1 |
| 50 | +fi |
| 51 | + |
| 52 | +case "$SONAR_HOST_URL" in |
| 53 | + http://*|https://*) ;; |
| 54 | + *) |
| 55 | + echo "SONAR_URL must include http(s) scheme: $SONAR_HOST_URL" |
| 56 | + exit 1 |
| 57 | + ;; |
| 58 | +esac |
| 59 | + |
| 60 | +if [ -z "${SONAR_TOKEN:-}" ]; then |
| 61 | + echo "SONAR_TOKEN not set - proceeding without authentication" |
| 62 | +fi |
| 63 | + |
| 64 | +sonar-scanner \ |
| 65 | + -Dsonar.host.url="$SONAR_HOST_URL" \ |
| 66 | + -Dsonar.token="$SONAR_TOKEN" \ |
| 67 | + -Dsonar.projectVersion="$VERSION" \ |
| 68 | + -Dsonar.working.directory="$SONAR_DIR/scannerwork" |
0 commit comments