ICTU/quality-time

View on GitHub
.github/workflows/sonarcloud.yml

Summary

Maintainability
Test Coverage
---
name: SonarCloud

on:
  push:
    branches:
      - master
  pull_request:
    types: [opened, synchronize, reopened]

jobs:
  sonarcloud:
    runs-on: ubuntu-latest
    env:
      SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
    steps:
      - name: Login to DockerHub
        if: env.SONAR_TOKEN != null
        uses: docker/login-action@v3
        with:
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_PASSWORD }}
      - uses: actions/checkout@v4.2.2
        if: env.SONAR_TOKEN != null
        with:
          fetch-depth: 0 # Disabling shallow clone is recommended for improving relevancy of reporting
      - name: Install uv
        if: env.SONAR_TOKEN != null
        uses: astral-sh/setup-uv@v3
        with:
          version: "0.4.22"
      - name: Set up Node
        if: env.SONAR_TOKEN != null
        uses: actions/setup-node@v4.1.0
        with:
          node-version: "22"
      - name: Collector
        if: env.SONAR_TOKEN != null
        working-directory: components/collector
        run: |
          uv venv
          ci/pip-install.sh
          ci/unittest.sh
          export PYTHONPATH=`python -c 'import sys;print(":".join(sys.argv[1:]))' src $PYTHONPATH`
          .venv/bin/python -m xmlrunner --output-file build/unittests.xml
      - name: Notifier
        if: env.SONAR_TOKEN != null
        working-directory: components/notifier
        run: |
          uv venv
          ci/pip-install.sh
          ci/unittest.sh
          export PYTHONPATH=`python -c 'import sys;print(":".join(sys.argv[1:]))' src $PYTHONPATH`
          .venv/bin/python -m xmlrunner --output-file build/unittests.xml
      - name: API-server
        if: env.SONAR_TOKEN != null
        working-directory: components/api_server
        run: |
          uv venv
          ci/pip-install.sh
          ci/unittest.sh
          export PYTHONPATH=`python -c 'import sys;print(":".join(sys.argv[1:]))' src $PYTHONPATH`
          .venv/bin/python -m xmlrunner --output-file build/unittests.xml
      - name: Shared Code
        if: env.SONAR_TOKEN != null
        working-directory: components/shared_code
        run: |
          uv venv
          ci/pip-install.sh
          ci/unittest.sh
          export PYTHONPATH=`python -c 'import sys;print(":".join(sys.argv[1:]))' src $PYTHONPATH`
          .venv/bin/python -m xmlrunner --output-file build/unittests.xml
      - name: Frontend
        if: env.SONAR_TOKEN != null
        working-directory: components/frontend
        run: |
          npm install --ignore-scripts
          npm run --ignore-scripts build --if-present
          npm test -- --coverage
        env:
          CI: true
      - name: Create packages
        if: env.SONAR_TOKEN != null
        run: |
          touch components/__init__.py
          touch components/api_server/__init__.py
          touch components/api_server/src/__init__.py
          touch components/collector/__init__.py
          touch components/collector/src/__init__.py
          touch components/notifier/__init__.py
          touch components/notifier/src/__init__.py
          touch components/shared_code/__init__.py
          touch components/shared_code/src/__init__.py
      - name: Fix code coverage paths # Needed because the Sonar scanner runs in a container with different file paths
        if: env.SONAR_TOKEN != null
        run: |
          sed -i 's/\/home\/runner\/work\/quality-time\/quality-time\//\/github\/workspace\//g' components/collector/build/unittest-coverage.xml
          sed -i 's/\/home\/runner\/work\/quality-time\/quality-time\//\/github\/workspace\//g' components/notifier/build/unittest-coverage.xml
          sed -i 's/\/home\/runner\/work\/quality-time\/quality-time\//\/github\/workspace\//g' components/api_server/build/unittest-coverage.xml
          sed -i 's/\/home\/runner\/work\/quality-time\/quality-time\//\/github\/workspace\//g' components/shared_code/build/unittest-coverage.xml
      - name: Sonarcloud scan
        if: env.SONAR_TOKEN != null
        uses: sonarsource/sonarcloud-github-action@master
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}