diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 71219aab13..960722bdae 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -49,28 +49,23 @@ jobs: steps: - uses: actions/checkout@v4 + - run: pipx install poetry + - run: pipx install nox + - run: pipx inject nox nox-poetry - uses: actions/setup-python@v5 with: + check-latest: true python-version: | 3.8 3.9 3.10 3.11 3.12 + cache: "poetry" + cache-dependency-path: | + poetry.lock + noxfile.py - - name: Pip and nox cache - id: cache - uses: actions/cache@v4 - with: - path: | - ~/.cache - ~/.nox - .nox - key: - ${{ runner.os }}-nox-${{ matrix.session.session }}-${{ - hashFiles('**/poetry.lock') }}-${{ hashFiles('**/noxfile.py') }}-4 - - - run: pip install poetry nox nox-poetry - run: nox -r -t tests -s "${{ matrix.session.session }}" - uses: actions/upload-artifact@v4 if: ${{ always() }} @@ -103,13 +98,14 @@ jobs: - uses: actions/setup-python@v5 id: setup-python with: + check-latest: true python-version: "3.12" architecture: x64 cache: "poetry" + cache-dependency-path: | + poetry.lock - - run: poetry env use 3.12 - run: poetry install - if: steps.setup-python.outputs.cache-hit != 'true' - name: Run benchmarks uses: CodSpeedHQ/action@v2 @@ -125,6 +121,9 @@ jobs: steps: - uses: actions/checkout@v4 + - run: pipx install poetry + - run: pipx install nox + - run: pipx inject nox nox-poetry - uses: actions/setup-python@v5 with: python-version: | @@ -133,24 +132,11 @@ jobs: 3.10 3.11 3.12 + cache: "poetry" + cache-dependency-path: | + poetry.lock + noxfile.py - - name: Pip and nox cache - id: cache - uses: actions/cache@v4 - with: - path: | - ~/.cache - ~/.nox - .nox - key: - ${{ runner.os }}-nox-lint-${{ matrix.session.session }}-${{ - hashFiles('**/poetry.lock') }}-${{ hashFiles('**/noxfile.py') }} - restore-keys: | - ${{ runner.os }}-lint-nox-${{ matrix.session.session }}- - ${{ runner.os }}-lint-nox- - - - run: pip install poetry - - run: pip install nox nox-poetry - run: nox -r -t lint unit-tests-on-windows: @@ -166,9 +152,10 @@ jobs: with: python-version: "3.11" cache: "poetry" + cache-dependency-path: | + poetry.lock - run: poetry install --with integrations - if: steps.setup-python.outputs.cache-hit != 'true' # Since we are running all the integrations at once, we can't use # pydantic v2. It is not compatible with starlette yet - run: poetry run pip install pydantic==1.10 diff --git a/noxfile.py b/noxfile.py index 406ad3c6b9..27a4fdddd0 100644 --- a/noxfile.py +++ b/noxfile.py @@ -1,4 +1,5 @@ import itertools +from pathlib import Path from typing import Any, Callable, List import nox @@ -66,10 +67,23 @@ def with_gql_core_parametrize(name: str, params: List[str]) -> Callable[[Any], A return lambda fn: nox.parametrize(arg_names, combinations, ids=ids)(fn) +def install(session: Session, *, with_integrations: bool = False) -> None: + session._session.install("poetry") # type: ignore + session.run_always( + "poetry", + "env", + "use", + str(Path(session.virtualenv.bin) / "python"), + ) + extra_args = ["--with", "integrations"] if with_integrations else [] + session.run_always("poetry", "install", *extra_args) + + @session(python=PYTHON_VERSIONS, name="Tests", tags=["tests"]) @gql_core_parametrize def tests(session: Session, gql_core: str) -> None: - session.run_always("poetry", "install", external=True) + install(session) + _install_gql_core(session, gql_core) markers = ( ["-m", f"not {integration}", f"--ignore=tests/{integration}"] @@ -87,7 +101,8 @@ def tests(session: Session, gql_core: str) -> None: @session(python=["3.11", "3.12"], name="Django tests", tags=["tests"]) @with_gql_core_parametrize("django", ["4.2.0", "4.1.0", "4.0.0", "3.2.0"]) def tests_django(session: Session, django: str, gql_core: str) -> None: - session.run_always("poetry", "install", external=True) + install(session) + _install_gql_core(session, gql_core) session._session.install(f"django~={django}") # type: ignore session._session.install("pytest-django") # type: ignore @@ -98,7 +113,7 @@ def tests_django(session: Session, django: str, gql_core: str) -> None: @session(python=["3.11"], name="Starlette tests", tags=["tests"]) @with_gql_core_parametrize("starlette", ["0.28.0", "0.27.0", "0.26.1"]) def tests_starlette(session: Session, starlette: str, gql_core: str) -> None: - session.run_always("poetry", "install", external=True) + install(session) session._session.install(f"starlette=={starlette}") # type: ignore _install_gql_core(session, gql_core) @@ -121,7 +136,7 @@ def tests_starlette(session: Session, starlette: str, gql_core: str) -> None: ], ) def tests_integrations(session: Session, integration: str, gql_core: str) -> None: - session.run_always("poetry", "install", external=True) + install(session) session._session.install(integration) # type: ignore _install_gql_core(session, gql_core) @@ -139,7 +154,7 @@ def tests_integrations(session: Session, integration: str, gql_core: str) -> Non @session(python=PYTHON_VERSIONS, name="Pydantic tests", tags=["tests", "pydantic"]) @with_gql_core_parametrize("pydantic", ["1.10", "2.7.0", "2.8.0"]) def test_pydantic(session: Session, pydantic: str, gql_core: str) -> None: - session.run_always("poetry", "install", external=True) + install(session) session._session.install(f"pydantic~={pydantic}") # type: ignore _install_gql_core(session, gql_core) @@ -156,7 +171,7 @@ def test_pydantic(session: Session, pydantic: str, gql_core: str) -> None: @session(python=PYTHON_VERSIONS, name="Type checkers tests", tags=["tests"]) def tests_typecheckers(session: Session) -> None: - session.run_always("poetry", "install", external=True) + install(session) session.install("pyright") session.install("pydantic") @@ -174,7 +189,7 @@ def tests_typecheckers(session: Session) -> None: @session(python=PYTHON_VERSIONS, name="CLI tests", tags=["tests"]) def tests_cli(session: Session) -> None: - session.run_always("poetry", "install", external=True) + install(session) session._session.install("uvicorn") # type: ignore session._session.install("starlette") # type: ignore @@ -191,7 +206,7 @@ def tests_cli(session: Session) -> None: @session(name="Mypy", tags=["lint"]) def mypy(session: Session) -> None: - session.run_always("poetry", "install", "--with", "integrations", external=True) + install(session, with_integrations=True) session.install("mypy") session.run("mypy", "--config-file", "mypy.ini")