Skip to content

Commit

Permalink
build: Update test and publish workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
empicano committed May 18, 2023
1 parent bbf6273 commit 6f211dc
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 45 deletions.
18 changes: 6 additions & 12 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: docs
name: Build documentation

on:
push:
branches: [main, poetry-and-rename]
branches: [main]
paths:
- "docs/**"
- README.md
Expand All @@ -22,24 +22,18 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up Python
id: setup-python
uses: actions/setup-python@v4 # Uses the Python version in the .python-version file
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: "1.4.2"
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
- name: Load cached dependencies
id: cache
uses: actions/cache@v3
- name: Set up Python
id: setup-python
uses: actions/setup-python@v4 # Uses the Python version in .python-version
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('poetry.lock') }}
cache: "poetry"
- name: Install dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: scripts/setup
- name: Build documentation
run: poetry run sphinx-build -b html docs docs/_build
Expand Down
40 changes: 30 additions & 10 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,44 @@
name: Publish package to PyPI
name: Publish to PyPI

on:
release:
types: [published]
pull_request:

jobs:
publish:
runs-on: ubuntu-latest
defaults:
run:
shell: bash
environment:
name: test-pypi
url: https://test.pypi.org/project/aiomqtt-test
permissions:
id-token: write
steps:
- name: Checkout
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0 # Fetch entire history for poetry-dynamic-versioning
- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
- name: Set up Python
uses: actions/setup-python@v4
id: setup-python
uses: actions/setup-python@v4 # Uses the Python version in .python-version
with:
python-version: 3.x
- name: Install dependencies
run: pip install build
- name: Create package
run: python -m build -s -w .
- name: Upload package
cache: "poetry"
- name: Setup dynamic versioning
run: poetry self add "poetry-dynamic-versioning[plugin]"
- name: Build package
run: poetry build
# - name: Publish to PyPI
# uses: pypa/gh-action-pypi-publish@release/v1
- name: Publish to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
repository-url: https://test.pypi.org/legacy/
31 changes: 18 additions & 13 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: test suite
name: Run tests

on:
push:
Expand All @@ -22,32 +22,37 @@ jobs:
- os: windows-latest
python-version: "3.11"
runs-on: ${{ matrix.os }}
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v3
- name: Checkout repository
uses: actions/checkout@v3
- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- uses: actions/cache@v3
with:
path: ~/.cache/pip
key: pip-test-${{ matrix.python-version }}-${{ matrix.os }}
cache: "poetry"
- name: Install dependencies
run: pip install -e .[lint,tests]
- name: Run Ruff
run: ruff --format=github .
- name: Run mypy
run: mypy .
run: rm poetry.lock && script/setup # Ignore poetry.lock
- name: Run checks
run: scripts/check
- name: Test with pytest
run: pytest --cov=asyncio_mqtt --cov=tests --cov-report=xml
run: scripts/test
- name: Upload coverage
uses: codecov/codecov-action@v3
with:
name: ${{ matrix.os }} Python ${{ matrix.python-version }}
files: ./reports/coverage.xml
- name: Publish JUnit reports
uses: mikepenz/action-junit-report@v3
if: always() # always run even if the previous step fails
if: always() # Always run, even if the previous step fails
with:
check_name: Junit reports
report_paths: "./reports/*.xml"
10 changes: 1 addition & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ build-backend = "poetry_dynamic_versioning.backend"
target-version = ["py37", "py38", "py39", "py310", "py311"]

[tool.ruff]
required-version = "0.0.262"
required-version = "0.0.263"
target-version = "py37"
select = ["ALL"]
ignore = [
Expand Down Expand Up @@ -108,7 +108,6 @@ pretty = true
no_strict_concatenate = true # TODO: remove when dropping python 3.7

[tool.pytest.ini_options] # https://docs.pytest.org/en/latest/reference/reference.html#ini-options-ref
addopts = "--color=yes --doctest-modules --exitfirst --failed-first --strict-config --strict-markers --verbosity=2 --junitxml=reports/pytest.xml tests"
filterwarnings = [
"error",
"ignore:ssl.PROTOCOL_TLS is deprecated:DeprecationWarning",
Expand All @@ -117,13 +116,9 @@ xfail_strict = true

[tool.coverage.run] # https://coverage.readthedocs.io/en/latest/config.html#run
branch = true
data_file = "reports/.coverage"

[tool.coverage.report] # https://coverage.readthedocs.io/en/latest/config.html#report
fail_under = 85
precision = 1
show_missing = true
skip_covered = true
# Regexes for lines to exclude from consideration
exclude_lines = [
# Have to re-enable the standard pragma
Expand All @@ -132,6 +127,3 @@ exclude_lines = [
"raise AssertionError",
"raise NotImplementedError",
]

[tool.coverage.xml] # https://coverage.readthedocs.io/en/latest/config.html#xml
output = "reports/coverage.xml"
10 changes: 10 additions & 0 deletions scripts/check
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

# Safety first
set -o errexit -o pipefail -o nounset
# Change into the project's directory
cd "$(dirname "$0")/.."

# Check with ruff and mypy
poetry run ruff check asyncio_mqtt tests
poetry run mypy asyncio_mqtt tests
2 changes: 1 addition & 1 deletion scripts/setup
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ set -o errexit -o pipefail -o nounset
cd "$(dirname "$0")/.."

# Install the dependencies
poetry install --with dev
poetry install --with dev --sync
9 changes: 9 additions & 0 deletions scripts/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

# Safety first
set -o errexit -o pipefail -o nounset
# Change into the project's directory
cd "$(dirname "$0")/.."

# Run tests with pytest
poetry run pytest --failed-first --strict-config --strict-markers --verbosity=2 --cov=asyncio_mqtt --cov-report=xml --junitxml=reports/pytest.xml tests

0 comments on commit 6f211dc

Please sign in to comment.