commit: 04cb23acd0367277883e7cdf00033dd8d2451c5a
parent 63c3bc9841a5ff15dfa8e79d6ea85e6a41cd5ce7
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Fri, 11 Feb 2022 19:30:12 +0100
git-hooks/post-update.srht: Add builds.sr.ht hook
Diffstat:
2 files changed, 67 insertions(+), 0 deletions(-)
diff --git a/git-hooks/post-update b/git-hooks/post-update
@@ -12,6 +12,10 @@ git update-server-info && is_ok
printf "$update_f" work
mkdir -p "${base}.work/.git" && GIT_INDEX_FILE="${base}.work/.git/index" git --work-tree="${base}.work" --git-dir="${base}.git" checkout -f && is_ok
+if test -f "${base}.git/post-update.env" ; then
+. "${base}.git/post-update.env"
+fi
+
for i in ${base}.git/hooks/post-update.*; do
[[ -x $i ]] && echo "${PS4:-+}${i}" && $i
done
diff --git a/git-hooks/post-update.srht b/git-hooks/post-update.srht
@@ -0,0 +1,63 @@
+#!/usr/bin/env perl
+# Collection of Unix tools, comparable to coreutils
+# Copyright 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
+# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
+use strict;
+use utf8;
+no warnings; # Wide Character…
+
+use LWP::UserAgent;
+use JSON::MaybeXS;
+use Cwd;
+
+my $json = JSON::MaybeXS->new(utf8 => 1);
+my $base = getcwd();
+$base =~ s/.git$//;
+
+sub new_job {
+ my ($manifest_file) = @_;
+
+ my $manifest = '';
+
+ open FILE, '<', $manifest_file or die $!;
+
+ while(<FILE>) {
+ $manifest .= $_;
+ }
+
+ my $ua = LWP::UserAgent->new;
+ $ua->agent("git post-update hook <https://hacktivis.me/git/utils/>");
+
+ my $job = {
+ "manifest" => $manifest,
+ };
+
+ my $res = $ua->post(
+ $ENV{SRHT_HOST} . "/api/jobs",
+ Authorization => 'token ' . $ENV{SRHT_TOKEN},
+ Content_Type => 'application/json',
+ Content => encode_json $job,
+ );
+
+ if(not $res->is_success) {
+ print $res->message;
+ print $res->content;
+ die $!;
+ };
+}
+
+defined($ENV{SRHT_HOST}) || die;
+defined($ENV{SRHT_TOKEN}) || die;
+
+if (-d $base . ".work/.builds") {
+ # TODO: Shuffle manifests, take 4
+ my $builds = $base . ".work/.builds";
+ my @manifests = <"${builds}/*.yml">;
+ for (@manifests) {
+ new_job $_;
+ }
+} elsif (-e $base . ".work/.build.yml") {
+ new_job "${base}.work/.build.yml";
+} else {
+ print "No build manifest found";
+}