summaryrefslogtreecommitdiffstats
path: root/files/jenkins/master/generate_tails_iso_jobs
blob: 0ac6551be01b3c1db977cb6231bc546c1f4cc090 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/python3

import yaml
import re
from tailslib.jenkins import ActiveBranches

TAILS_RM_EMAIL = 'tails-rm@boum.org'
TAILS_TESTING_TEAM = 'anonym@riseup.net killyourtv@i2pmail.org'

class TailsISOProject(object):
    """Create a jenkins-job-builder Tails ISO project file for a branch."""

    PROJECT_SNIPPET = '''
    NODE_NAME: 'NODE_NAME'
    UPSTREAMJOB_BUILD_NUMBER: 'UPSTREAMJOB_BUILD_NUMBER'
    BUILD_NUMBER: 'BUILD_NUMBER' '''

    VALID_JOB_RECIPIENTS = [
        'release_managers',
        'whoever_broke_the_build',
    ]

    def __init__(self, branch, snippet=PROJECT_SNIPPET):
        assert isinstance(branch['project_name'], str)
        assert branch['project_name'].__len__() > 0
        assert isinstance(branch['branch_name'], str)
        assert branch['branch_name'].__len__() > 0
        assert isinstance(branch['is_base_branch'], bool)
        assert isinstance(snippet, str)
        assert snippet.__len__() > 0
        assert isinstance(branch['recipients'], str)
        assert self.VALID_JOB_RECIPIENTS.count(branch['recipients'])
        self.project = yaml.safe_load(snippet)
        self.project['name'] = branch['project_name']
        self.project['branch_name'] = branch['branch_name']
        if branch['recipients'] == 'release_managers':
            self.project['jobs'] = [{'build_Tails_ISO_{name}':
                {'email': TAILS_RM_EMAIL}}]
        elif branch['recipients'] == 'whoever_broke_the_build':
            self.project['jobs'] = [{'build_Tails_ISO_{name}':
                {'email': '$NOTIFY_TO'}}]
        else:
            raise ""
        self.project['jobs'].append('wrap_test_Tails_ISO_{name}')
        self.project['jobs'].append({'test_Tails_ISO_{name}':
                {'email': TAILS_TESTING_TEAM}})
        self.project['ticket_number'] = branch['ticket_number']

    def __str__(self):
        return yaml.safe_dump([{'project': self.project}], default_flow_style=False)


def get_active_branches(git_repo_path):
    """Retrieve the list of active branches using the Tails python library."""
    branches = ActiveBranches(git_repo_path)
    return branches.compute()

if __name__ == "__main__":
    import argparse
    parser = argparse.ArgumentParser()
    parser.add_argument("Tails_git_directory",
        help="Full path to the .git directory of the local Tails git repo checkout.")
    parser.add_argument("Projects_directory",
        help="Full path to the output directory of the Jenkins Jobs project files.")
    args = parser.parse_args()
    wip_branch_re = re.compile(r'^wip/')
    for active_branch in get_active_branches(args.Tails_git_directory):
        if not wip_branch_re.search(active_branch['branch_name']):
            project = TailsISOProject(active_branch)
            project_filename = args.Projects_directory + "%s.yaml" % active_branch['project_name']
            with open(project_filename, 'w') as project_file:
                project_file.write(str(project))