From 3b0208c64b88edab6b0d582c887c654cc58c869d 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 | 51 +++++++++++++++++++++++++------- .openapi-generator/FILES | 1 + openfga_sdk/sync/open_fga_api.py | 1 - test-requirements.txt | 6 +++- 5 files changed, 51 insertions(+), 12 deletions(-) create mode 100644 .codecov.yml 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.yaml index 8d4ff77..a00131e 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -1,3 +1,4 @@ + name: Build, Test and Publish on: @@ -6,15 +7,22 @@ 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 @@ -26,22 +34,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 +86,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..ad89c57 100644 --- a/.openapi-generator/FILES +++ b/.openapi-generator/FILES @@ -1,3 +1,4 @@ +.codecov.yml .fossa.yml .github/CODEOWNERS .github/ISSUE_TEMPLATE/bug_report.yaml 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