Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

chore(ci): add shared uv setup action (#96867)

Raúl Negrón-Oterofa14c5e39f6d
diff --git a/.depot/actions/setup-uv/action.yml b/.depot/actions/setup-uv/action.yml
new file mode 100644
index 000000000000..30501f76b9e1
--- /dev/null
+++ b/.depot/actions/setup-uv/action.yml
@@ -0,0 +1,42 @@
+name: Set up uv
+description: |
+ Installs CI's exact uv version and optionally restores its cache.
+
+ The exact pin makes installs reproducible. setup-uv v7.6.0 resolves
+ downloads through Astral's static manifest, not the GitHub releases API.
+ Jobs that check out an older revision must install uv directly: this
+ action does not exist in those trees.
+
+ Defaults suit the root Python project: cache against uv.lock and save
+ only on master. Tool-only jobs should disable dependency caching.
+
+inputs:
+ enable-cache:
+ description: Whether to use the uv cache
+ required: false
+ default: 'true'
+ cache-dependency-glob:
+ description: Files used to calculate the uv cache key
+ required: false
+ default: uv.lock
+ save-cache:
+ description: Whether to save the uv cache after the job
+ required: false
+ default: ${{ github.ref == 'refs/heads/master' }}
+
+outputs:
+ cache-hit:
+ description: Whether a matching cache entry was restored
+ value: ${{ steps.setup-uv.outputs.cache-hit }}
+
+runs:
+ using: composite
+ steps:
+ - name: Install uv
+ id: setup-uv
+ uses: astral-sh/setup-uv@37802adc94f370d6bfd71619e3f0bf239e1f3b78 # v7.6.0
+ with:
+ version: '0.11.28'
+ enable-cache: ${{ inputs.enable-cache }}
+ cache-dependency-glob: ${{ inputs.cache-dependency-glob }}
+ save-cache: ${{ inputs.save-cache }}
diff --git a/.github/actions/setup-uv/action.yml b/.github/actions/setup-uv/action.yml
new file mode 100644
index 000000000000..30501f76b9e1
--- /dev/null
+++ b/.github/actions/setup-uv/action.yml
@@ -0,0 +1,42 @@
+name: Set up uv
+description: |
+ Installs CI's exact uv version and optionally restores its cache.
+
+ The exact pin makes installs reproducible. setup-uv v7.6.0 resolves
+ downloads through Astral's static manifest, not the GitHub releases API.
+ Jobs that check out an older revision must install uv directly: this
+ action does not exist in those trees.
+
+ Defaults suit the root Python project: cache against uv.lock and save
+ only on master. Tool-only jobs should disable dependency caching.
+
+inputs:
+ enable-cache:
+ description: Whether to use the uv cache
+ required: false
+ default: 'true'
+ cache-dependency-glob:
+ description: Files used to calculate the uv cache key
+ required: false
+ default: uv.lock
+ save-cache:
+ description: Whether to save the uv cache after the job
+ required: false
+ default: ${{ github.ref == 'refs/heads/master' }}
+
+outputs:
+ cache-hit:
+ description: Whether a matching cache entry was restored
+ value: ${{ steps.setup-uv.outputs.cache-hit }}
+
+runs:
+ using: composite
+ steps:
+ - name: Install uv
+ id: setup-uv
+ uses: astral-sh/setup-uv@37802adc94f370d6bfd71619e3f0bf239e1f3b78 # v7.6.0
+ with:
+ version: '0.11.28'
+ enable-cache: ${{ inputs.enable-cache }}
+ cache-dependency-glob: ${{ inputs.cache-dependency-glob }}
+ save-cache: ${{ inputs.save-cache }}
diff --git a/.github/workflows/ci-python.yml b/.github/workflows/ci-python.yml
index cfa314c5bb84..65a8e5310435 100644
--- a/.github/workflows/ci-python.yml
+++ b/.github/workflows/ci-python.yml
@@ -92,7 +92,11 @@ jobs:
- .github/workflows/ci-python.yml
- .github/workflows/ci-dagster.yml
- .github/workflows/ci-backend.yml
+ - .github/actions/setup-uv/**
+ - .depot/actions/setup-uv/**
+ - '.depot/workflows/*.yml'
- .flox/env/manifest.toml
+ - .flox/env/manifest.lock
# Schema changes need to trigger Python CI to validate schema.py is regenerated
- 'frontend/src/queries/schema.json'
# Products changes need to trigger Python CI to validate the json usage is still valid
@@ -194,12 +198,7 @@ jobs:
- name: Install uv
id: setup-uv
- uses: astral-sh/setup-uv@37802adc94f370d6bfd71619e3f0bf239e1f3b78 # v7.6.0
- with:
- version: '0.11.28' # pinned: unpinned setup-uv calls GH API on every job, exhausts rate limit
- enable-cache: true
- cache-dependency-glob: uv.lock
- save-cache: ${{ github.ref == 'refs/heads/master' }}
+ uses: ./.github/actions/setup-uv
- name: Check uv and Python version compatibility
shell: bash
diff --git a/bin/check_uv_python_compatibility.py b/bin/check_uv_python_compatibility.py
index e7200e4706db..a25048877424 100755
--- a/bin/check_uv_python_compatibility.py
+++ b/bin/check_uv_python_compatibility.py
@@ -11,20 +11,19 @@ The shape we enforce:
breaking the moment master ships a new pin. Raise the floor only when the
code on master genuinely requires a newer uv feature.
-- .github/workflows/*.yml use setup-uv with an explicit exact version literal
- (e.g. `version: '0.11.14'`). Every workflow pins the SAME exact version so
- CI is deterministic across jobs. The pin must satisfy the pyproject floor.
- An exact literal also avoids the historical GH API rate-limit issue caused
- by range resolution (astral-sh/setup-uv#325).
+- .github/actions/setup-uv/action.yml holds CI's exact uv version. The Depot
+ mirror and jobs that check out older revisions keep matching exact pins.
+ Exact pins prevent CI from floating to a new release. setup-uv v7.6.0 uses
+ a static manifest rather than the rate-limited releases API used by v7.3.0.
- .flox/env/manifest.toml mirrors the CI pin for parity between local dev and
CI. Comparison is on major.minor to allow patch drift.
Performs four checks:
-1. Workflow pins are present, exact literals, and identical across all files.
-2. Workflow pin satisfies pyproject's required-version floor.
-3. Workflow pin can download the required Python version.
-4. Flox manifest uv version matches the workflow pin on major.minor.
+1. CI pins are present, exact literals, and identical across all files.
+2. The pin satisfies pyproject's required-version floor.
+3. The pin can download the required Python version.
+4. Flox manifest uv version matches the CI pin on major.minor.
Run in CI via .github/workflows/ci-python.yml to catch issues early.
@@ -107,31 +106,41 @@ def get_uv_version_from_flox() -> str | None:
return match.group(1) if match else None
-def get_uv_versions_from_workflows() -> dict[str, list[str | None]]:
- """Find all setup-uv usages in CI workflows and their version pins.
+def get_uv_pins_from_ci_files() -> dict[str, list[str | None]]:
+ """Find direct setup-uv usages in CI configuration and their version pins.
- Returns a dict mapping workflow filename to list of version strings (or None
- if a usage has no pin). Every usage must be pinned with an exact literal —
- unpinned setup-uv would resolve via GitHub API on every job and hit rate
- limits under concurrent load (see astral-sh/setup-uv#325).
+ Returns a dict mapping each repo-relative file to its direct setup-uv
+ versions. Composite actions are globbed rather than named, so a second
+ wrapper — a .depot mirror, or a future per-tool action — cannot carry an
+ unpinned setup-uv past this check.
"""
- workflows_dir = Path(__file__).parent.parent / ".github" / "workflows"
+ repo_root = Path(__file__).parent.parent
+ ci_files = [
+ *sorted(repo_root.glob(".github/actions/*/action.y*ml")),
+ *sorted(repo_root.glob(".depot/actions/*/action.y*ml")),
+ *sorted((repo_root / ".github" / "workflows").glob("*.y*ml")),
+ *sorted((repo_root / ".depot" / "workflows").glob("*.y*ml")),
+ ]
uv_usages: dict[str, list[str | None]] = {}
- for workflow_file in sorted(workflows_dir.glob("*.yml")):
- lines = workflow_file.read_text().splitlines()
+ for ci_file in ci_files:
+ lines = ci_file.read_text().splitlines()
for i, line in enumerate(lines):
if "setup-uv@" not in line:
continue
version: str | None = None
- for lookahead in lines[i + 1 : i + 6]:
- if re.match(r"^\s+-\s+name:", lookahead):
+ step_indent = len(line) - len(line.lstrip()) - (0 if line.lstrip().startswith("- ") else 2)
+ for lookahead in lines[i + 1 :]:
+ if not lookahead.strip() or lookahead.lstrip().startswith("#"):
+ continue
+ if len(lookahead) - len(lookahead.lstrip()) <= step_indent:
break
- m = re.match(r"^\s+version:\s*['\"]?([0-9.]+)['\"]?", lookahead)
+ m = re.fullmatch(r"\s+version:\s*(['\"]?)(\d+\.\d+\.\d+)\1\s*(?:#.*)?", lookahead)
if m:
- version = m.group(1)
+ version = m.group(2)
break
- uv_usages.setdefault(workflow_file.name, []).append(version)
+ path = str(ci_file.relative_to(repo_root))
+ uv_usages.setdefault(path, []).append(version)
return uv_usages
@@ -177,10 +186,10 @@ def _divider() -> None:
def label_workflow_pins(workflow_usages: dict[str, list[str | None]]) -> tuple[list[str], dict[str, list[str]]]:
- """Split workflow usages into missing pins and pins grouped by version.
+ """Split usages into missing pins and pins grouped by version.
Returns (missing_pins, pin_locations). Each usage is labelled with its
- workflow name, plus a `(usage N)` suffix when a workflow has several.
+ repo-relative path, plus a `(usage N)` suffix when a file has several.
"""
missing_pins: list[str] = []
pin_locations: dict[str, list[str]] = {}
@@ -197,14 +206,14 @@ def label_workflow_pins(workflow_usages: dict[str, list[str | None]]) -> tuple[l
def check_workflow_pins() -> tuple[bool, str | None]:
- """Check 1: pins present, exact literals, and identical across workflows.
+ """Check 1: pins present, exact literals, and identical across CI files.
Returns (ok, workflow_pin). The pin is the single agreed version, or None
when it is missing or ambiguous.
"""
_section("Check 1: CI workflow uv version pins")
- workflow_usages = get_uv_versions_from_workflows()
+ workflow_usages = get_uv_pins_from_ci_files()
missing_pins, pin_locations = label_workflow_pins(workflow_usages)
distinct_pins = set(pin_locations)
@@ -214,8 +223,7 @@ def check_workflow_pins() -> tuple[bool, str | None]:
for name in missing_pins:
print(f" - {name}")
print()
- print(" Without an exact pin, setup-uv may resolve via GitHub API and")
- print(" hit rate limits under concurrent load (astral-sh/setup-uv#325).")
+ print(" Use the shared setup-uv action, or an exact pin for an older-revision job.")
ok = False
workflow_pin: str | None = None
diff --git a/bin/test/test_check_uv_python_compatibility.py b/bin/test/test_check_uv_python_compatibility.py
index f03e3f00a349..45a888c493e1 100644
--- a/bin/test/test_check_uv_python_compatibility.py
+++ b/bin/test/test_check_uv_python_compatibility.py
@@ -1,13 +1,17 @@
#!/usr/bin/env python3
+import io
import subprocess
+from contextlib import redirect_stdout
+from pathlib import Path
+from tempfile import TemporaryDirectory
import unittest
from unittest.mock import patch
from parameterized import parameterized
-from bin.check_uv_python_compatibility import check_uv_python_compatibility, label_workflow_pins
+from bin.check_uv_python_compatibility import check_uv_python_compatibility, check_workflow_pins, label_workflow_pins
class TestCheckUvPythonCompatibility(unittest.TestCase):
@@ -38,6 +42,53 @@ class TestCheckUvPythonCompatibility(unittest.TestCase):
class TestLabelWorkflowPins(unittest.TestCase):
+ @parameterized.expand(
+ [
+ (".github/actions/setup-uv/action.yml", "'0.11.28' # exact", True),
+ (".depot/actions/setup-uv/action.yaml", '"0.11.28"', True),
+ (".github/workflows/ci.yml", "0.11.28", True),
+ (".depot/workflows/ci.yaml", "'0.11.28'", True),
+ (".depot/actions/setup-uv/action.yml", "'0.11.28.*'", False),
+ (".github/actions/setup-uv/action.yml", "'>=0.11.28'", False),
+ (".github/actions/setup-uv/action.yml", "'latest'", False),
+ (".github/actions/setup-uv/action.yml", "'0.11.28, <0.12'", False),
+ ]
+ )
+ def test_ci_pin_discovery(self, filename: str, version: str, expected_ok: bool) -> None:
+ with TemporaryDirectory() as directory:
+ root = Path(directory)
+ ci_file = root / filename
+ ci_file.parent.mkdir(parents=True)
+ ci_file.write_text(
+ f"steps:\n - name: Install uv\n uses: astral-sh/setup-uv@abc\n with:\n version: {version}\n"
+ )
+ with (
+ patch("bin.check_uv_python_compatibility.__file__", str(root / "bin/check.py")),
+ redirect_stdout(io.StringIO()),
+ ):
+ ok, pin = check_workflow_pins()
+ self.assertEqual((ok, pin), (expected_ok, "0.11.28" if expected_ok else None))
+
+ def test_missing_pin_does_not_read_next_step(self) -> None:
+ with TemporaryDirectory() as directory:
+ root = Path(directory)
+ workflow = root / ".github/workflows/ci.yml"
+ workflow.parent.mkdir(parents=True)
+ workflow.write_text(
+ "steps:\n"
+ " - uses: astral-sh/setup-uv@abc\n"
+ " - uses: another/setup@abc\n"
+ " with:\n"
+ " version: '0.11.28'\n"
+ )
+ with (
+ patch("bin.check_uv_python_compatibility.__file__", str(root / "bin/check.py")),
+ redirect_stdout(io.StringIO()),
+ ):
+ ok, pin = check_workflow_pins()
+ self.assertFalse(ok)
+ self.assertIsNone(pin)
+
def test_single_usage_uses_bare_name(self):
missing, locations = label_workflow_pins({"ci-a.yml": ["0.11.28"]})
self.assertEqual(missing, [])