aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralex <alex@pdp7.net>2026-01-24 21:54:41 +0100
committeralexpdp7 <alex@corcoles.net>2026-01-24 20:55:19 +0000
commit3c9b2277f5723c5300bb672bcbb298b0790a7cc1 (patch)
tree57a1d481bae4b1e3d94f73a288373ddcab6c1578
parentb30ff21fcff123c01d71f5f4d4fee1f7295c8dc9 (diff)
Draft hook
-rwxr-xr-xblog_v2/post-receive38
1 files changed, 38 insertions, 0 deletions
diff --git a/blog_v2/post-receive b/blog_v2/post-receive
new file mode 100755
index 0000000..4858baa
--- /dev/null
+++ b/blog_v2/post-receive
@@ -0,0 +1,38 @@
+#!/usr/bin/env python3
+import os
+import pathlib
+import subprocess
+import sys
+import tempfile
+
+
+target_ref = "refs/heads/master"
+pushed_commit = None
+uv = pathlib.Path.home() / ".local" / "bin" / "uv"
+dest = pathlib.Path.home() / "public_html"
+
+refs = sys.stdin.readlines()
+
+for ref in refs:
+ _from, to, ref = ref.split()
+ if ref == target_ref:
+ pushed_commit = to
+
+if not pushed_commit:
+ print("Not pushing to {target_ref}, move on")
+ sys.exit(0)
+
+print(f"Building {pushed_commit}", flush=True)
+
+with tempfile.TemporaryDirectory() as tempdir:
+ tempdir = pathlib.Path(tempdir)
+ repo = tempdir / "repo"
+ subprocess.run(["git", "worktree", "add", repo, pushed_commit], check=True)
+ os.chdir(repo / "blog_v2")
+ blog = repo / "blog"
+ migrated = tempdir / "migrated"
+ built = tempdir / "built"
+ subprocess.run([uv, "run", "blog", "migrate", blog, migrated], check=True)
+ # TODO: links are not generated properly :(
+ subprocess.run([uv, "run", "blog", "build", migrated, built], check=True)
+ subprocess.run(["rsync", "-r", "--delete-after", f"{built}/", f"{dest}/"], check=True)