From ee17b41aadbe089419cc6ca0e9edc8e776dfe724 Mon Sep 17 00:00:00 2001 From: Robin Y Bobbitt Date: Sun, 13 Aug 2023 23:03:08 -0400 Subject: [PATCH] Configure sonarcloud --- .github/workflows/tox.yml | 20 ++++++++++++++++++-- sonar-project.properties | 9 +++++++++ tox.ini | 2 +- 3 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 sonar-project.properties diff --git a/.github/workflows/tox.yml b/.github/workflows/tox.yml index d6cec34..6dbafc6 100644 --- a/.github/workflows/tox.yml +++ b/.github/workflows/tox.yml @@ -1,8 +1,11 @@ name: Python package on: - - push - - pull_request + push: + branches: + - main + pull_request: + types: [opened, synchronize, reopened] jobs: build: @@ -13,6 +16,8 @@ jobs: steps: - uses: actions/checkout@v3 + with: + fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v4 with: @@ -23,3 +28,14 @@ jobs: python -m pip install tox tox-gh-actions - name: Test with tox run: tox + # See https://sonarsource.atlassian.net/browse/SONARPY-1203 + - name: Fix paths in coverage file + run: | + sed -i 's/\/home\/runner\/work\/anonymizer\/anonymizer/\/github\/workspace\//g' coverage.xml + - name: SonarCloud scan + # skip sonarcloud scan from PRs from a fork + if: matrix.python-version == 3.11 && !(github.event.pull_request && github.event.pull_request.head.repo.fork) + uses: SonarSource/sonarcloud-github-action@master + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} diff --git a/sonar-project.properties b/sonar-project.properties new file mode 100644 index 0000000..f7b7b6d --- /dev/null +++ b/sonar-project.properties @@ -0,0 +1,9 @@ +sonar.projectKey=ansible_anonymizer +sonar.organization=ansible + +sonar.sources = ansible_anonymizer/ +sonar.tests = tests/ + +sonar.python.version=3.11 + +sonar.python.coverage.reportPaths=coverage.xml diff --git a/tox.ini b/tox.ini index 1ec19c4..489e3fd 100644 --- a/tox.ini +++ b/tox.ini @@ -19,7 +19,7 @@ deps = pytest-cov commands = pip install -U pip - pytest --cov --cov-append --cov-report=term-missing --cov-fail-under=95 {posargs:tests} + pytest --cov --cov-append --cov-report=term-missing --cov-report=xml:coverage.xml --cov-fail-under=95 {posargs:tests} depends = {py311}: clean report: py311