Skip to content

Commit b2ca444

Browse files
authored
Merge branch 'main' into sd-db/triage/dbt-empty-inline-ref-alias
2 parents 0a01c13 + ea6a384 commit b2ca444

File tree

4 files changed

+217
-16
lines changed

4 files changed

+217
-16
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: "Setup Python Dependencies"
2+
description: |
3+
Restores pre-cached Python dependencies and enables offline mode.
4+
Outputs cache-hit so callers can fall back to setup-jfrog-pypi on miss.
5+
6+
outputs:
7+
cache-hit:
8+
description: "Whether the dependency cache was restored and offline mode enabled"
9+
value: ${{ steps.uv-cache.outputs.cache-matched-key != '' }}
10+
11+
runs:
12+
using: "composite"
13+
steps:
14+
- name: Restore uv and pip cache
15+
id: uv-cache
16+
uses: actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830 # v4
17+
with:
18+
path: |
19+
~/.cache/uv
20+
~/.cache/pip
21+
~/.cache/pip-wheelhouse
22+
key: python-deps-${{ hashFiles('uv.lock', 'pyproject.toml') }}-latest
23+
restore-keys: python-deps-${{ hashFiles('uv.lock', 'pyproject.toml') }}-
24+
25+
- name: Restore pre-commit cache
26+
uses: actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830 # v4
27+
with:
28+
path: ~/.cache/pre-commit
29+
key: pre-commit-deps-${{ hashFiles('.pre-commit-config.yaml') }}-latest
30+
restore-keys: pre-commit-deps-${{ hashFiles('.pre-commit-config.yaml') }}-
31+
32+
- name: Enable offline mode
33+
if: steps.uv-cache.outputs.cache-matched-key != ''
34+
shell: bash
35+
run: |
36+
echo "UV_OFFLINE=true" >> "$GITHUB_ENV"
37+
echo "UV_INDEX_URL=https://databricks.jfrog.io/artifactory/api/pypi/db-pypi/simple" >> "$GITHUB_ENV"
38+
echo "PIP_NO_INDEX=1" >> "$GITHUB_ENV"
39+
echo "PIP_FIND_LINKS=$HOME/.cache/pip-wheelhouse" >> "$GITHUB_ENV"

.github/dependabot.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
version: 2
22
updates:
3-
# Python dependencies
3+
# Python dependencies — security updates only
44
- package-ecosystem: "pip"
55
directory: "/"
66
schedule:
7-
interval: "daily"
7+
interval: "weekly"
8+
open-pull-requests-limit: 0
89
rebase-strategy: "disabled"
910

10-
# GitHub Actions — auto-update SHA pins
11+
# GitHub Actions — security updates only
1112
- package-ecosystem: "github-actions"
1213
directory: "/"
1314
schedule:
1415
interval: "weekly"
16+
open-pull-requests-limit: 0
1517
rebase-strategy: "disabled"

.github/workflows/main.yml

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
# **what?**
22
# Runs code quality checks, unit tests, and verifies python build on
3-
# all code commited to the repository. This workflow should not
4-
# require any secrets since it runs for PRs from forked repos.
5-
# By default, secrets are not passed to workflows running from
6-
# a forked repo.
3+
# all code commited to the repository. Dependencies are served from a
4+
# pre-populated cache (see warmDepsCache.yml) when available, with a
5+
# JFrog OIDC fallback when the cache is cold.
76

87
# **why?**
98
# Ensure code for dbt meets a certain quality standard.
@@ -54,16 +53,17 @@ jobs:
5453
env:
5554
UV_FROZEN: "1"
5655

57-
strategy:
58-
fail-fast: false
59-
6056
steps:
6157
- name: Check out the repository
6258
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
6359

64-
- name: Setup JFrog PyPI Proxy
65-
uses: ./.github/actions/setup-jfrog-pypi
60+
- name: Setup Python Dependencies
61+
id: deps
62+
uses: ./.github/actions/setup-python-deps
6663

64+
- name: Setup JFrog PyPI Proxy (fallback)
65+
if: steps.deps.outputs.cache-hit != 'true'
66+
uses: ./.github/actions/setup-jfrog-pypi
6767

6868
- name: Set up Python
6969
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5
@@ -72,6 +72,8 @@ jobs:
7272

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

7678
- name: Install Hatch
7779
uses: pypa/hatch@257e27e51a6a5616ed08a39a408a21c35c9931bc # install
@@ -109,9 +111,13 @@ jobs:
109111
- name: Check out the repository
110112
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
111113

112-
- name: Setup JFrog PyPI Proxy
113-
uses: ./.github/actions/setup-jfrog-pypi
114+
- name: Setup Python Dependencies
115+
id: deps
116+
uses: ./.github/actions/setup-python-deps
114117

118+
- name: Setup JFrog PyPI Proxy (fallback)
119+
if: steps.deps.outputs.cache-hit != 'true'
120+
uses: ./.github/actions/setup-jfrog-pypi
115121

116122
- name: Set up Python ${{ matrix.python-version }}
117123
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5
@@ -120,6 +126,8 @@ jobs:
120126

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

124132
- name: Install Hatch
125133
uses: pypa/hatch@257e27e51a6a5616ed08a39a408a21c35c9931bc # install
@@ -129,6 +137,7 @@ jobs:
129137

130138
# Only run coverage comment once (not for all python versions)
131139
- name: Coverage Comment
140+
id: coverage_comment
132141
if: matrix.python-version == '3.12' && github.event_name == 'pull_request'
133142
uses: py-cov-action/python-coverage-comment-action@7188638f871f721a365d644f505d1ff3df20d683 # v3
134143
with:
@@ -154,9 +163,13 @@ jobs:
154163
- name: Check out the repository
155164
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
156165

157-
- name: Setup JFrog PyPI Proxy
158-
uses: ./.github/actions/setup-jfrog-pypi
166+
- name: Setup Python Dependencies
167+
id: deps
168+
uses: ./.github/actions/setup-python-deps
159169

170+
- name: Setup JFrog PyPI Proxy (fallback)
171+
if: steps.deps.outputs.cache-hit != 'true'
172+
uses: ./.github/actions/setup-jfrog-pypi
160173

161174
- name: Set up Python
162175
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5
@@ -165,6 +178,8 @@ jobs:
165178

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

169184
- name: Install Hatch
170185
uses: pypa/hatch@257e27e51a6a5616ed08a39a408a21c35c9931bc # install
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
# Warm Python Dependency Cache
2+
#
3+
# Pre-downloads all Python dependencies via JFrog Artifactory and saves them
4+
# to the GitHub Actions cache. PR workflows (including fork PRs, which cannot
5+
# authenticate to JFrog) restore this cache and build fully offline.
6+
#
7+
# Triggers:
8+
# - push to main when dependency files change (keeps cache fresh)
9+
# - daily schedule (prevents 7-day GitHub Actions cache eviction)
10+
# - manual dispatch (with optional PR number to warm cache for a fork's deps)
11+
12+
name: Warm Python Dependency Cache
13+
14+
on:
15+
push:
16+
branches: [main]
17+
paths:
18+
- "uv.lock"
19+
- "pyproject.toml"
20+
- ".pre-commit-config.yaml"
21+
schedule:
22+
- cron: "0 6 * * *" # Daily at 06:00 UTC
23+
workflow_dispatch:
24+
inputs:
25+
pr_number:
26+
description: "PR number to warm cache for (reads lockfiles from the PR branch). Leave empty to warm from main."
27+
required: false
28+
type: string
29+
30+
permissions:
31+
id-token: write
32+
contents: read
33+
pull-requests: read
34+
35+
jobs:
36+
warm-cache:
37+
runs-on:
38+
group: databricks-protected-runner-group
39+
labels: linux-ubuntu-latest
40+
41+
env:
42+
UV_FROZEN: "1"
43+
44+
steps:
45+
- name: Checkout main branch
46+
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
47+
48+
- name: Overlay PR dependency files
49+
if: inputs.pr_number != ''
50+
shell: bash
51+
run: |
52+
set -euo pipefail
53+
54+
PR_DATA=$(curl -sLS \
55+
-H "Accept: application/vnd.github+json" \
56+
-H "Authorization: Bearer ${{ github.token }}" \
57+
"https://api.github.com/repos/${{ github.repository }}/pulls/${{ inputs.pr_number }}")
58+
59+
FORK_REPO=$(echo "$PR_DATA" | jq -r '.head.repo.full_name')
60+
FORK_REF=$(echo "$PR_DATA" | jq -r '.head.ref')
61+
62+
echo "Warming cache for PR #${{ inputs.pr_number }} from ${FORK_REPO}@${FORK_REF}"
63+
64+
git remote add fork "https://github.com/${FORK_REPO}.git"
65+
git fetch --depth=1 fork "${FORK_REF}"
66+
git checkout FETCH_HEAD -- uv.lock pyproject.toml .pre-commit-config.yaml
67+
68+
- name: Setup JFrog PyPI Proxy
69+
uses: ./.github/actions/setup-jfrog-pypi
70+
71+
- name: Set up Python
72+
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5
73+
with:
74+
python-version: "3.10"
75+
76+
- name: Install uv
77+
uses: astral-sh/setup-uv@38f3f104447c67c051c4a08e39b64a148898af3a # v4
78+
with:
79+
cache-local-path: ~/.cache/uv
80+
81+
- name: Install Hatch
82+
uses: pypa/hatch@257e27e51a6a5616ed08a39a408a21c35c9931bc # install
83+
84+
- name: Install Python versions for test matrix
85+
run: uv python install 3.11 3.12 3.13
86+
87+
- name: Create hatch environments (populates uv cache)
88+
run: |
89+
set -euo pipefail
90+
hatch env create default
91+
hatch env create test.py3.10
92+
hatch env create test.py3.11
93+
hatch env create test.py3.12
94+
hatch env create test.py3.13
95+
hatch env create verify
96+
97+
- name: Warm pre-commit cache
98+
run: hatch run pre-commit install-hooks
99+
100+
- name: Create pip wheelhouse
101+
run: |
102+
set -euo pipefail
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
120+
121+
- name: Generate cache key
122+
id: cache-key
123+
shell: bash
124+
run: |
125+
TIMESTAMP=$(date -u +%Y%m%d%H%M%S)
126+
LOCK_HASH="${{ hashFiles('uv.lock', 'pyproject.toml') }}"
127+
echo "python-deps-key=python-deps-${LOCK_HASH}-${TIMESTAMP}" >> "$GITHUB_OUTPUT"
128+
129+
PRECOMMIT_HASH="${{ hashFiles('.pre-commit-config.yaml') }}"
130+
echo "pre-commit-key=pre-commit-deps-${PRECOMMIT_HASH}-${TIMESTAMP}" >> "$GITHUB_OUTPUT"
131+
132+
- name: Save uv and pip cache
133+
uses: actions/cache/save@0057852bfaa89a56745cba8c7296529d2fc39830 # v4
134+
with:
135+
path: |
136+
~/.cache/uv
137+
~/.cache/pip
138+
~/.cache/pip-wheelhouse
139+
key: ${{ steps.cache-key.outputs.python-deps-key }}
140+
141+
- name: Save pre-commit cache
142+
uses: actions/cache/save@0057852bfaa89a56745cba8c7296529d2fc39830 # v4
143+
with:
144+
path: ~/.cache/pre-commit
145+
key: ${{ steps.cache-key.outputs.pre-commit-key }}

0 commit comments

Comments
 (0)