gitlab CI: extend the generation script to be somewhat more generic
[platform/upstream/libevdev.git] / .gitlab-ci / generate-gitlab-ci.py
1 #!/usr/bin/env python3
2 # vim: set expandtab shiftwidth=4:
3
4 # This file generates the .gitlab-ci.yml file that defines the pipeline.
5
6 import argparse
7 import jinja2
8 import os
9 import sys
10
11 from pathlib import Path
12
13
14 distributions = [
15     {'name': 'fedora', 'version': '30'},
16     {'name': 'fedora', 'version': '31'},
17     {'name': 'ubuntu', 'version': '19.10'},
18     {'name': 'ubuntu', 'version': '19.04'},
19     {'name': 'debian', 'version': 'stable'},
20     {'name': 'debian', 'version': 'sid'},
21     {
22         'name': 'centos', 'version': '7',
23         'build': {
24             'extra_variables': {
25                 'MAKE_ARGS': ('\'\'  # disable distcheck, requires doxygen'),
26             }
27         },
28         'meson': False
29     },
30     {
31         'name': 'centos', 'version': '8',
32         'build': {
33             'extra_variables': {
34                 'MAKE_ARGS': ('\'\'  # disable distcheck, requires doxygen'),
35             }
36         },
37         'meson': False
38     },
39     {'name': 'arch', 'version': 'rolling',
40      'flavor': 'archlinux' },  # see https://gitlab.freedesktop.org/wayland/ci-templates/merge_requests/19
41     {'name': 'alpine', 'version': 'latest'},
42 ]
43
44 # The various sources for templating
45 SOURCE_DIR = Path('.gitlab-ci')
46 TEMPLATE_FILE = 'gitlab-ci.tmpl'
47
48 BASE_DIR = Path('.')
49 OUTPUT_FILE = '.gitlab-ci.yml'
50
51 def generate_template():
52     env = jinja2.Environment(loader=jinja2.FileSystemLoader(os.fspath(SOURCE_DIR)),
53                              trim_blocks=True, lstrip_blocks=True)
54
55     template = env.get_template(TEMPLATE_FILE)
56     config = {'distributions': distributions}
57     with open(BASE_DIR / OUTPUT_FILE, 'w') as fd:
58         template.stream(config).dump(fd)
59
60
61 if __name__ == '__main__':
62     description = ('''
63     This script generates the .gitlab-ci.yml file.
64
65     It must be run from the git repository root directory and will overwrite
66     the existing .gitlab-ci.yml file.
67     ''')
68     parser = argparse.ArgumentParser(description=description)
69     parser.parse_args()
70
71     if not SOURCE_DIR.exists():
72         print('Error: run me from the top-level tree')
73         sys.exit(1)
74     generate_template()