aboutsummaryrefslogtreecommitdiff
path: root/blog/post-receive
blob: 0721ce3b5261b4e7338ef02aeca2352d85dd7e2d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/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)
    blog = repo / "blog"
    os.chdir(blog)
    os.environ["PATH"] = "/home/alex/.local/bin:" + os.environ["PATH"]
    subprocess.run(["./build.sh", dest], check=True)