From 1ba95c2ecfcccc686a48254535a40e9ad02c82b0 Mon Sep 17 00:00:00 2001 From: Evan Sims Date: Tue, 2 Apr 2024 18:21:38 -0500 Subject: [PATCH] chore(ci): add code coverage support --- .codecov.yml | 4 ++ .github/workflows/{main.yaml => main.yml} | 52 ++++++++++++++++++----- .openapi-generator/FILES | 3 +- openfga_sdk/sync/open_fga_api.py | 1 - test-requirements.txt | 6 ++- 5 files changed, 52 insertions(+), 14 deletions(-) create mode 100644 .codecov.yml rename .github/workflows/{main.yaml => main.yml} (58%) diff --git a/.codecov.yml b/.codecov.yml new file mode 100644 index 0000000..0385c10 --- /dev/null +++ b/.codecov.yml @@ -0,0 +1,4 @@ +coverage: + precision: 2 + range: "60...80" + round: down diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yml similarity index 58% rename from .github/workflows/main.yaml rename to .github/workflows/main.yml index 8d4ff77..4614638 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yml @@ -6,19 +6,26 @@ on: pull_request: workflow_dispatch: +concurrency: + group: ${{ github.head_ref || github.run_id }} + cancel-in-progress: true + jobs: test: runs-on: ubuntu-latest + strategy: fail-fast: false matrix: python-version: ["3.10", "3.11", "3.12"] + steps: - - uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2 + - name: Checkout code + uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2 with: fetch-depth: 0 - - name: Set up Python ${{ matrix.python-version }} + - name: Set up Python${{ matrix.python-version }} uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v5.1.0 with: python-version: ${{ matrix.python-version }} @@ -26,22 +33,44 @@ jobs: cache-dependency-path: | **/setup.cfg **/requirements*.txt + **/test-requirements*.txt + - name: Install dependencies - run: | - python -m pip install -r test-requirements.txt - - name: Test - run: python -m pytest - - name: Flake8 + run: pip install -r test-requirements.txt --upgrade pip + + - if: matrix.python-version == '3.10' + name: Run Flake8 run: flake8 . --count --show-source --statistics + - if: matrix.python-version == '3.10' + name: Run Black + run: black . --check + + - if: matrix.python-version == '3.10' + name: Run isort + run: isort . --profile black --diff --check-only + + - if: matrix.python-version == '3.10' + name: Run autoflake + run: autoflake --exclude=__init__.py --remove-unused-variables --remove-all-unused-imports --quiet --check-diff --recursive . + + - name: Run tests and collect coverage + run: pytest --cov-fail-under 60 --cov openfga_sdk + + - if: matrix.python-version == '3.10' + name: Upload coverage to Codecov + uses: codecov/codecov-action@c16abc29c95fcf9174b58eb7e1abf4c866893bc8 # v4.1.1 + with: + token: ${{ secrets.CODECOV_TOKEN }} + slug: openfga/python-sdk + publish: runs-on: ubuntu-latest if: startsWith(github.ref, 'refs/tags/v') needs: [test] permissions: - # Required for PyPI trusted publishing - id-token: write + id-token: write # Required for PyPI trusted publishing steps: - uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2 @@ -56,9 +85,10 @@ jobs: cache-dependency-path: | **/setup.cfg **/requirements*.txt + **/test-requirements*.txt + - name: Install dependencies - run: | - python -m pip install -r test-requirements.txt + run: pip install -r test-requirements.txt --upgrade pip - name: Build package run: | diff --git a/.openapi-generator/FILES b/.openapi-generator/FILES index 86ea4be..884e274 100644 --- a/.openapi-generator/FILES +++ b/.openapi-generator/FILES @@ -1,10 +1,11 @@ +.codecov.yml .fossa.yml .github/CODEOWNERS .github/ISSUE_TEMPLATE/bug_report.yaml .github/ISSUE_TEMPLATE/config.yaml .github/ISSUE_TEMPLATE/feature_request.yaml .github/dependabot.yaml -.github/workflows/main.yaml +.github/workflows/main.yml .github/workflows/semgrep.yaml .gitignore .snyk diff --git a/openfga_sdk/sync/open_fga_api.py b/openfga_sdk/sync/open_fga_api.py index 92e7a29..09a8c7d 100644 --- a/openfga_sdk/sync/open_fga_api.py +++ b/openfga_sdk/sync/open_fga_api.py @@ -10,7 +10,6 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ - from openfga_sdk.exceptions import ApiValueError, FgaValidationException from openfga_sdk.sync.api_client import ApiClient from openfga_sdk.sync.oauth2 import OAuth2Client diff --git a/test-requirements.txt b/test-requirements.txt index 37be0b6..0e1083a 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,6 +1,10 @@ -r requirements.txt mock >= 5.1.0, < 6 +autoflake==2.3.0 +black==24.2.0 flake8 >= 7.0.0, < 8 -pytest-cov >= 5, < 6 griffe >= 0.41.2, < 1 +isort==5.13.2 +pytest-cov >= 5, < 6 +pyupgrade==3.15.1