Skip to content

Commit

Permalink
Setup test automation with nox
Browse files Browse the repository at this point in the history
  • Loading branch information
lampajr committed Mar 25, 2024
1 parent 46ff8ce commit 97988fa
Show file tree
Hide file tree
Showing 7 changed files with 229 additions and 33 deletions.
32 changes: 22 additions & 10 deletions .github/workflows/check-openapi-change.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# This workflow will fetch the new openapi from the provided branch of https://github.com/Hyperfoil/Horreum and based on
# that it will re-generate the Horreum raw client and check the build/tests are still working.
# It could be tested running `gh act workflow_dispatch -e ./test/workflow_dispatch_event_example.json`. Remember to
# comment out the pull request creation :)
# It could be tested running `gh act workflow_dispatch -e ./test/workflow_dispatch_event_example.json`.
name: Update Horreum auto-generated client

on:
Expand All @@ -18,6 +17,13 @@ jobs:
check-openapi-change:
# TODO: find a way to set name including the branch we are checking
runs-on: ubuntu-latest
env:
FORCE_COLOR: "1"
PRE_COMMIT_COLOR: "always"
strategy:
fail-fast: false
matrix:
python: [ "3.9", "3.10", "3.11" ]
steps:
- name: Fetch Horreum branch
id: fetch-horreum-branch
Expand Down Expand Up @@ -45,14 +51,20 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Generate horreum client
run: make HORREUM_BRANCH=${{ steps.fetch-horreum-branch.outputs.horreum_branch }} generate
python-version: ${{ matrix.python }}
- name: Upgrade pip
run: |
pip install --constraint=./dev-constraints.txt pip
pip --version
- name: Install poetry
run: |
pipx install --pip-args=--constraint=./dev-constraints.txt poetry
pip install --constraint=./dev-constraints.txt poetry
poetry --version
- name: Build python library
run: poetry build
- name: Test horreum library
run: pytest test/horreum_client_test.py
- name: Install Nox
run: |
pip install --constraint=./dev-constraints.txt nox nox-poetry
nox --version
- name: Generate horreum client
run: make HORREUM_BRANCH=${{ steps.fetch-horreum-branch.outputs.horreum_branch }} generate
- name: Test horreum
run: nox --python=${{ matrix.python }} -s tests
25 changes: 14 additions & 11 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# This workflow will run the full CI for the Horreum python library including the build and the tests execution
# This is going to be triggered on every pull request as well as on main branch.
# TODO: trigger tests once implemented
name: Python client ci

on:
Expand All @@ -11,7 +10,7 @@ on:

jobs:
test:
name: ${{ matrix.session }} ${{ matrix.python }}
name: test/${{ matrix.python }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
Expand All @@ -27,15 +26,19 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
- name: Generate horreum client
run: make generate
- name: Upgrade pip
run: |
pip install --constraint=./dev-constraints.txt pip
pip --version
- name: Install poetry
run: |
pipx install --pip-args=--constraint=./dev-constraints.txt poetry
pip install --constraint=./dev-constraints.txt poetry
poetry --version
- name: Install dependencies
run: poetry install
- name: Build python library
run: poetry build
- name: Test horreum library
run: poetry run pytest test/horreum_client_test.py
- name: Install Nox
run: |
pip install --constraint=./dev-constraints.txt nox nox-poetry
nox --version
- name: Generate horreum client
run: make generate
- name: Test horreum
run: nox --python=${{ matrix.python }} -s tests
33 changes: 23 additions & 10 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,10 @@ jobs:
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
env:
FORCE_COLOR: "1"
PY_VERSION: "3.10"
steps:
- name: Check out the repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install poetry
run: |
pipx install --pip-args=--constraint=./dev-constraints.txt poetry
poetry --version
- name: Check version coherence
run: |
PROJECT_VERSION=$(poetry version | cut -d' ' -f2)
Expand All @@ -36,9 +29,29 @@ jobs:
echo "::error title='$GIT_TAG tag does not match project version'::"
exit 1
fi
- name: Build python library
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${PY_VERSION}
- name: Upgrade pip
run: |
pip install --constraint=./dev-constraints.txt pip
pip --version
- name: Install poetry
run: |
pip install --constraint=./dev-constraints.txt poetry
poetry --version
- name: Install Nox
run: |
pip install --constraint=./dev-constraints.txt nox nox-poetry
nox --version
- name: Generate horreum client
# HORREUM_BRANCH must be properly set to the Horreum branch you want to fetch the openapi
run: make generate && poetry build --ansi
run: make generate
- name: Test horreum
run: nox --python=${PY_VERSION} -s tests
- name: Build python library
run: poetry build --ansi
- name: Publish package on PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
Expand Down
6 changes: 5 additions & 1 deletion dev-constraints.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
pip==23.3.1
nox==2024.3.2
nox-poetry==1.0.3
poetry==1.8.2
pytest==8.1.1
pytest-asyncio==0.23.6
pytest-asyncio==0.23.6
virtualenv==20.24.6
21 changes: 21 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import nox
from nox_poetry import Session, session

py_versions = ["3.9", "3.10", "3.11"]

nox.needs_version = ">= 2021.6.6"
nox.options.sessions = (
"tests",
)


@session(python=py_versions)
def tests(s: Session):
s.install(".")
s.install("pytest")
# run tests
s.run(
"pytest",
"test/horreum_client_test.py",
*s.posargs
)
143 changes: 142 additions & 1 deletion poetry.lock

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

2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ microsoft-kiota-serialization-multipart = "^0.1.0"
[tool.poetry.group.dev.dependencies]
pytest = "^8.1.1"
pytest-asyncio = "^0.23.6"
nox = "^2024.3.2"
nox-poetry = "^1.0.3"

[build-system]
requires = ["poetry-core"]
Expand Down

0 comments on commit 97988fa

Please sign in to comment.