diff --git a/.codecov.yml b/.codecov.yml deleted file mode 100644 index ef2e1eabfb..0000000000 --- a/.codecov.yml +++ /dev/null @@ -1,14 +0,0 @@ -comment: off - -coverage: - status: - project: - default: - target: 0 # Target % coverage, can be auto. Turned off for now - threshold: null - base: auto - patch: - default: - target: 0 - threshold: null - base: auto diff --git a/.coveragerc b/.coveragerc index 11f2ec8387..18b34693e7 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,8 +1,8 @@ [run] branch = True parallel = True -include=$TOP/synapse/* -data_file = $TOP/.coverage +include=synapse/* +data_file = .coverage [report] precision = 2 diff --git a/.github/workflows/sonarqube.yml b/.github/workflows/sonarqube.yml new file mode 100644 index 0000000000..1849d10125 --- /dev/null +++ b/.github/workflows/sonarqube.yml @@ -0,0 +1,37 @@ +name: SonarQube +on: + workflow_run: + workflows: [ "Tests" ] + types: + - completed +concurrency: + group: ${{ github.workflow }}-${{ github.event.workflow_run.head_branch }} + cancel-in-progress: true +jobs: + prdetails: + name: PR Details + if: github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'pull_request' + uses: matrix-org/matrix-js-sdk/.github/workflows/pr_details.yml@develop + with: + owner: ${{ github.event.workflow_run.head_repository.owner.login }} + branch: ${{ github.event.workflow_run.head_branch }} + + sonarqube: + name: 🩻 SonarQube + needs: prdetails + # Only wait for prdetails if it isn't skipped + if: | + always() && + (needs.prdetails.result == 'success' || needs.prdetails.result == 'skipped') && + github.event.workflow_run.conclusion == 'success' + uses: matrix-org/matrix-js-sdk/.github/workflows/sonarcloud.yml@develop + with: + repo: ${{ github.event.workflow_run.head_repository.full_name }} + pr_id: ${{ needs.prdetails.outputs.pr_id }} + head_branch: ${{ needs.prdetails.outputs.head_branch || github.event.workflow_run.head_branch }} + base_branch: ${{ needs.prdetails.outputs.base_branch }} + revision: ${{ github.event.workflow_run.head_sha }} + coverage_workflow_name: tests.yml + coverage_run_id: ${{ github.event.workflow_run.id }} + secrets: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index efa35b71df..f5f1f0f1e1 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -93,11 +93,13 @@ jobs: with: python-version: ${{ matrix.python-version }} extras: ${{ matrix.extras }} + - name: Install Coverage.py + run: pip install coverage - name: Await PostgreSQL if: ${{ matrix.postgres-version }} timeout-minutes: 2 run: until pg_isready -h localhost; do sleep 1; done - - run: poetry run trial --jobs=2 tests + - run: coverage run --branch --source=synapse poetry run trial --jobs=2 tests env: SYNAPSE_POSTGRES: ${{ matrix.database == 'postgres' || '' }} SYNAPSE_POSTGRES_HOST: localhost @@ -115,6 +117,12 @@ jobs: -exec cat {} \; -exec echo "::endgroup::" \; || true + - name: Upload coverage + uses: actions/upload-artifact@v3 + with: + name: coverage-${{ matrix.postgres-version }}-${{ matrix.database }}-${{ matrix.postgres-version }} + path: .coverage* + retention-days: 1 trial-olddeps: # Note: sqlite only; no postgres @@ -360,7 +368,29 @@ jobs: shell: bash name: Run Complement Tests - # a job which marks all the other jobs as complete, thus allowing PRs to be merged. + # a job which combines the coverage reports from all trials runs, ready for upload to SonarQube. + coverage: + needs: trial + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/download-artifact@v3 + with: + path: . + - name: Install Coverage.py + run: pip install coverage + - name: Combine coverage reports + run: coverage combine + - name: Write coverage to XML + run: coverage xml -i -o coverage/coverage.xml + - name: Upload combined coverage + uses: actions/upload-artifact@v3 + with: + name: coverage-combined + path: coverage + retention-days: 1 + + # a job which marks all the other jobs as complete, thus allowing PRs to be merged. tests-done: if: ${{ always() }} needs: @@ -374,6 +404,7 @@ jobs: - export-data - portdb - complement + - coverage runs-on: ubuntu-latest steps: - uses: matrix-org/done-action@v2 diff --git a/sonar-project.properties b/sonar-project.properties new file mode 100644 index 0000000000..8bd6d18e72 --- /dev/null +++ b/sonar-project.properties @@ -0,0 +1,15 @@ +sonar.projectKey=matrix-org_synapse +sonar.organization=matrix-org + +# Encoding of the source code. Default is default system encoding +#sonar.sourceEncoding=UTF-8 + +sonar.sources=synapse +sonar.tests=tests +sonar.exclusions=changelog.d,debian,demo,docker,docs + +sonar.coverage.exclusions=tests/**/* + +sonar.python.coverage.reportPaths=coverage/coverage.xml +sonar.python.version=3.10 +