From c252d868939d4e03474ccc00b76a7ce8d21042c8 Mon Sep 17 00:00:00 2001 From: Heitor Polizeli Rodrigues Date: Sat, 5 Apr 2025 11:19:31 -0300 Subject: [PATCH 1/7] feat: add github actions --- .github/workflows/build-test.yaml | 77 +++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 .github/workflows/build-test.yaml diff --git a/.github/workflows/build-test.yaml b/.github/workflows/build-test.yaml new file mode 100644 index 0000000..85b0eaa --- /dev/null +++ b/.github/workflows/build-test.yaml @@ -0,0 +1,77 @@ +name: Build and test + +on: + pull_request: + branches: + - main + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + test: + name: Run Tests with Testcontainers + runs-on: ubuntu-latest + + services: + docker: + image: docker:24.0.7 + options: >- + --privileged + + env: + UV_CACHE_DIR: .uv-cache + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.13" + + - name: Install uv + uses: yezz123/setup-uv@v4 + with: + uv-version: "latest" + + - name: Cache uv dependencies + uses: actions/cache@v4 + with: + path: .uv-cache + key: uv-${{ runner.os }}-${{ hashFiles('pyproject.toml', 'uv.lock') }} + restore-keys: | + uv-${{ runner.os }}- + + - name: Install dependencies with uv + run: | + uv venv + source .venv/bin/activate + uv pip install -e . -r <(uv pip compile --group dev) + + - name: Set Docker host for Testcontainers + run: | + echo "DOCKER_HOST=unix:///var/run/docker.sock" >> $GITHUB_ENV + + - name: Run ruff (lint) + run: | + source .venv/bin/activate + ruff check . + + - name: Run pyright (type check) + run: | + source .venv/bin/activate + pyright + + - name: Run tests with pytest + run: | + source .venv/bin/activate + pytest + + - name: Upload coverage report + uses: actions/upload-artifact@v4 + with: + name: coverage-report + path: coverage.xml From f87b724b8dd65a8ae1d932abafbf42f72c07e6d4 Mon Sep 17 00:00:00 2001 From: Heitor Polizeli Rodrigues Date: Sat, 5 Apr 2025 11:27:38 -0300 Subject: [PATCH 2/7] chore: setup uv v5 --- .github/workflows/build-test.yaml | 44 +++++++------------------------ 1 file changed, 10 insertions(+), 34 deletions(-) diff --git a/.github/workflows/build-test.yaml b/.github/workflows/build-test.yaml index 85b0eaa..3c41948 100644 --- a/.github/workflows/build-test.yaml +++ b/.github/workflows/build-test.yaml @@ -20,55 +20,31 @@ jobs: options: >- --privileged - env: - UV_CACHE_DIR: .uv-cache - steps: - name: Checkout code uses: actions/checkout@v4 - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: "3.13" - - - name: Install uv - uses: yezz123/setup-uv@v4 - with: - uv-version: "latest" - - - name: Cache uv dependencies - uses: actions/cache@v4 + - name: Setup uv + id: setup-uv + uses: astral-sh/setup-uv@v5 with: - path: .uv-cache - key: uv-${{ runner.os }}-${{ hashFiles('pyproject.toml', 'uv.lock') }} - restore-keys: | - uv-${{ runner.os }}- + enable-cache: true + cache-suffix: "uv-cache" - name: Install dependencies with uv - run: | - uv venv - source .venv/bin/activate - uv pip install -e . -r <(uv pip compile --group dev) + run: uv sync - name: Set Docker host for Testcontainers - run: | - echo "DOCKER_HOST=unix:///var/run/docker.sock" >> $GITHUB_ENV + run: echo "DOCKER_HOST=unix:///var/run/docker.sock" >> $GITHUB_ENV - name: Run ruff (lint) - run: | - source .venv/bin/activate - ruff check . + run: uv run --frozen ruff check . - name: Run pyright (type check) - run: | - source .venv/bin/activate - pyright + run: uv run --frozen pyright - name: Run tests with pytest - run: | - source .venv/bin/activate - pytest + run: uv run --frozen pytest - name: Upload coverage report uses: actions/upload-artifact@v4 From 35775c4a8a7bed0a7672e9f7b9503bac0547a9e0 Mon Sep 17 00:00:00 2001 From: Heitor Polizeli Rodrigues Date: Sat, 5 Apr 2025 14:56:02 -0300 Subject: [PATCH 3/7] chore: add coverage check --- .github/workflows/build-test.yaml | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-test.yaml b/.github/workflows/build-test.yaml index 3c41948..ba962b9 100644 --- a/.github/workflows/build-test.yaml +++ b/.github/workflows/build-test.yaml @@ -11,7 +11,7 @@ concurrency: jobs: test: - name: Run Tests with Testcontainers + name: Run Tests runs-on: ubuntu-latest services: @@ -51,3 +51,15 @@ jobs: with: name: coverage-report path: coverage.xml + + - name: Validate coverage is >= 99% + run: | + total=$(xmllint --xpath "string(//coverage/@line-rate)" coverage.xml) + percent=$(awk "BEGIN {printf \"%.2f\", $total * 100}") + echo "Total coverage: $percent%" + if (( $(echo "$percent < 99.0" | bc -l) )); then + echo "❌ Coverage is below 99%" + exit 1 + else + echo "✅ Coverage check passed" + fi From 5362ab0b2a6e4ae5b30e49e5e58707109e147115 Mon Sep 17 00:00:00 2001 From: Heitor Polizeli Rodrigues Date: Sat, 5 Apr 2025 15:00:06 -0300 Subject: [PATCH 4/7] chore: add coverage check 2 --- .github/workflows/build-test.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-test.yaml b/.github/workflows/build-test.yaml index ba962b9..d4c6bef 100644 --- a/.github/workflows/build-test.yaml +++ b/.github/workflows/build-test.yaml @@ -54,11 +54,11 @@ jobs: - name: Validate coverage is >= 99% run: | - total=$(xmllint --xpath "string(//coverage/@line-rate)" coverage.xml) + total=$(grep -oP 'line-rate="\K[0-9.]+' coverage.xml) percent=$(awk "BEGIN {printf \"%.2f\", $total * 100}") echo "Total coverage: $percent%" if (( $(echo "$percent < 99.0" | bc -l) )); then - echo "❌ Coverage is below 99%" + echo "❌ Coverage check failed — current coverage is ${percent}%, required is >= 99%" exit 1 else echo "✅ Coverage check passed" From f113068cce97e7d389f2e80746be591eccb24f1e Mon Sep 17 00:00:00 2001 From: Heitor Polizeli Rodrigues Date: Sat, 5 Apr 2025 15:11:22 -0300 Subject: [PATCH 5/7] chore: sonar scan --- .github/workflows/build-test.yaml | 20 +++++++++----------- README.md | 2 ++ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/build-test.yaml b/.github/workflows/build-test.yaml index d4c6bef..f57040d 100644 --- a/.github/workflows/build-test.yaml +++ b/.github/workflows/build-test.yaml @@ -52,14 +52,12 @@ jobs: name: coverage-report path: coverage.xml - - name: Validate coverage is >= 99% - run: | - total=$(grep -oP 'line-rate="\K[0-9.]+' coverage.xml) - percent=$(awk "BEGIN {printf \"%.2f\", $total * 100}") - echo "Total coverage: $percent%" - if (( $(echo "$percent < 99.0" | bc -l) )); then - echo "❌ Coverage check failed — current coverage is ${percent}%, required is >= 99%" - exit 1 - else - echo "✅ Coverage check passed" - fi + - name: SonarCloud Scan + uses: SonarSource/sonarcloud-github-action@master + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + with: + args: > + -Dsonar.projectKey=heitorpr_python-template + -Dsonar.organization=heitorpr + -Dsonar.python.coverage.reportPaths=coverage.xml diff --git a/README.md b/README.md index a71420a..8104247 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=heitorpr_python-template&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=heitorpr_python-template) + # setup uv ```shell From 2b08c91c739807c4a15f0e130c2b714a2c13cb49 Mon Sep 17 00:00:00 2001 From: Heitor Polizeli Rodrigues Date: Sat, 5 Apr 2025 15:17:37 -0300 Subject: [PATCH 6/7] chore: sonar scan 2 --- .github/workflows/build-test.yaml | 9 ++------- sonar-project.properties | 2 ++ 2 files changed, 4 insertions(+), 7 deletions(-) create mode 100644 sonar-project.properties diff --git a/.github/workflows/build-test.yaml b/.github/workflows/build-test.yaml index f57040d..1c2676b 100644 --- a/.github/workflows/build-test.yaml +++ b/.github/workflows/build-test.yaml @@ -52,12 +52,7 @@ jobs: name: coverage-report path: coverage.xml - - name: SonarCloud Scan - uses: SonarSource/sonarcloud-github-action@master + - name: SonarQube Scan + uses: SonarSource/sonarqube-scan-action@v5 env: SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - with: - args: > - -Dsonar.projectKey=heitorpr_python-template - -Dsonar.organization=heitorpr - -Dsonar.python.coverage.reportPaths=coverage.xml diff --git a/sonar-project.properties b/sonar-project.properties new file mode 100644 index 0000000..2d991e0 --- /dev/null +++ b/sonar-project.properties @@ -0,0 +1,2 @@ +sonar.projectKey=heitorpr_python-template +sonar.organization=heitorpr From 4c88b0d4bd924212f40301e0f5b258aa8e556e52 Mon Sep 17 00:00:00 2001 From: Heitor Polizeli Rodrigues Date: Sat, 5 Apr 2025 15:20:47 -0300 Subject: [PATCH 7/7] chore: sonar scan 3 --- sonar-project.properties | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sonar-project.properties b/sonar-project.properties index 2d991e0..bf0d98c 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -1,2 +1,5 @@ sonar.projectKey=heitorpr_python-template sonar.organization=heitorpr +sonar.sources=src +sonar.tests=tests +sonar.python.coverage.reportPaths=coverage.xml