fix sonarcloud coverage configuration #6
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
| name: sonarcloud analysis | |
| on: | |
| push: | |
| branches: [ main, develop ] | |
| pull_request: | |
| types: [opened, synchronize, reopened] | |
| jobs: | |
| sonarcloud: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # shallow clones should be disabled for better analysis | |
| - name: set up python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.13' | |
| - name: cache pip dependencies | |
| uses: actions/cache@v3 | |
| with: | |
| path: ~/.cache/pip | |
| key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} | |
| restore-keys: | | |
| ${{ runner.os }}-pip- | |
| - name: install dependencies | |
| run: | | |
| cd testing | |
| python -m venv .venv | |
| source .venv/bin/activate | |
| python -m pip install --upgrade pip | |
| pip install pytest pytest-cov pytest-asyncio httpx | |
| pip install -r ../crypto_service/requirements.txt | |
| pip install -r ../pki_service/requirements.txt | |
| - name: start crypto service | |
| run: | | |
| cd crypto_service | |
| python -m pip install -r requirements.txt | |
| # set env vars for CI environment | |
| export HSM_IP="localhost" | |
| export HSM_PORT="1234" | |
| export CRYPTO_HSM="GP" | |
| export ENVIRONMENT="test" | |
| export PYTHONPATH="../:$PYTHONPATH" | |
| nohup uvicorn app.main:app --host 0.0.0.0 --port 8001 > crypto.log 2>&1 & | |
| echo $! > crypto.pid | |
| - name: start pki service | |
| run: | | |
| cd pki_service | |
| python -m pip install -r requirements.txt | |
| # set env vars for CI environment | |
| export KC_CLI="pki-ci" | |
| export ENVIRONMENT="test" | |
| export PYTHONPATH="../:$PYTHONPATH" | |
| nohup uvicorn app.main:app --host 0.0.0.0 --port 8000 > pki.log 2>&1 & | |
| echo $! > pki.pid | |
| - name: wait for services to start | |
| run: | | |
| # give services time to start | |
| sleep 10 | |
| # check if services are running | |
| echo "Checking crypto service status..." | |
| if ! ps aux | grep -v grep | grep "crypto_service"; then | |
| echo "Crypto service not running, checking logs:" | |
| cat crypto_service/crypto.log || echo "No crypto log found" | |
| fi | |
| echo "Checking pki service status..." | |
| if ! ps aux | grep -v grep | grep "pki_service"; then | |
| echo "PKI service not running, checking logs:" | |
| cat pki_service/pki.log || echo "No pki log found" | |
| fi | |
| # wait for crypto service with extended timeout | |
| echo "Waiting for crypto service health check..." | |
| timeout 60s bash -c 'until curl -f http://localhost:8001/health > /dev/null 2>&1; do sleep 3; done' | |
| echo "crypto service is ready" | |
| # wait for pki service with extended timeout | |
| echo "Waiting for pki service health check..." | |
| timeout 60s bash -c 'until curl -f http://localhost:8000/health > /dev/null 2>&1; do sleep 3; done' | |
| echo "pki service is ready" | |
| - name: run tests with coverage | |
| run: | | |
| cd testing | |
| source .venv/bin/activate | |
| export HSM_IP="localhost" | |
| export HSM_PORT="1234" | |
| export CRYPTO_HSM="GP" | |
| export CRYPTO_HOST="localhost" | |
| export CRYPTO_PORT="8001" | |
| export ENVIRONMENT="test" | |
| export PKI_HOST="localhost" | |
| export PKI_PORT="8000" | |
| export PROTOCOL="http" | |
| export PYTHONPATH="../:$PYTHONPATH" | |
| pytest unit_tests/ integration_tests/ e2e_tests/ \ | |
| --cov=../crypto_service \ | |
| --cov=../pki_service \ | |
| --cov=../common \ | |
| --cov-report=xml:coverage.xml \ | |
| --cov-report=html:htmlcov \ | |
| --junitxml=test-results.xml \ | |
| -v | |
| - name: stop services | |
| if: always() | |
| run: | | |
| # stop crypto service if running | |
| if [ -f crypto_service/crypto.pid ]; then | |
| kill $(cat crypto_service/crypto.pid) || true | |
| rm crypto_service/crypto.pid | |
| fi | |
| # stop pki service if running | |
| if [ -f pki_service/pki.pid ]; then | |
| kill $(cat pki_service/pki.pid) || true | |
| rm pki_service/pki.pid | |
| fi | |
| - name: sonarcloud scan | |
| uses: SonarSource/sonarcloud-github-action@master | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
| with: | |
| projectBaseDir: . | |
| # use the sonar-project.properties file from testing directory | |
| # override key settings for sonarcloud | |
| args: > | |
| -Dsonar.projectKey=jagnd1_fmcrypto | |
| -Dsonar.organization=jagnd1 | |
| -Dsonar.host.url=https://sonarcloud.io |