From fff0b171aa6583f7435b426bbba2def754c7e51d Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Fri, 15 Dec 2023 12:31:38 -0800 Subject: [PATCH] Replace git hook with a python script --- build/git-post-receive-hook | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/build/git-post-receive-hook b/build/git-post-receive-hook index a21ab00..8376535 100755 --- a/build/git-post-receive-hook +++ b/build/git-post-receive-hook @@ -1,9 +1,28 @@ -#!/usr/bin/env bash +#!/usr/bin/env python -while read precommit postcommit refname -do - echo "precommit: ${precommit}; postcommit: ${postcommit}; refname: ${refname}" - if [[ "${precommit}" != "0000000000000000000000000000000000000000" ]]; then - git diff --name-status $precommit $postcommit - fi -done +from shlex import quote +from subprocess import run +import os +import re +import sys + +directories = set() + +for line in sys.stdin: + precommit, postcommit, refname = line.split(' ') + + if not refname == "refs/heads/main": + print(f"Skipping ref {refname}") + continue + + print(f"precommit: {precommit}; postcommit: {postcommit}; refname: {refname}") + + if not re.match(r"^0+$", precommit): + process = run(f"git diff --name-only {quote(precommit)} {quote(postcommit)}", shell=True, capture_output=True) + for filename in process.stdout.strip().split(b'\n'): + directories.add(os.path.dirname(filename).decode()) + +os.putenv("LAMINAR_REASON", "Push to git repository") +process = run(f"laminarc queue freeloadio directories={quote(str.join(';', directories))}", shell=True, capture_output=True) +buildname, buildrun = process.stdout.strip().split(b':') +print(f"Queued build: https://laminar.ryuslash.org/jobs/{buildname}/{buildrun}")