Skip to content

Commit

Permalink
Enable tests to validate dist build contents (getpelican#3229)
Browse files Browse the repository at this point in the history
  • Loading branch information
lioman authored Oct 30, 2023
1 parent 6f467fe commit 4e438ff
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 30 deletions.
19 changes: 18 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,23 @@ jobs:
- name: Run linters
run: pdm lint --diff

build:
name: Test build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: pdm-project/setup-pdm@v3
with:
python-version: 3.9
cache: true
cache-dependency-path: ./pyproject.toml
- name: Install dependencies
run: pdm install --dev
- name: Build package
run: pdm build
- name: Test build
run: pdm run pytest --check-build=dist pelican/tests/build_test

docs:
name: Build docs
runs-on: ubuntu-latest
Expand All @@ -84,7 +101,7 @@ jobs:
deploy:
name: Deploy
environment: Deployment
needs: [test, lint, docs]
needs: [test, lint, docs, build]
runs-on: ubuntu-latest
if: github.ref=='refs/heads/master' && github.event_name!='pull_request' && github.repository == 'getpelican/pelican'

Expand Down
2 changes: 1 addition & 1 deletion pelican/tests/build_test/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
def pytest_addoption(parser):
parser.addoption(
"--check-wheel",
"--check-build",
action="store",
default=False,
help="Check wheel contents.",
Expand Down
66 changes: 66 additions & 0 deletions pelican/tests/build_test/test_build_files.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
from re import match
import tarfile
from pathlib import Path
from zipfile import ZipFile

import pytest


@pytest.mark.skipif(
"not config.getoption('--check-build')",
reason="Only run when --check-build is given",
)
def test_wheel_contents(pytestconfig):
"""
This test should test the contents of the wheel to make sure
that everything that is needed is included in the final build
"""
dist_folder = pytestconfig.getoption("--check-build")
wheels = Path(dist_folder).rglob("*.whl")
for wheel_file in wheels:
files_list = ZipFile(wheel_file).namelist()
# Check if theme files are copied to wheel
simple_theme = Path("./pelican/themes/simple/templates")
for x in simple_theme.iterdir():
assert str(x) in files_list

# Check if tool templates are copied to wheel
tools = Path("./pelican/tools/templates")
for x in tools.iterdir():
assert str(x) in files_list

assert "pelican/tools/templates/tasks.py.jinja2" in files_list


@pytest.mark.skipif(
"not config.getoption('--check-build')",
reason="Only run when --check-build is given",
)
@pytest.mark.parametrize(
"expected_file",
[
("THANKS"),
("README.rst"),
("CONTRIBUTING.rst"),
("docs/changelog.rst"),
("samples/"),
],
)
def test_sdist_contents(pytestconfig, expected_file):
"""
This test should test the contents of the source distribution to make sure
that everything that is needed is included in the final build.
"""
dist_folder = pytestconfig.getoption("--check-build")
sdist_files = Path(dist_folder).rglob("*.tar.gz")
for dist in sdist_files:
files_list = tarfile.open(dist, "r:gz").getnames()
dir_matcher = ""
if expected_file.endswith("/"):
dir_matcher = ".*"
filtered_values = [
path
for path in files_list
if match(f"^pelican-\d\.\d\.\d/{expected_file}{dir_matcher}$", path)
]
assert len(filtered_values) > 0
28 changes: 0 additions & 28 deletions pelican/tests/build_test/test_wheel.py

This file was deleted.

0 comments on commit 4e438ff

Please sign in to comment.