diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0127982ef..85ee5ccbd 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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 @@ -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' diff --git a/pelican/tests/build_test/conftest.py b/pelican/tests/build_test/conftest.py index 548f79704..b1d1a54b9 100644 --- a/pelican/tests/build_test/conftest.py +++ b/pelican/tests/build_test/conftest.py @@ -1,6 +1,6 @@ def pytest_addoption(parser): parser.addoption( - "--check-wheel", + "--check-build", action="store", default=False, help="Check wheel contents.", diff --git a/pelican/tests/build_test/test_build_files.py b/pelican/tests/build_test/test_build_files.py new file mode 100644 index 000000000..2b51d3624 --- /dev/null +++ b/pelican/tests/build_test/test_build_files.py @@ -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 diff --git a/pelican/tests/build_test/test_wheel.py b/pelican/tests/build_test/test_wheel.py deleted file mode 100644 index 8e643981f..000000000 --- a/pelican/tests/build_test/test_wheel.py +++ /dev/null @@ -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