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): restore python tool cache in ci-backend (#78434)

Raúl Negrón-Oteroaec3dcc84400
diff --git a/.depot/actions/setup-python-cached/action.yml b/.depot/actions/setup-python-cached/action.yml
new file mode 100644
index 000000000000..84f16ad20861
--- /dev/null
+++ b/.depot/actions/setup-python-cached/action.yml
@@ -0,0 +1,65 @@
+# Depot mirror of .github/actions/setup-python-cached (same pattern as .depot/actions/pnpm-install).
+# Kept byte-for-byte equivalent to canonical. actions/cache routes to Depot Cache, so the shared
+# keys do not collide.
+name: Set up Python
+description: |
+ Wraps actions/setup-python with a pre-seeded tool cache
+ (`python-toolcache-<os>-<arch>-<version>`, master-gated save) so a hit turns
+ setup-python into a filesystem lookup: no GitHub API calls, no download.
+ Same pattern as the Node tool cache in pnpm-install.
+
+inputs:
+ python-version:
+ description: 'Python version to install. Only exact x.y.z pins engage the tool cache.'
+ required: true
+ token:
+ description: |
+ GitHub token for setup-python's version-manifest lookup and download on
+ a cache miss. Pass an app token at high-fanout call sites to keep those
+ API calls off the shared per-repo GITHUB_TOKEN core bucket.
+ required: false
+ default: ${{ github.token }}
+
+runs:
+ using: composite
+ steps:
+ - name: Resolve Python version
+ id: python-version
+ shell: bash
+ # An empty version (non-exact pin) skips the tool cache steps, so
+ # setup-python falls back to resolving the version itself. Only exact
+ # x.y.z pins are cacheable: the tool-cache directory is named after
+ # the resolved version, so a range spec would never match it.
+ env:
+ PYTHON_VERSION: ${{ inputs.python-version }}
+ run: |
+ version=$(tr -d 'v[:space:]' <<< "$PYTHON_VERSION")
+ [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || version=""
+ echo "version=$version" >> "$GITHUB_OUTPUT"
+
+ # A tool-cache hit turns setup-python into a filesystem lookup. On a miss
+ # it fetches the version manifest from api.github.com (two rate-limited
+ # API calls per job) and downloads the tarball, on every Python job,
+ # because runner images don't ship the pinned version.
+ - name: Restore Python tool cache
+ id: python-toolcache
+ if: steps.python-version.outputs.version != ''
+ uses: actions/cache/restore@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
+ with:
+ path: ${{ runner.tool_cache }}/Python/${{ steps.python-version.outputs.version }}
+ key: python-toolcache-${{ runner.os }}-${{ runner.arch }}-${{ steps.python-version.outputs.version }}
+
+ - name: Set up Python
+ uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
+ with:
+ python-version: ${{ inputs.python-version }}
+ token: ${{ inputs.token }}
+
+ # Save only on the default branch, for the same reasons as the pnpm
+ # store save in pnpm-install.
+ - name: Save Python tool cache
+ if: github.ref == 'refs/heads/master' && steps.python-version.outputs.version != '' && steps.python-toolcache.outputs.cache-hit != 'true'
+ uses: actions/cache/save@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
+ with:
+ path: ${{ runner.tool_cache }}/Python/${{ steps.python-version.outputs.version }}
+ key: python-toolcache-${{ runner.os }}-${{ runner.arch }}-${{ steps.python-version.outputs.version }}
diff --git a/.depot/workflows/ci-backend.yml b/.depot/workflows/ci-backend.yml
index 882b14cbb13c..e4b292859d74 100644
--- a/.depot/workflows/ci-backend.yml
+++ b/.depot/workflows/ci-backend.yml
@@ -9,8 +9,9 @@
#
# Intentional deltas vs canonical (everything else is kept apples-to-apples):
# - runs-on: depot-* labels instead of ubuntu-latest
-# - action paths: ./.depot/actions/... instead of ./.github/actions/... (pnpm-install
-# and setup-sqlx-cli are byte-equivalent mirrors of the canonical composites)
+# - action paths: ./.depot/actions/... instead of ./.github/actions/... (pnpm-install,
+# setup-sqlx-cli, and setup-python-cached mirror the canonical composites; any
+# deltas are documented in each mirror's header)
# - permissions: pull-requests:read (no comment/auto-commit side effects)
# - Stripped side effects: artifact uploads, CI report section posters (canonical
# additionally skips these on trunk-merge/** branches to save GITHUB_TOKEN budget;
@@ -846,7 +847,7 @@ jobs:
with:
install-command: pnpm install --frozen-lockfile --filter=@posthog/root
- name: Set up Python
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
+ uses: ./.depot/actions/setup-python-cached
with:
python-version: 3.13.13
token: ${{ secrets.POSTHOG_BOT_PAT }}
@@ -961,7 +962,7 @@ jobs:
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Set up Python
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
+ uses: ./.depot/actions/setup-python-cached
with:
python-version: 3.13.13
- name: Install uv
@@ -1023,7 +1024,7 @@ jobs:
owner: ${{ github.repository_owner }}
repositories: ${{ github.event.repository.name }}
- name: Set up Python
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
+ uses: ./.depot/actions/setup-python-cached
with:
python-version: 3.13.13
token: ${{ steps.app-token.outputs.token || github.token }}
@@ -1091,7 +1092,7 @@ jobs:
nohup bin/ci-wait-for-docker launch --background --down \
</dev/null >"${RUNNER_TEMP:-/tmp}/compose-launch.log" 2>&1
- name: Set up Python
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
+ uses: ./.depot/actions/setup-python-cached
with:
python-version: 3.13.13
- name: Install uv
@@ -1643,6 +1644,17 @@ jobs:
- name: Add service hostnames to /etc/hosts
shell: bash
run: echo "127.0.0.1 db redis7 kafka clickhouse clickhouse-coordinator objectstorage seaweedfs temporal" | sudo tee -a /etc/hosts
+ # Tool cache steps inlined rather than the setup-python-cached composite:
+ # this job checks out the PR head ref, which cannot resolve a local
+ # action that only exists on master until the branch rebases. The
+ # restore sits before the parallel block so the tool cache is warm
+ # when setup-python starts.
+ - name: Restore Python tool cache
+ id: python-toolcache
+ uses: actions/cache/restore@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
+ with:
+ path: ${{ runner.tool_cache }}/Python/${{ matrix.python-version }}
+ key: python-toolcache-${{ runner.os }}-${{ runner.arch }}-${{ matrix.python-version }}
- parallel:
- name: Set up Python
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
@@ -1654,6 +1666,12 @@ jobs:
with:
toolchain: 1.91.1
components: cargo
+ - name: Save Python tool cache
+ if: github.ref == 'refs/heads/master' && steps.python-toolcache.outputs.cache-hit != 'true'
+ uses: actions/cache/save@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
+ with:
+ path: ${{ runner.tool_cache }}/Python/${{ matrix.python-version }}
+ key: python-toolcache-${{ runner.os }}-${{ runner.arch }}-${{ matrix.python-version }}
- name: Install uv
id: setup-uv-tests
uses: astral-sh/setup-uv@37802adc94f370d6bfd71619e3f0bf239e1f3b78 # v7.6.0
diff --git a/.github/actions/setup-python-cached/action.yml b/.github/actions/setup-python-cached/action.yml
new file mode 100644
index 000000000000..68852daa27ba
--- /dev/null
+++ b/.github/actions/setup-python-cached/action.yml
@@ -0,0 +1,62 @@
+name: Set up Python
+description: |
+ Wraps actions/setup-python with a pre-seeded tool cache
+ (`python-toolcache-<os>-<arch>-<version>`, master-gated save) so a hit turns
+ setup-python into a filesystem lookup: no GitHub API calls, no download.
+ Same pattern as the Node tool cache in pnpm-install.
+
+inputs:
+ python-version:
+ description: 'Python version to install. Only exact x.y.z pins engage the tool cache.'
+ required: true
+ token:
+ description: |
+ GitHub token for setup-python's version-manifest lookup and download on
+ a cache miss. Pass an app token at high-fanout call sites to keep those
+ API calls off the shared per-repo GITHUB_TOKEN core bucket.
+ required: false
+ default: ${{ github.token }}
+
+runs:
+ using: composite
+ steps:
+ - name: Resolve Python version
+ id: python-version
+ shell: bash
+ # An empty version (non-exact pin) skips the tool cache steps, so
+ # setup-python falls back to resolving the version itself. Only exact
+ # x.y.z pins are cacheable: the tool-cache directory is named after
+ # the resolved version, so a range spec would never match it.
+ env:
+ PYTHON_VERSION: ${{ inputs.python-version }}
+ run: |
+ version=$(tr -d 'v[:space:]' <<< "$PYTHON_VERSION")
+ [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || version=""
+ echo "version=$version" >> "$GITHUB_OUTPUT"
+
+ # A tool-cache hit turns setup-python into a filesystem lookup. On a miss
+ # it fetches the version manifest from api.github.com (two rate-limited
+ # API calls per job) and downloads the tarball, on every Python job,
+ # because runner images don't ship the pinned version.
+ - name: Restore Python tool cache
+ id: python-toolcache
+ if: steps.python-version.outputs.version != ''
+ uses: actions/cache/restore@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
+ with:
+ path: ${{ runner.tool_cache }}/Python/${{ steps.python-version.outputs.version }}
+ key: python-toolcache-${{ runner.os }}-${{ runner.arch }}-${{ steps.python-version.outputs.version }}
+
+ - name: Set up Python
+ uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
+ with:
+ python-version: ${{ inputs.python-version }}
+ token: ${{ inputs.token }}
+
+ # Save only on the default branch, for the same reasons as the pnpm
+ # store save in pnpm-install.
+ - name: Save Python tool cache
+ if: github.ref == 'refs/heads/master' && steps.python-version.outputs.version != '' && steps.python-toolcache.outputs.cache-hit != 'true'
+ uses: actions/cache/save@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
+ with:
+ path: ${{ runner.tool_cache }}/Python/${{ steps.python-version.outputs.version }}
+ key: python-toolcache-${{ runner.os }}-${{ runner.arch }}-${{ steps.python-version.outputs.version }}
diff --git a/.github/workflows/ci-backend.yml b/.github/workflows/ci-backend.yml
index 52a85a62476e..6f5d01ba954e 100644
--- a/.github/workflows/ci-backend.yml
+++ b/.github/workflows/ci-backend.yml
@@ -849,7 +849,7 @@ jobs:
token: ${{ steps.setup-gh-token.outputs.token || github.token }}
- name: Set up Python
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
+ uses: ./.github/actions/setup-python-cached
with:
python-version: 3.13.13
token: ${{ steps.setup-gh-token.outputs.token || github.token }}
@@ -1152,7 +1152,7 @@ jobs:
skip-token-revoke: true
- name: Set up Python
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
+ uses: ./.github/actions/setup-python-cached
with:
python-version: 3.13.13
token: ${{ steps.setup-gh-token.outputs.token || github.token }}
@@ -1284,6 +1284,9 @@ jobs:
owner: ${{ github.repository_owner }}
repositories: ${{ github.event.repository.name }}
+ # Plain setup-python: this PR-only job runs on ubuntu-latest, whose cache
+ # store no master job ever saves the python tool cache to, so the
+ # setup-python-cached restore would miss on every run.
- name: Set up Python
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
@@ -1383,7 +1386,7 @@ jobs:
skip-token-revoke: true
- name: Set up Python
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
+ uses: ./.github/actions/setup-python-cached
with:
python-version: 3.13.13
token: ${{ steps.setup-gh-token.outputs.token || github.token }}
@@ -2026,12 +2029,29 @@ jobs:
private-key: ${{ secrets.GH_APP_POSTHOG_DEVEX_GENERAL_PRIVATE_KEY }}
skip-token-revoke: true
+ # Tool cache steps inlined rather than the setup-python-cached composite:
+ # this job checks out the PR head ref, which cannot resolve a local
+ # action that only exists on master until the branch rebases.
+ - name: Restore Python tool cache
+ id: python-toolcache
+ uses: actions/cache/restore@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
+ with:
+ path: ${{ runner.tool_cache }}/Python/3.13.13
+ key: python-toolcache-${{ runner.os }}-${{ runner.arch }}-3.13.13
+
- name: Set up Python
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version: 3.13.13
token: ${{ steps.setup-gh-token.outputs.token || github.token }}
+ - name: Save Python tool cache
+ if: github.ref == 'refs/heads/master' && steps.python-toolcache.outputs.cache-hit != 'true'
+ uses: actions/cache/save@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
+ with:
+ path: ${{ runner.tool_cache }}/Python/3.13.13
+ key: python-toolcache-${{ runner.os }}-${{ runner.arch }}-3.13.13
+
- name: Install uv
id: setup-uv
uses: astral-sh/setup-uv@37802adc94f370d6bfd71619e3f0bf239e1f3b78 # v7.6.0
@@ -2588,6 +2608,18 @@ jobs:
private-key: ${{ secrets.GH_APP_POSTHOG_DEVEX_GENERAL_PRIVATE_KEY }}
skip-token-revoke: true
+ # Tool cache steps inlined rather than the setup-python-cached composite:
+ # this job checks out the PR head ref, which cannot resolve a local
+ # action that only exists on master until the branch rebases. The
+ # restore sits before the parallel block so the tool cache is warm
+ # when setup-python starts.
+ - name: Restore Python tool cache
+ id: python-toolcache
+ uses: actions/cache/restore@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
+ with:
+ path: ${{ runner.tool_cache }}/Python/${{ matrix.python-version }}
+ key: python-toolcache-${{ runner.os }}-${{ runner.arch }}-${{ matrix.python-version }}
+
- parallel:
- name: Set up Python
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
@@ -2602,6 +2634,13 @@ jobs:
toolchain: 1.91.1
components: cargo
+ - name: Save Python tool cache
+ if: github.ref == 'refs/heads/master' && steps.python-toolcache.outputs.cache-hit != 'true'
+ uses: actions/cache/save@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
+ with:
+ path: ${{ runner.tool_cache }}/Python/${{ matrix.python-version }}
+ key: python-toolcache-${{ runner.os }}-${{ runner.arch }}-${{ matrix.python-version }}
+
- name: Install uv
id: setup-uv-tests
uses: astral-sh/setup-uv@37802adc94f370d6bfd71619e3f0bf239e1f3b78 # v7.6.0