aboutsummaryrefslogtreecommitdiffstats
path: root/etc/ci/generate_workflow.py
blob: a3295e1c0a261491f96e4fbfa8e541fe893b2260 (plain) (blame)
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
# Copyright 2021 The Servo Project Developers. See the COPYRIGHT
# file at the top-level directory of this distribution.
#
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
# option. This file may not be copied, modified, or distributed
# except according to those terms.

import os.path
import sys

BASE = os.path.dirname(__file__.replace('\\', '/'))
sys.path.insert(0, os.path.join(
    BASE, "..", "..", "components", "style", "properties", "Mako-1.1.2-py2.py3-none-any.whl"
))

from mako import exceptions  # noqa
from mako.lookup import TemplateLookup  # noqa
from mako.template import Template  # noqa


def abort(message):
    print(message, file=sys.stderr)
    sys.exit(1)


def render(filename, **context):
    try:
        lookup = TemplateLookup(directories=[BASE],
                                input_encoding="utf8",
                                strict_undefined=True)
        template = Template(open(os.path.join(BASE, filename), "rb").read(),
                            filename=filename,
                            input_encoding="utf8",
                            lookup=lookup,
                            strict_undefined=True)
        # Uncomment to debug generated Python code:
        # write("/tmp", "mako_%s.py" % os.path.basename(filename), template.code)
        return template.render(**context)
    except Exception:
        # Uncomment to see a traceback in generated Python code:
        # raise
        abort(exceptions.text_error_template().render())


def main():
    with open(os.path.join(".github", "workflows", "main.yml"), 'w') as f:
        f.write(render(
            'workflow.mako',
            total_chunks=20,
            REPOSITORY_NAME="${{ github.event.repository.name }}",
            CODESIGN_CERT="${{ secrets.WINDOWS_CODESIGN_CERT }}",
        ))


if __name__ == "__main__":
    main()