From 27da79a92bf38b0b84a133afeccee24346ca7158 Mon Sep 17 00:00:00 2001 From: Shashi Date: Thu, 23 Dec 2021 13:31:52 +0530 Subject: [PATCH] Added parent hook and some renderer --- lib/wine.py | 38 +++++++++++++++++++++++++++ multibuild.py | 40 ++++++++++++++++++++++++++++ parent_hook | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 151 insertions(+) create mode 100644 lib/wine.py create mode 100644 parent_hook diff --git a/lib/wine.py b/lib/wine.py new file mode 100644 index 0000000..c12d036 --- /dev/null +++ b/lib/wine.py @@ -0,0 +1,38 @@ +from buildbot.plugins import util +import re + +def _is_github(props): + if re.search(r'[/@]github.com', props.getProperty('repository')): + return True + return False + +@util.renderer +def is_github(props): + return _is_github(props) + +@util.renderer +def isnt_github(props): + return not _is_github(props) + +def _is_gitea(props): + if re.search(r'[/@]git.bitmessage.org', props.getProperty('repository'), re.I): + return True + return False + +@util.renderer +def is_gitea(props): + return _is_gitea(props) + +@util.renderer +def isnt_gitea(props): + return not _is_gitea(props) + +@util.renderer +def is_build_script_available(props): + # Actual check will got here + return props.getProperty('jobname', default='') != '' + +@util.renderer +def is_test_script_available(props): + # Actual check will got here + return props.getProperty('jobname', default='') != '' \ No newline at end of file diff --git a/multibuild.py b/multibuild.py index 17c9f32..05eee87 100644 --- a/multibuild.py +++ b/multibuild.py @@ -12,6 +12,23 @@ Requires docker from os import walk from os.path import exists, isfile, join, listdir +import requests + +request_url = "https://buildbot.sysdeploy.org/change_hook/base" +request_headers = { + 'Content-Type': 'application/x-www-form-urlencoded', + 'Accept': 'text/plain' +} +request_data = { + 'repository': 'git@git.bitmessage.org:Sysdeploy/buildbot-scripts.git', + 'project': 'testproject', + 'author': 'cloud-init', + 'comments': 'testcomment', +} + +ty = 'child_hook' +hn = 'buildbot.sysdeploy.org' #hostname here(required?) +addn = ',"build_script_available":"{build_script_available}","test_script_available":"{test_script_available}"' def list_jobs(directory=".buildbot"): @@ -37,3 +54,26 @@ def find_artifacts(directory="out"): if not isfile(join(directory, _)): continue return join(directory, _) + +def trigger_child_hooks(directory=".buildbot"): + + # List all jobs in the directory + jobs = list_jobs(directory) + + # Check if build.sh or test.sh exists in each of the jobs + for job in jobs: + build_script_exists = False + test_script_exists = False + if exists(join(directory, job, "build.sh")): + build_script_exists = True + if exists(join(directory, job, "test.sh")): + test_script_exists = True + + addn = addn.format(build_script_available=build_script_exists, test_script_available=test_script_exists) + + # make a post request + request_data['properties'] = '{"node":{hn},"type":{ty}{addn}"}'.format(hn=hn, ty=ty, addn=addn) + requests.post(request_url, headers=request_headers, data=request_data) + +if __name__ == "__main__": + trigger_child_hooks() \ No newline at end of file diff --git a/parent_hook b/parent_hook new file mode 100644 index 0000000..aace749 --- /dev/null +++ b/parent_hook @@ -0,0 +1,73 @@ +#!/usr/bin/env python3 +""" parent webhook """ + +from buildbot.plugins import steps, util, secrets +from .lib.wine import * + +c = BuildmasterConfig = {} + +c['buildbotNetUsageData'] = None + +####### SECRETS + +c['secretsProviders'] = [secrets.SecretInAFile(dirname="/var/lib/buildbot/secrets/bitmessage")] +gitea_known_hosts = util.Secret('gitea_known_hosts') +gitea_privkey = util.Secret('gitea_privkey') + +travis_bash = util.BuildFactory() +travis_bash.addStep( + steps.GitHub( + repourl=util.Property("repository"), + name="github", + doStepIf=is_github, + hideStepIf=isnt_github, + branch=util.Property("branch"), + mode="incremental", + ) +) +travis_bash.addStep( + steps.Gitea( + repourl=util.Property("repository"), + sshPrivateKey=gitea_privkey, + sshKnownHosts=gitea_known_hosts, + name="gitea", + doStepIf=is_gitea, + hideStepIf=isnt_gitea, + branch=util.Property("branch"), + mode="incremental", + ) +) + +# execute an interpolate of '.buildbot/$(prop:jobname)/build.sh' +travis_bash.addStep( + steps.ShellCommand( + name="Execute build script", + command=[ + "bash", + util.Interpolate(".buildbot/$(prop:jobname)/build.sh"), + ], + doStepIf=is_build_script_available, + ) +) + +travis_bash.addStep( + steps.ShellCommand( + name="Execute test script", + command=[ + "bash", + util.Interpolate(".buildbot/$(prop:jobname)/test.sh"), + ], + doStepIf=is_test_script_available, + ) +) + +# execute multibuild.py +travis_bash.addStep( + steps.ShellCommand( + name="Execute multibuild script", + command=[ + "python", + util.Interpolate("multibuild.py"), + ], + ) +)