From 6789d21eb5bc9117cc6086e5158a54a7bd27d06a Mon Sep 17 00:00:00 2001 From: HIMANSHU Date: Thu, 14 Mar 2024 12:24:24 +0530 Subject: [PATCH 1/6] Feat:Sonar Integration --- .github/workflows/ci.yml | 68 +++++++++++++++++++++++----------------- .gitignore | 1 + 2 files changed, 40 insertions(+), 29 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6543c1a..b709eed 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,40 +1,50 @@ name: FastAPI-CI - -on: +'on': push: branches: - main pull_request: - types: [opened, synchronize, reopened] + types: + - opened + - synchronize + - reopened branches: - main - jobs: test: runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - uses: actions/setup-python@v4 - with: - python-version: 3.11.8 - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r requirements.txt - - - name: Install plugin - run: pip install pytest-github-actions-annotate-failures - - - name: Build coverage file - run: | - pytest --junitxml=pytest.xml --cov-report=term-missing:skip-covered --cov=app app/tests/ | tee pytest-coverage.txt - - - name: Pytest coverage comment - uses: MishaKav/pytest-coverage-comment@main - with: - pytest-coverage-path: ./pytest-coverage.txt - junitxml-path: ./pytest.xml - \ No newline at end of file + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: 3.11.8 + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + - name: Install plugin + run: pip install pytest-github-actions-annotate-failures + - name: Build coverage file + run: > + pytest --junitxml=pytest.xml --cov-report=term-missing:skip-covered + --cov=app app/tests/ | tee pytest-coverage.txt + - name: Pytest coverage comment + uses: MishaKav/pytest-coverage-comment@main + with: + pytest-coverage-path: ./pytest-coverage.txt + junitxml-path: ./pytest.xml + - name: SonarQube Scan + uses: sonarsource/sonarqube-scan-action@master + with: + args: | + -Dsonar.scm.revision=${{ github.event.pull_request.head.sha }} + env: + GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}' + SONAR_TOKEN: '${{ secrets.SONAR_TOKEN }}' + SONAR_HOST_URL: '${{ secrets.SONAR_HOST_URL }}' + - uses: sonarsource/sonarqube-quality-gate-action@master + timeout-minutes: 5 + env: + GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}' + SONAR_TOKEN: '${{ secrets.SONAR_TOKEN }}' + SONAR_HOST_URL: '${{ secrets.SONAR_HOST_URL }}' diff --git a/.gitignore b/.gitignore index b091b48..e964998 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,4 @@ venv tmp/ temp/ *.xml +.idea From c220f162775b673438d250f978dd4a8e39cb1bbd Mon Sep 17 00:00:00 2001 From: HIMANSHU Date: Thu, 14 Mar 2024 12:48:41 +0530 Subject: [PATCH 2/6] Feat:Sonar Integration --- sonar-project.properties | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 sonar-project.properties diff --git a/sonar-project.properties b/sonar-project.properties new file mode 100644 index 0000000..09518b1 --- /dev/null +++ b/sonar-project.properties @@ -0,0 +1,10 @@ +sonar.projectKey=wednesday-solutions_python-fastapi_AY434cJSB2n8RRmGoUoD +sonar.projectName=python-fastapi +sonar.projectVersion=1.0 +sonar.sources=./app +sonar.test.inclusions=**/*_test.py +sonar.tests=./app +sonar.language=py +sonar.sourceEncoding=UTF-8 +sonar.python.tests.reportPaths=test-report.json +sonar.python.coverage.reportPaths=test-coverage.out From 9ef1eb4389d8ec89e1059f302d164d5afb6e9c5e Mon Sep 17 00:00:00 2001 From: HIMANSHU Date: Fri, 15 Mar 2024 18:34:12 +0530 Subject: [PATCH 3/6] Updated with latest master --- sonar-project.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sonar-project.properties b/sonar-project.properties index 09518b1..f5c6118 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -2,7 +2,7 @@ sonar.projectKey=wednesday-solutions_python-fastapi_AY434cJSB2n8RRmGoUoD sonar.projectName=python-fastapi sonar.projectVersion=1.0 sonar.sources=./app -sonar.test.inclusions=**/*_test.py +sonar.test.inclusions=**/test_*.py sonar.tests=./app sonar.language=py sonar.sourceEncoding=UTF-8 From 28279a56a07916d6639f602994b1c8b99a90619d Mon Sep 17 00:00:00 2001 From: HIMANSHU Date: Fri, 15 Mar 2024 18:56:50 +0530 Subject: [PATCH 4/6] Updated with latest master --- scripts/run_tests.sh | 2 +- sonar-project.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/run_tests.sh b/scripts/run_tests.sh index 15b1265..ef95e33 100755 --- a/scripts/run_tests.sh +++ b/scripts/run_tests.sh @@ -1,2 +1,2 @@ coverage run -m pytest -coverage report \ No newline at end of file +coverage xml diff --git a/sonar-project.properties b/sonar-project.properties index f5c6118..934f6be 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -7,4 +7,4 @@ sonar.tests=./app sonar.language=py sonar.sourceEncoding=UTF-8 sonar.python.tests.reportPaths=test-report.json -sonar.python.coverage.reportPaths=test-coverage.out +sonar.python.coverage.reportPaths=coverage.xml From d89bb8d80e7ad63e2439cb2d049a794ea2781921 Mon Sep 17 00:00:00 2001 From: HIMANSHU Date: Sat, 16 Mar 2024 00:47:44 +0530 Subject: [PATCH 5/6] Updated with latest master --- sonar-project.properties | 1 + 1 file changed, 1 insertion(+) diff --git a/sonar-project.properties b/sonar-project.properties index 934f6be..b64174e 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -6,5 +6,6 @@ sonar.test.inclusions=**/test_*.py sonar.tests=./app sonar.language=py sonar.sourceEncoding=UTF-8 +sonar.coverage.exclusions=**/*.* sonar.python.tests.reportPaths=test-report.json sonar.python.coverage.reportPaths=coverage.xml From bb76458b6bbcd9098cbe47345fbf9b0b3c6e131e Mon Sep 17 00:00:00 2001 From: Anas WS Date: Mon, 18 Mar 2024 11:10:09 +0530 Subject: [PATCH 6/6] minor change in run_tests.sh --- scripts/run_tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/run_tests.sh b/scripts/run_tests.sh index ef95e33..59110e5 100755 --- a/scripts/run_tests.sh +++ b/scripts/run_tests.sh @@ -1,2 +1,2 @@ coverage run -m pytest -coverage xml +coverage report