Skip to content

Commit

Permalink
Fix release.py test-release smoke test for new release style (Cherr…
Browse files Browse the repository at this point in the history
…y-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 <huon@exoflare.io>
  • Loading branch information
WorkerPants and huonw authored Oct 23, 2023
1 parent bb35a46 commit a4a3a3e
Showing 1 changed file with 64 additions and 9 deletions.
73 changes: 64 additions & 9 deletions src/python/pants_release/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}")


# -----------------------------------------------------------------------------------------------
Expand Down

0 comments on commit a4a3a3e

Please sign in to comment.