Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(ci): add code coverage support #84

Merged
merged 1 commit into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
coverage:
precision: 2
range: "60...80"
round: down
51 changes: 41 additions & 10 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

name: Build, Test and Publish

on:
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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: |
Expand Down
1 change: 1 addition & 0 deletions .openapi-generator/FILES
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.codecov.yml
.fossa.yml
.github/CODEOWNERS
.github/ISSUE_TEMPLATE/bug_report.yaml
Expand Down
1 change: 0 additions & 1 deletion openfga_sdk/sync/open_fga_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT.
"""


Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is necessary to make the linter happy and pass the tests. I will check why it's catching it here, but the Generator output isn't.

from openfga_sdk.exceptions import ApiValueError, FgaValidationException
from openfga_sdk.sync.api_client import ApiClient
from openfga_sdk.sync.oauth2 import OAuth2Client
Expand Down
6 changes: 5 additions & 1 deletion test-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
-r requirements.txt

mock >= 5.1.0, < 6
autoflake==2.3.0
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are usually installed directly in the Generator's Makefile, but since we'll also be running tests here, let's transition them into the development dependencies manifest directly.

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