diff options
Diffstat (limited to 'blog/post-receive')
| -rwxr-xr-x | blog/post-receive | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/blog/post-receive b/blog/post-receive new file mode 100755 index 00000000..f69abaf6 --- /dev/null +++ b/blog/post-receive @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 +import os +import pathlib +import subprocess +import sys +import tempfile + + +target_ref = "refs/heads/master" +pushed_commit = None +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) + try: + blog = repo / "blog" + os.environ["PATH"] = "/home/alex/.local/bin:" + os.environ["PATH"] + subprocess.run(["./build.sh", dest], check=True, cwd=blog) + finally: + subprocess.run(["git", "worktree", "remove", repo], check=True) |
