From a4a3a3e3d411d0458c1009b544327a2e5e2ae90a Mon Sep 17 00:00:00 2001 From: "Worker Pants (Pantsbuild GitHub Automation Bot)" <133242086+WorkerPants@users.noreply.github.com> Date: Mon, 23 Oct 2023 17:35:16 -0500 Subject: [PATCH] Fix `release.py test-release` smoke test for new release style (Cherry-pick of #20002) (#20073) This adjusts the `test-release` subcommand of the `release.py` script to do a smoke test that works with the new release style. This is step 4 of the release procedure, and is, in my mind, designed to catch major infra failures. For instance, if things haven't been published at all. Co-authored-by: Huon Wilson --- src/python/pants_release/release.py | 73 +++++++++++++++++++++++++---- 1 file changed, 64 insertions(+), 9 deletions(-) diff --git a/src/python/pants_release/release.py b/src/python/pants_release/release.py index c6422abc116..a34daa91227 100644 --- a/src/python/pants_release/release.py +++ b/src/python/pants_release/release.py @@ -487,6 +487,15 @@ def build_all_wheels() -> None: ) +def install_and_test_packages(version: str, *, extra_pip_args: list[str] | None = None) -> None: + with create_tmp_venv() as bin_dir: + for pkg in PACKAGES: + pip_req = f"{pkg.name}=={version}" + banner(f"Installing and testing {pip_req}") + pkg.validate(version, bin_dir, extra_pip_args or []) + green(f"Tests succeeded for {pip_req}") + + def build_pants_wheels() -> None: banner(f"Building Pants wheels with Python {CONSTANTS.python_version}") version = CONSTANTS.pants_stable_version @@ -809,17 +818,63 @@ def prompt_to_generate_docs() -> None: def test_release() -> None: banner("Installing and testing the latest released packages") - install_and_test_packages(CONSTANTS.pants_stable_version) - banner("Successfully installed and tested the latest released packages") + smoke_test_install_and_version(CONSTANTS.pants_stable_version) + banner("Successfully ran a smoke test of the released packages") + + +def smoke_test_install_and_version(version: str) -> None: + """Do two tests to confirm that both sets of artifacts (PEXes for running normally, and wheels + for plugins) have ended up somewhere plausible, to catch major infra failures.""" + with temporary_dir() as dir_: + dir = Path(dir_) + (dir / "pants.toml").write_text( + f""" + [GLOBAL] + pants_version = "{version}" + + backend_packages = [ + "pants.backend.python", + "pants.backend.plugin_development", + ] + [python] + interpreter_constraints = ["==3.9.*"] + enable_resolves = true + """ + ) -def install_and_test_packages(version: str, *, extra_pip_args: list[str] | None = None) -> None: - with create_tmp_venv() as bin_dir: - for pkg in PACKAGES: - pip_req = f"{pkg.name}=={version}" - banner(f"Installing and testing {pip_req}") - pkg.validate(version, bin_dir, extra_pip_args or []) - green(f"Tests succeeded for {pip_req}") + # First: test that running pants normally reports the expected version: + result = subprocess.run( + ["pants", "version"], + cwd=dir, + check=True, + stdout=subprocess.PIPE, + ) + printed_version = result.stdout.decode().strip() + if printed_version != version: + die(f"Failed to confirm pants version, expected {version!r}, got {printed_version!r}") + + # Second: test that the wheels can be installed/imported (for plugins): + (dir / "BUILD").write_text("python_sources(name='py'); pants_requirements(name='pants')") + # We confirm the version from the main wheel, but only check that the testutil code can + # be imported at all. + (dir / "example.py").write_text( + "from pants import version, testutil; print(version.VERSION)" + ) + result = subprocess.run( + ["pants", "generate-lockfiles"], + cwd=dir, + check=True, + ) + result = subprocess.run( + ["pants", "run", "example.py"], + cwd=dir, + check=True, + stdout=subprocess.PIPE, + ) + wheel_version = result.stdout.decode().strip() + if printed_version != version: + die(f"Failed to confirm wheel version, expected {version!r}, got {wheel_version!r}") # -----------------------------------------------------------------------------------------------