diff options
author | Vishal Bhoj <vishal.bhoj@linaro.org> | 2016-08-22 19:31:08 +0530 |
---|---|---|
committer | Fathi Boudra <fathi.boudra@linaro.org> | 2016-08-31 08:38:54 +0000 |
commit | afb8736f3a7bd72682c286bd72df16b474ad7780 (patch) | |
tree | 4288e955cccb18a593ffa19def291288d88598cc /run-jjb.py | |
parent | 7c38b7ae613c20cbb9d704f13fd94df5958c7160 (diff) |
run-jjb: Update jobs with updates on included files
We recursively look if the updated file is used in any
of the yaml of the job then we add them to the list.
Change-Id: I45d98ee8bbba3cbaaef5dd935651bd409962cafe
Signed-off-by: Vishal Bhoj <vishal.bhoj@linaro.org>
Diffstat (limited to 'run-jjb.py')
-rwxr-xr-x | run-jjb.py | 46 |
1 files changed, 41 insertions, 5 deletions
diff --git a/run-jjb.py b/run-jjb.py index 77265fc6cc..0a8ff7a10d 100755 --- a/run-jjb.py +++ b/run-jjb.py @@ -8,6 +8,30 @@ import subprocess import sys from distutils.spawn import find_executable + +def findparentfiles(fname): + filelist = [] + newlist = [] + args = ['grep', '-rl', '--exclude-dir=.git', fname] + proc = subprocess.Popen(args, + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + universal_newlines=False, + preexec_fn=lambda: + signal.signal(signal.SIGPIPE, signal.SIG_DFL)) + data = proc.communicate()[0] + if proc.returncode != 0: + return filelist + for filename in data.splitlines(): + if filename.endswith('.yaml') and '/' not in filename: + filelist.append(filename) + else: + newlist = findparentfiles(filename) + for tempname in newlist: + filelist.append(tempname) + return filelist + + jjb_cmd = find_executable('jenkins-job-builder') or sys.exit('jenkins-job-builder is not found.') try: @@ -27,11 +51,23 @@ data = proc.communicate()[0] if proc.returncode != 0: raise ValueError("command has failed with code '%s'" % proc.returncode) -for conf_filename in data.splitlines(): - if conf_filename.endswith('.yaml') and '/' not in conf_filename: - with open(conf_filename) as f: - buffer = f.read() - template = string.Template(buffer) +filelist = [] +files = [] +for filename in data.splitlines(): + if filename.endswith('.yaml') and '/' not in filename: + filelist.append(filename) + else: + files = findparentfiles(filename) + for tempname in files: + filelist.append(tempname) + +# Remove dplicate entries in the list +filelist = list(set(filelist)) + +for conf_filename in filelist: + with open(conf_filename) as f: + buffer = f.read() + template = string.Template(buffer) buffer = template.safe_substitute( PUBLISH_KEY=os.environ.get('PUBLISH_KEY') or sys.exit('Key is not defined.'), |