logo

utils

~/.local/bin tools and git-hooks git clone https://hacktivis.me/git/utils.git
commit: 6e1be1ece9c2f9f89f68030d302c48fed7b28e48
parent 32759972d4df7e79ccc67030d09e6292e58ee34c
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Sat, 12 Feb 2022 04:35:06 +0100

git-hooks/post-update.srht: Add tags support

Diffstat:

Mgit-hooks/post-update.srht29++++++++++++++++++-----------
1 file changed, 18 insertions(+), 11 deletions(-)

diff --git a/git-hooks/post-update.srht b/git-hooks/post-update.srht @@ -9,19 +9,25 @@ no warnings; # Wide Character… use LWP::UserAgent; use JSON::MaybeXS; use Cwd; +use File::Spec; my $json = JSON::MaybeXS->new(utf8 => 1); + my $base = getcwd(); $base =~ s/.git$//; +my $workdir = "${base}.work"; +my $project = (File::Spec->splitpath($base))[2]; + sub new_job { my ($manifest_file) = @_; + my $manifest_rel = (File::Spec->splitpath($manifest_file))[2]; my $manifest = ''; open FILE, '<', $manifest_file or die $!; - while(<FILE>) { + while (<FILE>) { $manifest .= $_; } @@ -30,36 +36,37 @@ sub new_job { my $job = { "manifest" => $manifest, + "tags" => [ "${project}", "${manifest_rel}" ], }; my $res = $ua->post( $ENV{SRHT_HOST} . "/api/jobs", Authorization => 'token ' . $ENV{SRHT_TOKEN}, - Content_Type => 'application/json', - Content => encode_json $job, + Content_Type => 'application/json', + Content => encode_json $job, ); - if(not $res->is_success) { + if (not $res->is_success) { print $res->message; print $res->content; die $!; - }; + } } -if (not ( defined($ENV{'SRHT_HOST'}) && defined($ENV{'SRHT_TOKEN'}) )) { +if (not(defined($ENV{'SRHT_HOST'}) && defined($ENV{'SRHT_TOKEN'}))) { print 'Environment variables $SRHT_HOST and $SRHT_TOKEN are undefined'; exit 1; } -if (-d $base . ".work/.builds") { +if (-d "${workdir}/.builds") { + # TODO: Shuffle manifests, take 4 - my $builds = $base . ".work/.builds"; - my @manifests = <"${builds}/*.yml">; + my @manifests = <"${workdir}/.builds/*.yml">; for (@manifests) { new_job $_; } -} elsif (-e $base . ".work/.build.yml") { - new_job "${base}.work/.build.yml"; +} elsif (-e "${workdir}/.build.yml") { + new_job "${workdir}/.build.yml"; } else { print "No build manifest found"; }