Skip to content

Commit

Permalink
Test wheels in CI (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
hynek committed Jan 2, 2024
1 parent 31a152d commit 5112695
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 61 deletions.
93 changes: 43 additions & 50 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ env:
PIP_NO_PYTHON_VERSION_WARNING: "1"
SETUPTOOLS_SCM_PRETEND_VERSION: "1.0" # avoid warnings about shallow checkout

# For re-actors/checkout-python-sdist
sdist-artifact: python-package-distributions
sdist-name: environ_config-1.0.tar.gz

permissions: {}

jobs:
Expand All @@ -32,38 +28,26 @@ jobs:

- run: python -Im pip install --upgrade wheel nox

- run: python -Im nox -e cog -- --check
- run: python -Im nox --session cog -- --check

build-sdist:
name: 📦 Build the source distribution
build-package:
name: Build & verify package
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version-file: .python-version-default
cache: pip
- run: python -Im pip install build

- run: python -Im build --sdist
fetch-depth: 0

- uses: actions/upload-artifact@v4
with:
name: ${{ env.sdist-artifact }}
# NOTE: Exact expected file names are specified here
# NOTE: as a safety measure — if anything weird ends
# NOTE: up being in this dir or not all dists will be
# NOTE: produced, this will fail the workflow.
path: dist/${{ env.sdist-name }}
retention-days: 15
- uses: hynek/build-and-inspect-python-package@v2

tests:
name: Tests on ${{ matrix.python-version }}
needs: [build-sdist]
needs: build-package
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
python-version:
# [[[cog
Expand All @@ -79,11 +63,12 @@ jobs:
# [[[end]]]

steps:
- name: Get source code from pre-built sdist
uses: re-actors/checkout-python-sdist@release/v1
- name: Download pre-built packages
uses: actions/download-artifact@v4
with:
source-tarball-name: ${{ env.sdist-name }}
workflow-artifact-name: ${{ env.sdist-artifact }}
name: Packages
path: dist
- run: tar xf dist/*.tar.gz --strip-components=1
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
Expand All @@ -92,7 +77,13 @@ jobs:

- run: python -Im pip install --upgrade wheel nox

- run: python -Im nox --python ${{ matrix.python-version }} --tags tests
- name: Run tests
run: |
python -Im nox \
--python ${{ matrix.python-version }} \
--tags tests \
-- \
--installpkg dist/*.whl
- name: Upload coverage data
uses: actions/upload-artifact@v4
Expand All @@ -105,19 +96,14 @@ jobs:
name: Combine & check coverage
runs-on: ubuntu-latest
needs: tests
if: always()

steps:
- name: Get source code from pre-built sdist
uses: re-actors/checkout-python-sdist@release/v1
with:
source-tarball-name: ${{ env.sdist-name }}
workflow-artifact-name: ${{ env.sdist-artifact }}
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version-file: .python-version-default
cache: pip

- run: python -Im pip install --upgrade coverage[toml]
python-version-file: .python-version-default

- uses: actions/download-artifact@v4
with:
Expand All @@ -126,6 +112,8 @@ jobs:

- name: Combine coverage & fail if it's <100%.
run: |
python -Im pip install --upgrade coverage[toml]
python -Im coverage combine
python -Im coverage html --skip-covered --skip-empty
Expand All @@ -144,7 +132,7 @@ jobs:

mypy:
name: Mypy on ${{ matrix.python-version }}
needs: [build-sdist]
needs: build-package
runs-on: ubuntu-latest
strategy:
fail-fast: false
Expand All @@ -163,11 +151,13 @@ jobs:
# [[[end]]]

steps:
- name: Get source code from pre-built sdist
uses: re-actors/checkout-python-sdist@release/v1
- name: Download pre-built packages
uses: actions/download-artifact@v4
with:
source-tarball-name: ${{ env.sdist-name }}
workflow-artifact-name: ${{ env.sdist-artifact }}
name: Packages
path: dist
- run: tar xf dist/*.tar.gz --strip-components=1

- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
Expand All @@ -176,18 +166,21 @@ jobs:

- run: python -Im pip install --upgrade wheel nox

- run: python -Im nox -e mypy
- run: python -Im nox --session mypy

docs:
name: Build docs & run doctests
needs: [build-sdist]
needs: build-package
runs-on: ubuntu-latest

steps:
- name: Get source code from pre-built sdist
uses: re-actors/checkout-python-sdist@release/v1
- name: Download pre-built packages
uses: actions/download-artifact@v4
with:
source-tarball-name: ${{ env.sdist-name }}
workflow-artifact-name: ${{ env.sdist-artifact }}
name: Packages
path: dist
- run: tar xf dist/*.tar.gz --strip-components=1

- uses: actions/setup-python@v5
with:
cache: pip
Expand All @@ -201,7 +194,7 @@ jobs:
# [[[end]]]
- run: python -Im pip install --upgrade wheel nox

- run: python -Im nox -e docs
- run: python -Im nox --session docs

install-dev:
name: Verify dev env on ${{ matrix.os }}
Expand All @@ -222,16 +215,16 @@ jobs:

# Ensure everything required is passing for branch protection.
required-checks-pass:
name: Ensure everything required is passing for branch protection
if: always()
runs-on: ubuntu-latest

needs:
- coverage
- docs
- install-dev
- mypy

runs-on: ubuntu-latest

steps:
- name: Decide whether the needed jobs succeeded or failed
uses: re-actors/alls-green@release/v1
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/pypi-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ on:
branches: [main]
tags: ["*"]
pull_request:
branches: [main]
release:
types:
- published
Expand Down
37 changes: 28 additions & 9 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
nox.options.error_on_external_run = True


RUN_UNDER_COVERAGE = ["3.7", "3.11"]
RUN_UNDER_COVERAGE = ["3.8", "3.11"]
ALL_SUPPORTED = [
# [[[cog
# for line in open("pyproject.toml"):
Expand Down Expand Up @@ -64,32 +64,51 @@ def pre_commit(session: nox.Session) -> None:
session.run("pre-commit", "run", "--all-files")


def _cov(session: nox.Session) -> None:
session.run("coverage", "run", "-m", "pytest", *session.posargs)
def _get_pkg(posargs: list[str]) -> tuple[str, list[str]]:
"""
Allow `--installpkg path/to/wheel.whl` to be passed.
"""
posargs = list(posargs)

try:
i = posargs.index("--installpkg")
pkg = posargs[i + 1]
del posargs[i : i + 2]
except ValueError:
pkg = "."

return f"{pkg}[tests]", posargs


def _cov(session: nox.Session, posargs: list[str]) -> None:
session.run("coverage", "run", "-m", "pytest", *posargs)

if os.environ.get("CI") != "true":
session.notify("coverage_report")


@nox.session(python=RUN_UNDER_COVERAGE, tags=["tests"])
def tests_cov(session: nox.Session) -> None:
session.install(".[tests]")
pkg, posargs = _get_pkg(session.posargs)
session.install(pkg, "coverage[toml]")

_cov(session)
_cov(session, posargs)


@nox.session(python=NOT_COVERAGE, tags=["tests"])
def tests(session: nox.Session) -> None:
session.install(".[tests]")
pkg, posargs = _get_pkg(session.posargs)
session.install(pkg, "coverage[toml]")

session.run("pytest", *session.posargs)
session.run("pytest", *posargs)


@nox.session(python=OLDEST_PYTHON, tags=["tests"])
def tests_oldest_attrs(session: nox.Session) -> None:
session.install(".[tests]", f"attrs=={OLDEST_ATTRS}")
pkg, posargs = _get_pkg(session.posargs)
session.install(pkg, "coverage[toml]", f"attrs=={OLDEST_ATTRS}")

_cov(session)
_cov(session, posargs)


@nox.session
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ classifiers = [
dependencies = ["attrs>=17.4.0", "importlib_metadata; python_version<'3.8'"]

[project.optional-dependencies]
tests = ["pytest", "coverage[toml]", "moto<4.2.1"]
tests = ["pytest", "moto<4.2.1"]
aws = ["boto3"]
docs = [
"environ-config[aws]",
Expand Down

0 comments on commit 5112695

Please sign in to comment.