generate_build_tails_iso_jobs 3.03 KB
Newer Older
1
2
3
4
#!/usr/bin/python3

import yaml

5
TAILS_RM_EMAIL = 'tails-rm@boum.org'
6

7
class BuildTailsISOJob:
8

9
10
    DESCRIPTION_TEMPLATE = \
'''<p>This job is managed by jenkins-job-builder. Do not edit it through this web interface, your changes would be overwritten.</p>
11
<p>You can <a href="http://nightly.tails.boum.org/%(job_name)s/">download build results</a>.</p>'''
12

13
14
15
16
17
18
19
20
21
22
23
24
25
26
    JOB_SNIPPET = '''node: isobuilder1 || isobuilder2
builders:
  - build_Tails_ISO
  - clean_Archives
triggers:
  - pollscm: '@weekly'
  - timed: '@daily'
wrappers:
  - timestamps
  - workspace-cleanup:
      dirmatch: true
      include:
        - "**"'''

27
28
29
30
31
    VALID_JOB_RECIPIENTS = [
        'release_managers',
        'whoever_broke_the_build',
    ]

32
    def __init__(self, branch, snippet = JOB_SNIPPET):
33
34
35
36
37
38
39
        assert type(branch['branch_name']) is str
        assert branch['branch_name'].__len__() > 0
        assert type(branch['job_name']) is str
        assert branch['job_name'].__len__() > 0
        assert type(branch['base_branch']) is bool
        assert type(snippet) is str
        assert snippet.__len__() > 0
40
41
        assert type(branch['job_recipients']) is str
        assert self.VALID_JOB_RECIPIENTS.count(branch['job_recipients'])
42
        self.job = yaml.safe_load(snippet)
43
        self.job['name'] = branch['job_name']
44
        self.job['scm'] = [{'git': \
45
                {'branches': [branch['branch_name']],
46
47
48
49
                 'browser': 'cgit',
                 'browser-url': 'https://git-tails.immerda.ch/tails/',
                 'url': 'gitolite@puppet-git.lizard:tails'}
                }]
50
51
52
53
54
55
56
57
58
59
        if branch['job_recipients'] == 'release_managers':
            self.job['publishers'] = [
                {'email': { 'recipients': TAILS_RM_EMAIL }}
            ]
        elif branch['job_recipients'] == 'whoever_broke_the_build':
            self.job['publishers'] = [
                {'email': { 'sent-to-individuals': True }}
            ]
        else:
            raise ""
60
61
62
        self.job['description'] = self.DESCRIPTION_TEMPLATE % {
            'job_name': self.job['name']
        }
63

64
    def __str__(self):
65
        return yaml.safe_dump([{'job': self.job}], default_flow_style=False)
66

67
68
69
70
71

def get_active_branches():
    """Retrieve the list of active branches using the Tails python library.
       Now is just a stub returning a list of branch dict."""
    return [{'branch_name': 'feature/test_active_branch_job',
72
             'job_name': 'build_Tails_ISO_feature-test_active_branch_job',
73
             'job_recipients': 'whoever_broke_the_build',
74
             'base_branch': False,
intrigeri's avatar
intrigeri committed
75
            },
76
            {'branch_name': 'bugfix/there_should_be_two_of_them',
77
             'job_name': 'build_Tails_ISO_bugfix-there_should_be_two_of_them',
78
             'job_recipients': 'release_managers',
79
             'base_branch': True,
intrigeri's avatar
intrigeri committed
80
            },
81
82
83
84
           ]

if __name__ == "__main__":
    for branch in get_active_branches():
85
        job = BuildTailsISOJob(branch)
86
87
88
89
        job_filename = "%s.yaml" % branch['job_name']
        with open(job_filename, 'w') as job_file:
            job_file.write(str(job))