From 7dbca288cd2bd907fdd7c84a15141ae8a90da390 Mon Sep 17 00:00:00 2001 From: Serhii Horodilov Date: Thu, 17 Aug 2023 01:07:20 +0300 Subject: [PATCH 1/6] Add SonarCloud workflow (coverage) Signed-off-by: Serhii Horodilov --- .github/workflows/sonarcloud.yml | 34 ++++++++++++++++++++++++++++++++ .gitignore | 1 + 2 files changed, 35 insertions(+) create mode 100644 .github/workflows/sonarcloud.yml diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml new file mode 100644 index 0000000..3dc6e00 --- /dev/null +++ b/.github/workflows/sonarcloud.yml @@ -0,0 +1,34 @@ +name: Collect coverage report for SonarCloud + +on: + push: + branches: + - master + pull_request: + branches: + - master + - devel + +jobs: + sonarcloud: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: "3.9" + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install pytest coverage + - name: Collect coverage + run: | + coverage run -m pytest + coverage xml + - name: Upload coverage report + uses: actions/upload-artifact@v2 + with: + name: coverage + path: ./coverage.xml diff --git a/.gitignore b/.gitignore index 9e2b438..deb125f 100644 --- a/.gitignore +++ b/.gitignore @@ -24,6 +24,7 @@ __pycache__ # coverage reports *.coverage.db *.coverage +coverage.* # local databases pgdata/ From c549ad968c13357eee2a71b07525f36316076f78 Mon Sep 17 00:00:00 2001 From: Serhii Horodilov Date: Thu, 17 Aug 2023 01:32:02 +0300 Subject: [PATCH 2/6] Update sonarcloud.yml workflow dependencies: coverage -> pytest-cov Signed-off-by: Serhii Horodilov --- .github/workflows/sonarcloud.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index 3dc6e00..7b07151 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -22,7 +22,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install pytest coverage + pip install pytest pytest-cov - name: Collect coverage run: | coverage run -m pytest From 3bbee49f5026be6af033b1c2d74eb0dc434cbc66 Mon Sep 17 00:00:00 2001 From: Serhii Horodilov Date: Thu, 17 Aug 2023 01:33:45 +0300 Subject: [PATCH 3/6] Update sonarcloud workflow: install local source packages --- .github/workflows/sonarcloud.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index 7b07151..3918d66 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -23,6 +23,9 @@ jobs: run: | python -m pip install --upgrade pip pip install pytest pytest-cov + - name: Install source packages + run: | + pip install -e . - name: Collect coverage run: | coverage run -m pytest From 027582915cb3d55cdf39f345d8662b5dce48ed8f Mon Sep 17 00:00:00 2001 From: Serhii Horodilov Date: Thu, 17 Aug 2023 02:04:46 +0300 Subject: [PATCH 4/6] Add SonarCloud Scan step --- .github/workflows/sonarcloud.yml | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index 3918d66..4a6e682 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -14,7 +14,9 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 + with: + fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis - name: Set up Python uses: actions/setup-python@v2 with: @@ -35,3 +37,13 @@ jobs: with: name: coverage path: ./coverage.xml + - name: SonarCloud Scan + uses: SonarSource/sonarcloud-github-action@master + with: + args: + -Dsonar.projectKey=edu-python-course_problem-sets + -Dsonar.organization=edu-python-course + -Dsonar.python.coverage.reportPaths=coverage.xml -X + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} \ No newline at end of file From 4f5836b550d682c7e0e0c6e1b8dbf909b042fc34 Mon Sep 17 00:00:00 2001 From: Serhii Horodilov Date: Thu, 17 Aug 2023 02:23:15 +0300 Subject: [PATCH 5/6] Update sonarcloud trigger events for pull request --- .github/workflows/sonarcloud.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index 4a6e682..dc41dee 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -5,6 +5,10 @@ on: branches: - master pull_request: + types: + - opened + - synchronize + - reopened branches: - master - devel From 83c0a1b0aa68a96850342bd178b409cd14a6c721 Mon Sep 17 00:00:00 2001 From: Serhii Horodilov Date: Thu, 17 Aug 2023 02:30:02 +0300 Subject: [PATCH 6/6] Update coverage run commands --- .github/workflows/sonarcloud.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index dc41dee..2f97849 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -34,7 +34,7 @@ jobs: pip install -e . - name: Collect coverage run: | - coverage run -m pytest + pytest --cov=src --quiet coverage xml - name: Upload coverage report uses: actions/upload-artifact@v2