Skip to content

Commit

Permalink
Chore: Add Poe task support and code coverage reporting (#231)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronsteers authored May 14, 2024
1 parent f4cd1ce commit 7859c10
Show file tree
Hide file tree
Showing 10 changed files with 196 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/autofix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Poetry
uses: Gr1N/setup-poetry@v8
uses: Gr1N/setup-poetry@v9
with:
poetry-version: "1.7.1"
- name: Set up Python
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/fix-pr-command.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ jobs:
[1]: ${{ steps.vars.outputs.run-url }}
- name: Set up Poetry
uses: Gr1N/setup-poetry@v8
uses: Gr1N/setup-poetry@v9
with:
poetry-version: "1.7.1"
- name: Set up Python
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pydoc_preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Poetry
uses: Gr1N/setup-poetry@v8
uses: Gr1N/setup-poetry@v9
with:
poetry-version: "1.7.1"
- name: Set up Python
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pydoc_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Poetry
uses: Gr1N/setup-poetry@v8
uses: Gr1N/setup-poetry@v9
with:
poetry-version: "1.7.1"
- name: Set up Python
Expand Down
12 changes: 9 additions & 3 deletions .github/workflows/python_lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Poetry
uses: Gr1N/setup-poetry@v8
uses: Gr1N/setup-poetry@v9
with:
poetry-version: "1.7.1"
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
cache: 'poetry'
- name: Install dependencies
run: poetry install

# Job-specifc step(s):
- name: Format code
Expand All @@ -39,14 +41,16 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Poetry
uses: Gr1N/setup-poetry@v8
uses: Gr1N/setup-poetry@v9
with:
poetry-version: "1.7.1"
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
cache: 'poetry'
- name: Install dependencies
run: poetry install

# Job-specifc step(s):
- name: Check code format
Expand All @@ -60,14 +64,16 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Poetry
uses: Gr1N/setup-poetry@v8
uses: Gr1N/setup-poetry@v9
with:
poetry-version: "1.7.1"
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
cache: 'poetry'
- name: Install dependencies
run: poetry install

# Job-specifc step(s):
- name: Check MyPy typing
Expand Down
67 changes: 59 additions & 8 deletions .github/workflows/python_pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Poetry
uses: Gr1N/setup-poetry@v8
uses: Gr1N/setup-poetry@v9
with:
poetry-version: "1.7.1"
- name: Set up Python
Expand All @@ -39,15 +39,31 @@ jobs:
- name: Install dependencies
run: poetry install

# Job-specific step(s):
- name: Run Pytest (Fast Tests Only)
- name: Run Pytest with Coverage (Fast Tests Only)
env:
GCP_GSM_CREDENTIALS: ${{ secrets.GCP_GSM_CREDENTIALS }}
run: >
poetry run pytest -m
poetry run coverage run -m pytest -m
"not slow and not requires_creds and not linting"
--durations=5 --exitfirst
- name: Print Coverage Report
if: always()
run: poetry run coverage report

- name: Create Coverage Artifacts
if: always()
run: |
poetry run coverage html -d htmlcov
poetry run coverage xml -o htmlcov/coverage.xml
- name: Upload coverage to GitHub Artifacts
if: always()
uses: actions/upload-artifact@v4
with:
name: fasttest-coverage
path: htmlcov/

pytest-no-creds:
name: Pytest (No Creds)
runs-on: ubuntu-latest
Expand All @@ -56,7 +72,7 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Poetry
uses: Gr1N/setup-poetry@v8
uses: Gr1N/setup-poetry@v9
with:
poetry-version: "1.7.1"
- name: Set up Python
Expand All @@ -73,9 +89,26 @@ jobs:
# Force this to a blank value.
GCP_GSM_CREDENTIALS: ""
run: >
poetry run pytest -m
poetry run coverage run -m pytest -m
"not requires_creds and not linting and not super_slow"
- name: Print Coverage Report
if: always()
run: poetry run coverage report

- name: Create Coverage Artifacts
if: always()
run: |
poetry run coverage html -d htmlcov
poetry run coverage xml -o htmlcov/coverage.xml
- name: Upload coverage to GitHub Artifacts
if: always()
uses: actions/upload-artifact@v4
with:
name: nocreds-test-coverage
path: htmlcov/

pytest:
name: Pytest (All, Python ${{ matrix.python-version }}, ${{ matrix.os }})
# Don't run on forks. Run on pushes to main, and on PRs that are not from forks.
Expand All @@ -101,7 +134,7 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Poetry
uses: Gr1N/setup-poetry@v8
uses: Gr1N/setup-poetry@v9
with:
poetry-version: "1.7.1"
- name: Set up Python
Expand All @@ -117,4 +150,22 @@ jobs:
env:
GCP_GSM_CREDENTIALS: ${{ secrets.GCP_GSM_CREDENTIALS }}
run: >
poetry run pytest -m "not linting and not super_slow"
poetry run coverage run -m pytest -m
"not linting and not super_slow"
- name: Print Coverage Report
if: always()
run: poetry run coverage report

- name: Create Coverage Artifacts
if: always()
run: |
poetry run coverage html -d htmlcov
poetry run coverage xml -o htmlcov/coverage.xml
- name: Upload coverage to GitHub Artifacts
if: always()
uses: actions/upload-artifact@v4
with:
name: py${{ matrix.python-version }}-${{ matrix.os }}-test-coverage
path: htmlcov/
2 changes: 1 addition & 1 deletion .github/workflows/test-pr-command.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ jobs:
# Same as the `python_pytest.yml` file:

- name: Set up Poetry
uses: Gr1N/setup-poetry@v8
uses: Gr1N/setup-poetry@v9
with:
poetry-version: "1.7.1"
- name: Set up Python
Expand Down
17 changes: 15 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,26 @@ Releases are published automatically to PyPi in response to a "published" event
To publish to PyPi, simply [create a GitHub Release](https://github.com/airbytehq/PyAirbyte/releases/new) with the correct version. Once you publish the release on GitHub it will automatically trigger a PyPi publish workflow in GitHub actions.

> **Warning**
>
>
> Be careful - "Cmd+Enter" will not 'save' but will instead 'publish'. (If you want to save a draft, use the mouse. 😅)
> **Note**
>
>
> There is no version to bump. Version is calculated during build and publish, using the [poetry-dynamic-versioning](https://github.com/mtkennerly/poetry-dynamic-versioning) plugin.
## Coverage

To run a coverage report, run:

```console
poetry run poe coverage-html
```

This will generate a coverage report in the `htmlcov` folder.

Note: If you have pre-installed [Poe](https://poethepoet.natn.io/index.html)
(`pipx install poethepoet`), then you can omit the `poetry run` prefix.

## Versioning

Versioning follows [Semantic Versioning](https://semver.org/). For new features, bump the minor version. For bug fixes, bump the patch version. For pre-releases, append `dev.N` to the version. For example, `0.1.0dev.1` is the first pre-release of the `0.1.0` version.
95 changes: 94 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 14 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ tomli = "^2.0"
responses = "^0.25.0"
airbyte-source-pokeapi = "^0.2.0"
pytest-mock = "^3.14.0"
poethepoet = "^0.26.1"
coverage = "^7.5.1"

[build-system]
requires = ["poetry-core>=1.0.0", "poetry-dynamic-versioning>=1.0.0,<2.0.0"]
Expand Down Expand Up @@ -285,7 +287,18 @@ generate-docs = "docs.generate:run"
airbyte-lib-validate-source = "airbyte.validate:run"

[tool.poe.tasks]
test = "pytest tests"
test = { shell = "pytest" }

coverage = { shell = "coverage run -m pytest && coverage report" }
coverage-report = { shell = "coverage report" }
coverage-html = { shell = "coverage html -d htmlcov && open htmlcov/index.html" }
coverage-reset = { shell = "coverage erase" }

check = { shell = "ruff check . && mypy ." }

fix = { shell = "ruff format . && ruff check --fix -s || ruff format ." }
fix-unsafe = { shell = "ruff format . && ruff check --fix --unsafe-fixes . && ruff format ." }
fix-and-check = { shell = "poe fix && poe check" }

[tool.airbyte_ci]
extra_poetry_groups = ["dev"]
Expand Down

0 comments on commit 7859c10

Please sign in to comment.