Skip to content

Commit 40bc0d6

Browse files
authored
fix: dependency cache bugs for fork PR CI (#1394)
## Summary Fixes issues preventing the dependency cache (#1386) from working on fork PRs: - **uv cache path**: `setup-uv` overrode the cache dir to a temp path. Use `cache-local-path` to pin it. - **uv offline lookups**: cache is scoped by index URL hash. Set `UV_INDEX_URL` to match the warmer's JFrog URL. - **Pre-commit broken symlinks**: warmer's Python path differed from consumer's. Use `setup-python` in warmer. - **pip offline**: `PIP_NO_INDEX` blocks all index access. Create a pip wheelhouse and use `PIP_FIND_LINKS`. - **Version-specific wheels**: create test envs for all matrix versions in the warmer. - Misc: removed no-op `strategy.fail-fast`, added missing `id: coverage_comment`. ## Test plan - [x] `warm-cache` job succeeds on this PR - [x] All `main.yml` jobs pass offline
1 parent 5194f6c commit 40bc0d6

3 files changed

Lines changed: 32 additions & 21 deletions

File tree

.github/actions/setup-python-deps/action.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ runs:
1818
path: |
1919
~/.cache/uv
2020
~/.cache/pip
21+
~/.cache/pip-wheelhouse
2122
key: python-deps-${{ hashFiles('uv.lock', 'pyproject.toml') }}-latest
2223
restore-keys: python-deps-${{ hashFiles('uv.lock', 'pyproject.toml') }}-
2324

@@ -33,6 +34,6 @@ runs:
3334
shell: bash
3435
run: |
3536
echo "UV_OFFLINE=true" >> "$GITHUB_ENV"
37+
echo "UV_INDEX_URL=https://databricks.jfrog.io/artifactory/api/pypi/db-pypi/simple" >> "$GITHUB_ENV"
3638
echo "PIP_NO_INDEX=1" >> "$GITHUB_ENV"
37-
mkdir -p ~/.config/pip
38-
printf '[global]\nno-index = true\n' > ~/.config/pip/pip.conf
39+
echo "PIP_FIND_LINKS=$HOME/.cache/pip-wheelhouse" >> "$GITHUB_ENV"

.github/workflows/main.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ jobs:
5252

5353
env:
5454
UV_FROZEN: "1"
55-
UV_CACHE_DIR: /home/runner/.cache/uv
5655

5756
steps:
5857
- name: Check out the repository
@@ -73,6 +72,8 @@ jobs:
7372

7473
- name: Install uv
7574
uses: astral-sh/setup-uv@38f3f104447c67c051c4a08e39b64a148898af3a # v4
75+
with:
76+
cache-local-path: ~/.cache/uv
7677

7778
- name: Install Hatch
7879
uses: pypa/hatch@257e27e51a6a5616ed08a39a408a21c35c9931bc # install
@@ -100,7 +101,6 @@ jobs:
100101

101102
env:
102103
UV_FROZEN: "1"
103-
UV_CACHE_DIR: /home/runner/.cache/uv
104104

105105
strategy:
106106
fail-fast: false
@@ -126,6 +126,8 @@ jobs:
126126

127127
- name: Install uv
128128
uses: astral-sh/setup-uv@38f3f104447c67c051c4a08e39b64a148898af3a # v4
129+
with:
130+
cache-local-path: ~/.cache/uv
129131

130132
- name: Install Hatch
131133
uses: pypa/hatch@257e27e51a6a5616ed08a39a408a21c35c9931bc # install
@@ -156,7 +158,6 @@ jobs:
156158

157159
env:
158160
UV_FROZEN: "1"
159-
UV_CACHE_DIR: /home/runner/.cache/uv
160161

161162
steps:
162163
- name: Check out the repository
@@ -177,6 +178,8 @@ jobs:
177178

178179
- name: Install uv
179180
uses: astral-sh/setup-uv@38f3f104447c67c051c4a08e39b64a148898af3a # v4
181+
with:
182+
cache-local-path: ~/.cache/uv
180183

181184
- name: Install Hatch
182185
uses: pypa/hatch@257e27e51a6a5616ed08a39a408a21c35c9931bc # install

.github/workflows/warmDepsCache.yml

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ on:
1818
- "uv.lock"
1919
- "pyproject.toml"
2020
- ".pre-commit-config.yaml"
21-
pull_request: # TEMPORARY: remove after testing
2221
schedule:
2322
- cron: "0 6 * * *" # Daily at 06:00 UTC
2423
workflow_dispatch:
@@ -41,9 +40,6 @@ jobs:
4140

4241
env:
4342
UV_FROZEN: "1"
44-
# Pin cache dir so setup-uv doesn't override it to a temp path.
45-
# Must match the path in setup-python-deps/action.yml cache restore.
46-
UV_CACHE_DIR: /home/runner/.cache/uv
4743

4844
steps:
4945
- name: Checkout main branch
@@ -65,8 +61,6 @@ jobs:
6561
6662
echo "Warming cache for PR #${{ inputs.pr_number }} from ${FORK_REPO}@${FORK_REF}"
6763
68-
# Fetch only lockfiles from the fork — .github/actions/ always
69-
# comes from main to prevent code injection from forks.
7064
git remote add fork "https://github.com/${FORK_REPO}.git"
7165
git fetch --depth=1 fork "${FORK_REF}"
7266
git checkout FETCH_HEAD -- uv.lock pyproject.toml .pre-commit-config.yaml
@@ -81,14 +75,16 @@ jobs:
8175

8276
- name: Install uv
8377
uses: astral-sh/setup-uv@38f3f104447c67c051c4a08e39b64a148898af3a # v4
78+
with:
79+
cache-local-path: ~/.cache/uv
8480

8581
- name: Install Hatch
8682
uses: pypa/hatch@257e27e51a6a5616ed08a39a408a21c35c9931bc # install
8783

8884
- name: Install Python versions for test matrix
89-
run: uv python install 3.10 3.11 3.12 3.13
85+
run: uv python install 3.11 3.12 3.13
9086

91-
- name: Create all hatch environments (populates uv cache)
87+
- name: Create hatch environments (populates uv cache)
9288
run: |
9389
set -euo pipefail
9490
hatch env create default
@@ -101,21 +97,31 @@ jobs:
10197
- name: Warm pre-commit cache
10298
run: hatch run pre-commit install-hooks
10399

104-
- name: Build and warm pip cache for verify environment
100+
- name: Create pip wheelhouse
105101
run: |
106102
set -euo pipefail
107-
hatch -v build
108-
# Run verify to populate ~/.cache/pip/ with runtime transitive deps.
109-
# Allow failure — we only care about populating the cache.
110-
hatch run verify:check-all || true
103+
mkdir -p ~/.cache/pip-wheelhouse
104+
hatch run python -c "
105+
try:
106+
import tomllib
107+
except ImportError:
108+
import tomli as tomllib
109+
with open('pyproject.toml', 'rb') as f:
110+
data = tomllib.load(f)
111+
for dep in data['project']['dependencies']:
112+
print(dep)
113+
" > /tmp/runtime-deps.txt
114+
hatch run pip download --dest ~/.cache/pip-wheelhouse \
115+
setuptools wheel twine check-wheel-contents \
116+
-r /tmp/runtime-deps.txt
117+
118+
- name: Build package
119+
run: hatch -v build
111120

112121
- name: Generate cache key
113122
id: cache-key
114123
shell: bash
115124
run: |
116-
# Hash first so consumers can prefix-match on the hash alone.
117-
# Timestamp suffix ensures each run creates a new immutable entry;
118-
# consumers pick the latest timestamp for a given hash.
119125
TIMESTAMP=$(date -u +%Y%m%d%H%M%S)
120126
LOCK_HASH="${{ hashFiles('uv.lock', 'pyproject.toml') }}"
121127
echo "python-deps-key=python-deps-${LOCK_HASH}-${TIMESTAMP}" >> "$GITHUB_OUTPUT"
@@ -129,6 +135,7 @@ jobs:
129135
path: |
130136
~/.cache/uv
131137
~/.cache/pip
138+
~/.cache/pip-wheelhouse
132139
key: ${{ steps.cache-key.outputs.python-deps-key }}
133140

134141
- name: Save pre-commit cache

0 commit comments

Comments
 (0)