diff --git a/.github/workflows/sonarqube.yml b/.github/workflows/sonarqube.yml new file mode 100644 index 0000000..99cb37f --- /dev/null +++ b/.github/workflows/sonarqube.yml @@ -0,0 +1,60 @@ +name: SonarQube + +on: + push: + branches: [ main, develop ] + pull_request: + +jobs: + sonar: + runs-on: ubuntu-latest + + steps: + - name: Check SONAR_TOKEN presence + run: | + if [ -z "$SONAR_TOKEN" ]; then + echo "SONAR_TOKEN missing" + exit 1 + else + echo "SONAR_TOKEN present" + fi + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.12' + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install requests + pip install pytest pytest-cov pytest-check coverage + pip install -e . + + - name: Set up Java + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: '21' + + - name: SonarQube Scan + uses: SonarSource/sonarqube-scan-action@v6 + with: + args: > + -Dsonar.scanner.skipJreProvisioning=true + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + SONAR_SCANNER_SKIP_JRE_PROVISIONING: "true" + + - name: Run tests with coverage + run: | + coverage run -m pytest + coverage xml -o coverage.xml + diff --git a/.github/workflows/test-sysmlv2-python-client.yml b/.github/workflows/test-sysmlv2-python-client.yml index 67b79aa..2ab44a3 100644 --- a/.github/workflows/test-sysmlv2-python-client.yml +++ b/.github/workflows/test-sysmlv2-python-client.yml @@ -18,7 +18,7 @@ jobs: id: setup-python uses: actions/setup-python@v4 with: - python-version: '3.11' + python-version: '3.12' - name: Cache pip dependencies uses: actions/cache@v3 @@ -37,11 +37,7 @@ jobs: - name: Run tests with coverage run: | mkdir -p test-results - pytest -v --tb=short \ - --junitxml=test-results/results.xml \ - --cov=src/sysmlv2_client \ - --cov-report=xml:test-results/coverage.xml \ - --cov-report=html:test-results/htmlcov + pytest -v --tb=short --junitxml=test-results/results.xml --cov=src/sysmlv2_client --cov-report=xml:test-results/coverage.xml --cov-report=html:test-results/htmlcov - name: Upload test results uses: actions/upload-artifact@v4 diff --git a/.gitignore b/.gitignore index e3258ba..68c2a5b 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,4 @@ env/ flexo-setup/docker-compose/env/*.env /build /src/sysmlv2_python_client.egg-info +/test-results diff --git a/sonar-project.properties b/sonar-project.properties new file mode 100644 index 0000000..3d36483 --- /dev/null +++ b/sonar-project.properties @@ -0,0 +1,8 @@ +sonar.projectKey=sysmlv2-python-client +sonar.organization=openmbee +sonar.host.url=https://sonarcloud.io + +sonar.sources=src +sonar.tests=tests +sonar.python.version=3.12 +sonar.python.coverage.reportPaths=coverage.xml