From 8ea48ba4ee5bcb75ca60ef8023c847751bf61f95 Mon Sep 17 00:00:00 2001 From: Izimic Date: Wed, 16 Dec 2020 00:43:00 +0100 Subject: [PATCH] option -e --- default.zsh | 25 +++++++++++++++++++++++++ src/webhooksd.cr | 13 +++++++++---- 2 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 default.zsh diff --git a/default.zsh b/default.zsh new file mode 100644 index 0000000..4f545fe --- /dev/null +++ b/default.zsh @@ -0,0 +1,25 @@ +#!/usr/bin/env zsh + + +PROJECT=dodb.cr +GIT=$(cat payload.json | jq '.repository.clone_url') +ENV=debian +SPECS=("crystal spec spec/test.cr --tap") + +echo $GIT + +git clone $GIT +cd $PROJECT + +shards install +shards build + +REV=$(git rev-parse HEAD) + +for i in ${SPECS[*]} +do + echo $i + /bin/sh -c $i | ../tap-aggregator add $PROJECT $ENV $REV +done + +exit 1 diff --git a/src/webhooksd.cr b/src/webhooksd.cr index b69cd96..254954c 100644 --- a/src/webhooksd.cr +++ b/src/webhooksd.cr @@ -6,7 +6,7 @@ VERSION = 0.1 port = 3000 storage = "webhooksd-data" -scriptfile = "on-push" +scriptfile = "default.zsh" jsonfile = "payload.json" args = [] of String @@ -31,6 +31,10 @@ OptionParser.parse do |parser| storage = s end + parser.on "-e SCRIPT", "--script=SCRIPT", "Default: #{scriptfile}" do |s| + scriptfile = s + end + parser.invalid_option do |flag| STDERR.puts "ERROR: #{flag} is not a valid option." STDERR.puts parser @@ -54,7 +58,7 @@ server = HTTP::Server.new do |context| payload = Payload.new(context.request) path_project = storage + "/" + payload.project - path_scriptfile = path_project + "/" + scriptfile + path_scriptfile = "../../../" + scriptfile path_jsonfile = path_project + "/" + jsonfile status = false @@ -63,12 +67,13 @@ server = HTTP::Server.new do |context| STDERR.puts "ERROR: Project #{payload.project} not found" status = false else - if File.exists?(path_scriptfile) == false + if File.exists?(scriptfile) == false + p scriptfile STDERR.puts "ERROR: Scriptfile not found" status = false else File.write(path_jsonfile, payload.content) - status = Process.run command: "zsh", args: [scriptfile], shell: true, + status = Process.run command: "zsh", args: [path_scriptfile], shell: true, error: STDERR, output: STDOUT, chdir: path_project end end