forked from github/pelican
Enable tests to validate dist build contents (#3229)
This commit is contained in:
parent
6f467fefdc
commit
4e438ffe60
4 changed files with 85 additions and 30 deletions
19
.github/workflows/main.yml
vendored
19
.github/workflows/main.yml
vendored
|
|
@ -64,6 +64,23 @@ jobs:
|
||||||
- name: Run linters
|
- name: Run linters
|
||||||
run: pdm lint --diff
|
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:
|
docs:
|
||||||
name: Build docs
|
name: Build docs
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
@ -84,7 +101,7 @@ jobs:
|
||||||
deploy:
|
deploy:
|
||||||
name: Deploy
|
name: Deploy
|
||||||
environment: Deployment
|
environment: Deployment
|
||||||
needs: [test, lint, docs]
|
needs: [test, lint, docs, build]
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
if: github.ref=='refs/heads/master' && github.event_name!='pull_request' && github.repository == 'getpelican/pelican'
|
if: github.ref=='refs/heads/master' && github.event_name!='pull_request' && github.repository == 'getpelican/pelican'
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
def pytest_addoption(parser):
|
def pytest_addoption(parser):
|
||||||
parser.addoption(
|
parser.addoption(
|
||||||
"--check-wheel",
|
"--check-build",
|
||||||
action="store",
|
action="store",
|
||||||
default=False,
|
default=False,
|
||||||
help="Check wheel contents.",
|
help="Check wheel contents.",
|
||||||
|
|
|
||||||
66
pelican/tests/build_test/test_build_files.py
Normal file
66
pelican/tests/build_test/test_build_files.py
Normal file
|
|
@ -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
|
||||||
|
|
@ -1,28 +0,0 @@
|
||||||
from pathlib import Path
|
|
||||||
import pytest
|
|
||||||
from zipfile import ZipFile
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skipif(
|
|
||||||
"not config.getoption('--check-wheel')",
|
|
||||||
reason="Only run when --check-wheel 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
|
|
||||||
"""
|
|
||||||
wheel_file = pytestconfig.getoption("--check-wheel")
|
|
||||||
assert wheel_file.endswith(".whl")
|
|
||||||
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
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue