Compare commits

...

2 commits

Author SHA1 Message Date
bf97e83d24 Add a build script
This script does what was previously done by the git hook script. It takes the
commit before the push and the one after the push and lists the directories that
have been affected in those commits.

This script doesn't yet start an actual process for processing the directories,
it just prints what it thinks a command line might look like.
2023-12-16 23:52:35 -08:00
7f1c755c4e Reduce scope of the git hook script
The git hook script should only extract the necessary information the build
script needs to operate. Right now this is only the commit before the push and
after the push, and the refname is added for future use.

The name of the variables passed to the laminar build are modeled after those
found in the GitLab CI documentation, just for some familiarity.

The functionality of finding the relevant directories has been moved to the
build script.
2023-12-16 23:50:11 -08:00
2 changed files with 39 additions and 16 deletions

28
build/freeloadio.run Executable file
View file

@ -0,0 +1,28 @@
#!/usr/bin/env python
from os import getenv
from os.path import dirname
from re import match
from shlex import quote
from subprocess import run
commit_before_sha = getenv('CI_COMMIT_BEFORE_SHA')
commit_sha = getenv('CI_COMMIT_SHA')
commit_ref_name = getenv('CI_COMMIT_REF_NAME')
directories = set()
cmd = 'git clone https://code.ryuslash.org/ryuslash/git-lfs-test.git .'
print(cmd)
run(cmd, shell=True)
if not match(r"^0+$", commit_before_sha):
cmd = f"git diff --name-only {quote(commit_before_sha)} {quote(commit_sha)}"
print(cmd)
process = run(cmd, shell=True, capture_output=True)
process_output = process.stdout.decode()
print(process_output)
for filename in process_output.strip().split('\n'):
directories.add(dirname(filename))
unix_directory_list = str.join(':', directories)
print(f'python tasks.py probe --directories={quote(unix_directory_list)}')

View file

@ -3,26 +3,21 @@
from shlex import quote from shlex import quote
from subprocess import run from subprocess import run
import os import os
import re
import sys import sys
directories = set()
for line in sys.stdin: for line in sys.stdin:
precommit, postcommit, refname = line.split(' ') precommit, postcommit, refname = line.strip().split(' ')
if not refname == "refs/heads/main": if not refname == "refs/heads/main":
print(f"Skipping ref {refname}") print(f"Skipping ref \"{refname}\"")
continue continue
print(f"precommit: {precommit}; postcommit: {postcommit}; refname: {refname}") os.putenv("LAMINAR_REASON", "Push to git repository")
cmd = "laminarc queue freeloadio " \
if not re.match(r"^0+$", precommit): f"CI_COMMIT_BEFORE_SHA={quote(precommit)} " \
process = run(f"git diff --name-only {quote(precommit)} {quote(postcommit)}", shell=True, capture_output=True) f"CI_COMMIT_SHA={quote(postcommit)} " \
for filename in process.stdout.strip().split(b'\n'): f"CI_COMMIT_REF_NAME={quote(refname)}"
directories.add(os.path.dirname(filename).decode()) print(cmd)
process = run(cmd, shell=True, capture_output=True)
os.putenv("LAMINAR_REASON", "Push to git repository") buildname, buildrun = process.stdout.decode().strip().split(':')
process = run(f"laminarc queue freeloadio directories={quote(str.join(';', directories))}", shell=True, capture_output=True) print(f"Queued build: https://laminar.ryuslash.org/jobs/{buildname}/{buildrun}")
buildname, buildrun = process.stdout.strip().split(b':')
print(f"Queued build: https://laminar.ryuslash.org/jobs/{buildname}/{buildrun}")