Skip to content

Commit cf9cca9

Browse files
committed
ci: add stripe branch to test and propagate workflows
1 parent a9f578d commit cf9cca9

2 files changed

Lines changed: 107 additions & 2 deletions

File tree

.github/workflows/propagate.yml

Lines changed: 99 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
strategy:
1414
fail-fast: false
1515
matrix:
16-
branch: [modal, hetzner]
16+
branch: [modal, hetzner, stripe]
1717
runs-on: ubuntu-latest
1818
steps:
1919
- name: Generate token
@@ -162,6 +162,101 @@ jobs:
162162
git push origin "$BRANCH"
163163
}
164164
165+
conflicts_are_stripe_overlay() {
166+
[ "$BRANCH" = "stripe" ] || return 1
167+
168+
conflicts="$(unresolved_conflicts)"
169+
[ -n "$conflicts" ] || return 1
170+
171+
while IFS= read -r file; do
172+
case "$file" in
173+
pyproject.toml|uv.lock) ;;
174+
*) return 1 ;;
175+
esac
176+
done <<< "$conflicts"
177+
}
178+
179+
add_stripe_dependency() {
180+
python3 <<'PY'
181+
from pathlib import Path
182+
import subprocess
183+
import tomllib
184+
185+
def is_stripe_dependency(dependency: str) -> bool:
186+
return dependency.split(";", 1)[0].strip().lower().startswith("stripe")
187+
188+
189+
def stripe_dependency_from_branch() -> str:
190+
try:
191+
result = subprocess.run(
192+
["git", "show", ":2:pyproject.toml"],
193+
check=True,
194+
capture_output=True,
195+
text=True,
196+
)
197+
except subprocess.CalledProcessError:
198+
return "stripe>=15.3.0"
199+
200+
dependencies = tomllib.loads(result.stdout).get("project", {}).get("dependencies", [])
201+
return next(
202+
(dependency for dependency in dependencies if is_stripe_dependency(dependency)),
203+
"stripe>=15.3.0",
204+
)
205+
206+
207+
path = Path("pyproject.toml")
208+
text = path.read_text()
209+
data = tomllib.loads(text)
210+
211+
dependencies = data.get("project", {}).get("dependencies", [])
212+
if any(is_stripe_dependency(dependency) for dependency in dependencies):
213+
raise SystemExit(0)
214+
215+
lines = text.splitlines()
216+
start = next(
217+
(index for index, line in enumerate(lines) if line.strip() == "dependencies = ["),
218+
None,
219+
)
220+
if start is None:
221+
raise SystemExit("Could not find project dependencies in pyproject.toml")
222+
223+
end = next(
224+
(index for index in range(start + 1, len(lines)) if lines[index].strip() == "]"),
225+
None,
226+
)
227+
if end is None:
228+
raise SystemExit("Could not find end of project dependencies in pyproject.toml")
229+
230+
lines.insert(end, f' "{stripe_dependency_from_branch()}",')
231+
path.write_text("\n".join(lines) + "\n")
232+
PY
233+
}
234+
235+
resolve_stripe_overlay() {
236+
if unresolved_conflicts | grep -qx "pyproject.toml"; then
237+
git checkout --theirs pyproject.toml
238+
fi
239+
240+
add_stripe_dependency
241+
242+
if unresolved_conflicts | grep -qx "uv.lock"; then
243+
git checkout --ours uv.lock
244+
fi
245+
246+
uv lock
247+
git add pyproject.toml uv.lock
248+
249+
remaining_conflicts="$(unresolved_conflicts)"
250+
if [ -n "$remaining_conflicts" ]; then
251+
echo "Conflicts remain after stripe overlay resolution:"
252+
echo "$remaining_conflicts"
253+
return 1
254+
fi
255+
256+
git commit --no-edit
257+
git push origin "$BRANCH"
258+
}
259+
165260
git checkout "$BRANCH"
166261
167262
if git merge origin/main --no-edit; then
@@ -170,6 +265,9 @@ jobs:
170265
elif conflicts_are_modal_overlay; then
171266
echo "Merge conflict only affects the modal dependency overlay; resolving automatically"
172267
resolve_modal_overlay
268+
elif conflicts_are_stripe_overlay; then
269+
echo "Merge conflict only affects the stripe dependency overlay; resolving automatically"
270+
resolve_stripe_overlay
173271
else
174272
echo "Merge conflict detected, opening PR"
175273
git merge --abort

.github/workflows/test.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ name: Test
22

33
on:
44
push:
5+
branches: [main, stripe]
56
pull_request:
6-
branches: [main]
7+
branches: [main, stripe]
78
workflow_dispatch:
89
workflow_call:
910

@@ -62,4 +63,10 @@ jobs:
6263
DB_NAME: db
6364
DB_USER: postgres
6465
DB_PASSWORD: postgres
66+
SECRET_KEY: test-secret-key-that-is-at-least-32-bytes-long
67+
BASE_URL: http://localhost:8000
68+
# Required on the stripe branch (billing always on); harmless on main.
69+
STRIPE_SECRET_KEY: sk_test_dummy
70+
STRIPE_WEBHOOK_SECRET: whsec_test_dummy
71+
STRIPE_PRICE_ID: price_test_dummy
6572
run: uv run pytest tests/

0 commit comments

Comments
 (0)