Skip to content

Commit

Permalink
Pin publish test to 3.12 (astral-sh#8951)
Browse files Browse the repository at this point in the history
The bump to 3.13 broke the test
  • Loading branch information
konstin authored Nov 10, 2024
1 parent 249089c commit 874aa29
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,7 @@ jobs:
env:
# No dbus in GitHub Actions
PYTHON_KEYRING_BACKEND: keyrings.alt.file.PlaintextKeyring
PYTHON_VERSION: 3.12
permissions:
# For trusted publishing
id-token: write
Expand All @@ -1149,7 +1150,7 @@ jobs:

- uses: actions/setup-python@v5
with:
python-version: "3.12"
python-version: "${{ env.PYTHON_VERSION }}"

- name: "Download binary"
uses: actions/download-artifact@v4
Expand All @@ -1169,14 +1170,15 @@ jobs:

- name: "Publish test packages"
# `-p 3.12` prefers the python we just installed over the one locked in `.python_version`.
run: ./uv run -p 3.12 scripts/publish/test_publish.py --uv ./uv all
run: ./uv run -p ${{ env.PYTHON_VERSION }} scripts/publish/test_publish.py --uv ./uv all
env:
RUST_LOG: uv=debug,uv_publish=trace
UV_TEST_PUBLISH_TOKEN: ${{ secrets.UV_TEST_PUBLISH_TOKEN }}
UV_TEST_PUBLISH_PASSWORD: ${{ secrets.UV_TEST_PUBLISH_PASSWORD }}
UV_TEST_PUBLISH_GITLAB_PAT: ${{ secrets.UV_TEST_PUBLISH_GITLAB_PAT }}
UV_TEST_PUBLISH_CODEBERG_TOKEN: ${{ secrets.UV_TEST_PUBLISH_CODEBERG_TOKEN }}
UV_TEST_PUBLISH_CLOUDSMITH_TOKEN: ${{ secrets.UV_TEST_PUBLISH_CLOUDSMITH_TOKEN }}
UV_TEST_PUBLISH_PYTHON_VERSION: ${{ env.PYTHON_VERSION }}

cache-test-ubuntu:
timeout-minutes: 10
Expand Down
32 changes: 23 additions & 9 deletions scripts/publish/test_publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
from packaging.version import Version

TEST_PYPI_PUBLISH_URL = "https://test.pypi.org/legacy/"
PYTHON_VERSION = os.environ.get("UV_TEST_PUBLISH_PYTHON_VERSION", "3.12")

cwd = Path(__file__).parent

Expand Down Expand Up @@ -124,8 +125,8 @@ class TargetConfiguration:
}


def get_new_version(project_name: str, client: httpx.Client) -> Version:
"""Return the next free patch version on all indexes of the package."""
def get_latest_version(project_name: str, client: httpx.Client) -> Version:
"""Return the latest version on all indexes of the package."""
# To keep the number of packages small we reuse them across targets, so we have to
# pick a version that doesn't exist on any target yet
versions = set()
Expand All @@ -151,10 +152,12 @@ def get_new_version(project_name: str, client: httpx.Client) -> Version:
time.sleep(1)
else:
raise RuntimeError(f"Failed to fetch {url}") from error
max_version = max(versions)
return max(versions)

# Bump the path version to obtain an empty version
release = list(max_version.release)

def get_new_version(latest_version: Version) -> Version:
"""Bump the path version to obtain an empty version."""
release = list(latest_version.release)
release[-1] += 1
return Version(".".join(str(i) for i in release))

Expand Down Expand Up @@ -193,7 +196,10 @@ def build_project_at_version(

if project_root.exists():
rmtree(project_root)
check_call([uv, "init", "--lib", "--name", project_name, dir_name], cwd=cwd)
check_call(
[uv, "init", "-p", PYTHON_VERSION, "--lib", "--name", project_name, dir_name],
cwd=cwd,
)
pyproject_toml = project_root.joinpath("pyproject.toml")

# Set to an unclaimed version
Expand All @@ -217,7 +223,12 @@ def build_project_at_version(
return project_root


def wait_for_index(index_url: str, project_name: str, version: Version, uv: Path):
def wait_for_index(
index_url: str,
project_name: str,
version: Version,
uv: Path,
):
"""Check that the index URL was updated, wait up to 100s if necessary.
Often enough the index takes a few seconds until the index is updated after an
Expand All @@ -231,6 +242,8 @@ def wait_for_index(index_url: str, project_name: str, version: Version, uv: Path
uv,
"pip",
"compile",
"-p",
PYTHON_VERSION,
"--index",
index_url,
"--quiet",
Expand All @@ -241,7 +254,7 @@ def wait_for_index(index_url: str, project_name: str, version: Version, uv: Path
"-",
],
text=True,
input=project_name,
input=f"{project_name}",
)
if f"{project_name}=={version}" in output and output.count("--hash") == 2:
break
Expand All @@ -265,7 +278,8 @@ def publish_project(target: str, uv: Path, client: httpx.Client):
print(f"\nPublish {project_name} for {target}")

# The distributions are build to the dist directory of the project.
version = get_new_version(project_name, client)
previous_version = get_latest_version(project_name, client)
version = get_new_version(previous_version)
project_dir = build_project_at_version(project_name, version, uv)

# Upload configuration
Expand Down

0 comments on commit 874aa29

Please sign in to comment.