Commit ed427c2f authored by Georges Racinet's avatar Georges Racinet 🦑
Browse files

heptapod-ci: preparations for tests involving Mercurial

This is done by a separate Python script originally because
it'd otherwise be an escaping nightmare with sed commands as
`prepare_build.sh` issues (especially because we'd need
an absolute path, and hence to escape $PWD).

Now this script does the following:

- create a virtualenv
- install all py-heptapod needed dependencies, for now
  in a Python2 virtual environment. We'll have to provide
  a recent Python3 for HGitaly later.
- configure GitLab for Mercurial operation.

This is done after `TestEnv.init` because the later would
cancel our changes in `config/gitlab.yml`

Note also that putting the local `test.hgrc` file in `tmp/tests`
would not work: something inside the `bin/rspec` run would delete
it before the time when the actual tests need it.

--HG--
branch : heptapod
parent 24c622118444
Pipeline #8397 passed with stage
in 19 minutes and 15 seconds
......@@ -23,6 +23,7 @@
- vendor/ruby/
- vendor/gitaly-ruby/
- .go/pkg/mod/
- venv
policy: pull
.static-analysis-cache:
......
......@@ -48,9 +48,14 @@ rspec:
- .heptapod-rails-cache
script:
- rm -rf tmp/tests/gitaly # stale files from previous builds can prevent proper installation
- apt-get -qq update && apt-get install -qy virtualenv python-dev
- run_timed_command "bundle exec ruby -I. -e 'require \"config/environment\"; TestEnv.init'"
- run_timed_command "python3 scripts/prepare_build_py_heptapod.py"
- ls -al tmp/tests/*
- run_timed_command "scripts/gitaly-test-build" # Do not use 'bundle exec' here
- rm tmp/tests/gitaly/.ruby-bundle # This file prevents gems from being installed even if vendor/gitaly-ruby is missing
- run_timed_command "scripts/gitaly-test-spawn"
- grep -A3 'hgrc:' config/gitlab.yml
- cat $PWD/config/tests.hgrc
- cat $PWD/vendor/py-heptapod/heptapod/required.hgrc
- scripts/heptapod_rspec.sh
#!/bin/sh
bin/rspec \
spec/lib/gitlab/mercurial_spec.rb \
spec/lib/gitlab/*_access*.rb \
spec/lib/gitlab/git \
spec/lib/gitlab/mercurial \
spec/models/*repository*.rb \
spec/models/merge_request_*_spec.rb \
spec/models/compare_spec.rb \
......
#!/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
# later on we'll install python3.8 (CI base image is Debian 9 with 3.5)
INTERPRETER = 'python2'
CWD = os.getcwd()
PY_HEPTAPOD_CLONE_PATH = os.path.join(CWD, 'vendor', 'py-heptapod')
VENV = os.path.join(CWD, 'venv')
HG_BIN = os.path.join(VENV, 'bin', 'hg')
PIP_BIN = os.path.join(VENV, 'bin', 'pip')
# yes, Mercurial is readily available in GitLab base CI image!
# But its Debian 9 version (hg 4.0)
if os.path.exists(PY_HEPTAPOD_CLONE_PATH):
print("Updating py-heptapod clone at %s" % PY_HEPTAPOD_CLONE_PATH)
subprocess.check_call(('hg', '-R', PY_HEPTAPOD_CLONE_PATH, 'pull', '-u'))
else:
print("Cloning py-heptapod into %s" % PY_HEPTAPOD_CLONE_PATH)
subprocess.check_call(
('hg', 'clone', '-q',
'https://mirror.octobus.net/heptapod/py-heptapod',
PY_HEPTAPOD_CLONE_PATH,
))
virtualenv_cmd = ('virtualenv', '-p', INTERPRETER, VENV)
print("Creating virtualenv: " + repr(virtualenv_cmd))
subprocess.check_call(virtualenv_cmd)
dulwich_cmd = (PIP_BIN, 'install', 'dulwich<0.20')
print("Forcing install of a dulwich "
"version suitable for Python2: " + repr(dulwich_cmd))
subprocess.check_call(dulwich_cmd)
pip_cmd = (PIP_BIN, 'install', '-e', PY_HEPTAPOD_CLONE_PATH)
print("Installing py-heptapod in virtualenv: " + repr(pip_cmd))
subprocess.check_call(pip_cmd)
pip_logging_cmd = (PIP_BIN, 'install', 'hg-loggingmod')
print("Installing hg-loggingmod in virtualenv: " + repr(pip_logging_cmd))
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)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment