Read about our upcoming Code of Conduct on this issue

prepare_build_py_heptapod.py 2.54 KB
Newer Older
1
2
3
4
5
6
7
8
9
#!/usr/bin/env python3
"""Clone and prepare py_heptapod for CI build of the Rails applications.

Expected to be run from a clone of the Rails application, and assumes
that `config/gitlab.yml` has already been initialized.
"""
import os
import subprocess

10
INTERPRETER = 'python3.8'
11
12
13
14

CWD = os.getcwd()

PY_HEPTAPOD_CLONE_PATH = os.path.join(CWD, 'vendor', 'py-heptapod')
15
HGITALY_CLONE_PATH = os.path.join(CWD, 'vendor', 'hgitaly')
16

17
18
HG_BIN = '/usr/local/bin/hg'
PIP_BIN = 'pip3.8'
19

20
21
22
23
print("Upgrading pip and setuptools")
subprocess.check_call((PIP_BIN, 'install', '--upgrade',
                       'pip', 'setuptools', 'wheel'))

24
25
# yes, Mercurial is readily available in GitLab base CI image!
# But its Debian 9 version (hg 4.0)
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
for slug, target in (('py-heptapod', PY_HEPTAPOD_CLONE_PATH),
                     ('hgitaly', HGITALY_CLONE_PATH)):
    if os.path.exists(target):
        print("Updating %s clone at %s" % (slug, target))
        subprocess.check_call(('hg', '-R', target, 'pull', '-u'))
    else:
        print("Cloning %s into %s" % (slug, target))
        subprocess.check_call(
            ('hg', 'clone', '-q',
             'https://mirror.octobus.net/heptapod/' + slug,
             target,
             ))

    print("Current revision for %s:" % target)
    subprocess.check_call(('hg', '-R', target, 'log', '-r', '.'))

    pip_cmd = (PIP_BIN, 'install', '-e', target)
    print("Installing %s: %r" % (slug, pip_cmd))
    subprocess.check_call(pip_cmd)
45
46

pip_logging_cmd = (PIP_BIN, 'install', 'hg-loggingmod')
47
print("Installing hg-loggingmod: " + repr(pip_logging_cmd))
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
subprocess.check_call(pip_logging_cmd)

local_hgrc_path = os.path.join(CWD, 'config', 'tests.hgrc')
with open(local_hgrc_path, 'w') as local_hgrcf:
    local_hgrcf.write("\n".join((
        "[heptapod]",
        "# we won't really send the pre- and post-receive hooks, ",
        "# but `heptapod.hooks.Hook` is currently still instantiated and ",
        "# that requires the configuration.",
        "gitlab-internal-api-secret-file = " + os.path.join(CWD, '.gitlab_shell_secret'),
        "")))

req_hgrc_path = os.path.join(PY_HEPTAPOD_CLONE_PATH,
                             'heptapod', 'required.hgrc')

yml_format = 'hgrc:\n      - %s\n      - %s\n    bin_path: %s'

with open('config/gitlab.yml', 'r+') as conf:
    out_lines = [l.replace('# hgrc:',
                           yml_format % (local_hgrc_path,
                                         req_hgrc_path,
                                         HG_BIN))
                 for l in conf.readlines()]
    conf.seek(0)
    conf.writelines(out_lines)