From 3de1e4090fbc7802982a726594171a62731b0338 Mon Sep 17 00:00:00 2001 From: Gil Forcada Date: Sun, 1 Mar 2015 00:57:42 +0100 Subject: [PATCH] Add PLIPs script This fixes https://github.com/plone/jenkins.plone.org/issues/68 Create a script that checkouts buildout.coredev, looks for PLIPs cfg files and update jobs.yml with them. --- jobs.yml | 2 +- plips.py | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 plips.py diff --git a/jobs.yml b/jobs.yml index e8ecdb9c..e1f419ed 100644 --- a/jobs.yml +++ b/jobs.yml @@ -394,7 +394,7 @@ scm: - buildout-coredev: - branch: '5.0' + branch: '{branch}' builders: - shell: | diff --git a/plips.py b/plips.py new file mode 100644 index 00000000..0818af8b --- /dev/null +++ b/plips.py @@ -0,0 +1,101 @@ +# -*- coding: utf-8 -*- +"""Add all existing PLIPs to jobs.yml + +Scan buildout.coredev active branches for PLIPs cfg files and add them to +the list of jobs to be created by jenkins-job-builder. +""" +import os +import re +import subprocess + + +GIT_FOLDER = 'tmp' +GIT_URL = 'https://github.com/plone/buildout.coredev.git' +BRANCHES = ( + '4.3', + '5.0', +) + + +def get_plips(): + """Find all PLIPs cfg files on buildout.coredev branches.""" + regex = re.compile(r'plip(\d+)-*(.+).cfg') + plips = [] + + for branch in BRANCHES: + p = subprocess.Popen( + ['git', 'checkout', branch, ], + cwd=GIT_FOLDER + ) + p.wait() + + for plip in sorted(os.listdir('{0}/plips'.format(GIT_FOLDER))): + data = regex.match(plip) + if data: + plip_number = data.groups()[0] + plip_name = data.groups()[1] + plips.append( + {'branch': branch, + 'number': plip_number, + 'name': plip_name, + 'cfg': 'plips/{0}'.format(plip), + } + ) + return plips + + +def update_jobs_yml(plips): + """Read jjb jobs definition and update PLIPs project.""" + jobs_file = 'jobs.yml' + new_jobs_file = 'jobs-tmp.yml' + + with open(jobs_file) as jobs_file_handler, \ + open(new_jobs_file, 'w') as new_jobs_file_handler: + + found = False + for line in jobs_file_handler.readlines(): + # look for the marker PLIPs project and override + if not found and line.strip() == 'name: PLIPs': + found = True + + new_jobs_file_handler.write(line) + new_jobs_file_handler.write(' plip:\n') + for plip in plips: + write_job_definition(plip, new_jobs_file_handler) + + elif not found: + new_jobs_file_handler.write(line) + + # once all previously defined plips are processed, + # write the ending jobs and template and let it copy verbatim again + if found and line.strip() == "- 'plip-{plip}'": + new_jobs_file_handler.write('\n jobs:\n') + new_jobs_file_handler.write(line) + found = False + + os.rename(new_jobs_file, jobs_file) + + +def write_job_definition(plip, file_handler): + """Write jjb definition for the given plip on the given file.""" + job_id = '{0}-{1}-{2}'.format( + plip['branch'], + plip['number'], + plip['name'], + ) + file_handler.write(' - {0}:\n'.format(job_id)) + file_handler.write(' buildout: {0}\n'.format(plip['cfg'])) + file_handler.write(' branch: {0}\n'.format(plip['branch'])) + + +def main(): + # remove and download again buildout.coredev + subprocess.call(['rm', '-rf', GIT_FOLDER ]) + subprocess.call(['git', 'clone', '-q', GIT_URL, GIT_FOLDER]) + + plips = get_plips() + update_jobs_yml(plips) + + +if __name__ == '__main__': + main()