Skip to content

Tests: support multi test envs #83

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

Merged
merged 5 commits into from
Jan 9, 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
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"features": {
"ghcr.io/devcontainers-contrib/features/poetry:2": {}
},
"postCreateCommand": "poetry config virtualenvs.in-project true && poetry install -E all && poetry run pre-commit install",
"postCreateCommand": "./scripts/setup-envs.sh",
"customizations": {
"vscode": {
"settings": {
Expand Down
9 changes: 9 additions & 0 deletions .github/actions/setup-poetry/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: Setup Poetry
description: Setup Poetry

runs:
using: "composite"
steps:
- name: Install poetry
run: pipx install poetry
shell: bash
21 changes: 18 additions & 3 deletions .github/actions/setup-python/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,34 @@ inputs:
description: Python version
required: false
default: "3.10"
env-dir:
description: Environment directory
required: true
no-root:
description: Do not install package in the environment
required: false
default: "false"

runs:
using: "composite"
steps:
- name: Install poetry
run: pipx install poetry
shell: bash
uses: ./.github/actions/setup-poetry

- uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python-version }}
architecture: "x64"
cache: "poetry"
cache-dependency-path: |
./poetry.lock
${{ inputs.env-dir }}/poetry.lock

- run: poetry install --all-extras
- run: |
cd ${{ inputs.env-dir }}
if [ "${{ inputs.no-root }}" = "true" ]; then
poetry install --all-extras --no-root
else
poetry install --all-extras
fi
shell: bash
12 changes: 10 additions & 2 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ on:
- master
pull_request:
paths:
- "envs/**"
- "githubkit/**"
- "tests/**"
- ".github/actions/setup-poetry/**"
- ".github/actions/setup-python/**"
- ".github/workflows/codecov.yml"
- "pyproject.toml"
Expand All @@ -24,10 +26,12 @@ jobs:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
os: [ubuntu-latest, windows-latest, macos-latest]
env: [pydantic-v2]
fail-fast: false
env:
OS: ${{ matrix.os }}
PYTHON_VERSION: ${{ matrix.python-version }}
PYDANTIC_VERSION: ${{ matrix.env }}

steps:
- uses: actions/checkout@v4
Expand All @@ -36,15 +40,19 @@ jobs:
uses: ./.github/actions/setup-python
with:
python-version: ${{ matrix.python-version }}
env-dir: ./envs/${{ matrix.env }}
no-root: true

- name: Run Pytest
run: poetry run pytest -n auto --cov-report xml
run: |
cd ./envs/${{ matrix.env }}
poetry run bash "../../scripts/run-tests.sh"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Upload coverage report
uses: codecov/codecov-action@v3
with:
env_vars: OS,PYTHON_VERSION
env_vars: OS,PYTHON_VERSION,PYDANTIC_VERSION
files: ./coverage.xml
flags: unittests
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Setup Python environment
uses: ./.github/actions/setup-python
- name: Setup Poetry
uses: ./.github/actions/setup-poetry

- name: Get Version
id: version
Expand Down
749 changes: 749 additions & 0 deletions envs/pydantic-v2/poetry.lock

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions envs/pydantic-v2/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[tool.poetry]
name = "githubkit-pydantic-v2"
version = "0.1.0"
description = "Private pydantic v2 test env for githubkit"
authors = ["yanyongyu <yyy@yyydl.top>"]
license = "MIT"

[tool.poetry.dependencies]
python = "^3.8"

[tool.poetry.group.dev.dependencies]
pydantic = "^2.0.0"
githubkit-test = { path = "../test/", develop = false }
githubkit = { path = "../../", extras = ["all"], develop = true }

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
1 change: 1 addition & 0 deletions envs/test/githubkit-test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# fake file to make project installable
325 changes: 325 additions & 0 deletions envs/test/poetry.lock

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions envs/test/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[tool.poetry]
name = "githubkit-test"
version = "0.1.0"
description = "Private test env for githubkit"
authors = ["yanyongyu <yyy@yyydl.top>"]
license = "MIT"
packages = [{ include = "githubkit-test.py" }]

[tool.poetry.dependencies]
python = "^3.8"
anyio = "*"
pytest = "^7.4.3"
pytest-cov = "^4.1.0"
pytest-xdist = "^3.5.0"
coverage-conditional-plugin = "^0.9.0"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
22 changes: 21 additions & 1 deletion poetry.lock

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

6 changes: 1 addition & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,7 @@ openapi-pydantic = "^0.4.0"
tomli = { version = "^2.0.1", python = "<3.11" }

[tool.poetry.group.test.dependencies]
anyio = "*"
pytest = "^7.4.3"
pytest-cov = "^4.1.0"
pytest-xdist = "^3.5.0"
coverage-conditional-plugin = "^0.9.0"
githubkit-test = { path = "./envs/test", develop = false }

[tool.poetry.extras]
jwt = ["PyJWT"]
Expand Down
7 changes: 7 additions & 0 deletions scripts/run-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#! /usr/bin/env bash

# cd to the root of the project
cd "$(dirname "$0")/.."

# Run the tests
pytest -n auto --cov-report xml tests
10 changes: 10 additions & 0 deletions scripts/setup-envs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#! /usr/bin/env bash

# config poetry to install env in project
poetry config virtualenvs.in-project true

# setup dev environment
poetry install --all-extras && poetry run pre-commit install

# setup pydantic v2 test environment
(cd envs/pydantic-v2 && poetry install --no-root)